LFS258-LAB-Ingress

安裝traefik

  1. 添加rbac
student@ubuntu:~/ingress$cat traefik-rbac.yaml 
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: traefik-ingress-controller
rules:
  - apiGroups:
      - ""
    resources:
      - services
      - endpoints
      - secrets
    verbs:
      - get
      - list
      - watch
  - apiGroups:
      - extensions
    resources:
      - ingresses
    verbs:
      - get
      - list
      - watch
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
  name: traefik-ingress-controller
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: traefik-ingress-controller
subjects:
- kind: ServiceAccount
  name: traefik-ingress-controller
  namespace: kube-system

student@ubuntu:~/ingress$kubectl create -f traefik-rbac.yaml 
clusterrole.rbac.authorization.k8s.io/traefik-ingress-controller created
clusterrolebinding.rbac.authorization.k8s.io/traefik-ingress-controller created

2.添加traefik ds

student@ubuntu:~/ingress$cat traefik-ds.yaml 
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: traefik-ingress-controller
  namespace: kube-system
---
kind: DaemonSet
apiVersion: extensions/v1beta1
metadata:
  name: traefik-ingress-controller
  namespace: kube-system
  labels:
    k8s-app: traefik-ingress-lb
spec:
  template:
    metadata:
      labels:
        k8s-app: traefik-ingress-lb
        name: traefik-ingress-lb
    spec:
      serviceAccountName: traefik-ingress-controller
      terminationGracePeriodSeconds: 60
      hostNetwork: true
      containers:
      - image: traefik
        name: traefik-ingress-lb
        ports:
        - name: http
          containerPort: 80
          hostPort: 80
        - name: admin
          containerPort: 8080
          hostPort: 8080
        volumeMounts:
        - mountPath: "/ssl"
          name: "ssl"
        - mountPath: "/config"
          name: "config"
        args:
        - --api
        - --kubernetes
        - --logLevel=INFO
#        - --configfile=/config/traefik.toml
      volumes:
      - name: ssl
        secret:
          secretName: traefik-cert
      - name: config
        configMap:
          name: traefik-conf

student@ubuntu:~/ingress$kubectl create -f traefik-ds.yaml 
serviceaccount/traefik-ingress-controller created

3.添加ingress

student@ubuntu:~/ingress$cat nginx-ingress.yaml 
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: ingress-nginx
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: nginx.xj.com
    http:
      paths:
      - path: /
        backend:
          serviceName: nginx
          servicePort: 80
  - host: nginx-1.xj.com
    http:
      paths:
      - path: /
        backend:
          serviceName: nginx-1
          servicePort: 80
student@ubuntu:~/ingress$kubectl create -f nginx-ingress.yaml 
ingress.extensions/ingress-nginx created


student@ubuntu:~/ingress$kubectl run nginx --image=nginx
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
deployment.apps/nginx created
student@ubuntu:~/ingress$kubectl run nginx-1 --image=nginx
kubectl run --generator=deployment/apps.v1beta1 is DEPRECATED and will be removed in a future version. Use kubectl create instead.
deployment.apps/nginx-1 created
student@ubuntu:~/ingress$kubectl expose deployment nginx --port=80
service/nginx exposed
student@ubuntu:~/ingress$kubectl expose deployment nginx-1 --port=80

4.查看ui
http://<NODE-ip>:8080/dashboard/

5.查看反向代理

student@ubuntu:~/ingress$curl http://172.30.81.194/ -H"Host: nginx.xj.com"
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a >nginx.org</a>.<br/>
Commercial support is available at
<a >nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>

student@ubuntu:~/ingress$curl http://172.30.81.194/ -H"Host: nginx-no.xj.com"
404 page not found
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末讼油,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 211,743評(píng)論 6 492
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件改执,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)窘问,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,296評(píng)論 3 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來宜咒,“玉大人惠赫,你說我怎么就攤上這事」屎冢” “怎么了儿咱?”我有些...
    開封第一講書人閱讀 157,285評(píng)論 0 348
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)场晶。 經(jīng)常有香客問我混埠,道長(zhǎng),這世上最難降的妖魔是什么诗轻? 我笑而不...
    開封第一講書人閱讀 56,485評(píng)論 1 283
  • 正文 為了忘掉前任钳宪,我火速辦了婚禮,結(jié)果婚禮上扳炬,老公的妹妹穿的比我還像新娘吏颖。我一直安慰自己,他們只是感情好恨樟,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,581評(píng)論 6 386
  • 文/花漫 我一把揭開白布半醉。 她就那樣靜靜地躺著,像睡著了一般厌杜。 火紅的嫁衣襯著肌膚如雪奉呛。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,821評(píng)論 1 290
  • 那天夯尽,我揣著相機(jī)與錄音瞧壮,去河邊找鬼。 笑死匙握,一個(gè)胖子當(dāng)著我的面吹牛咆槽,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播圈纺,決...
    沈念sama閱讀 38,960評(píng)論 3 408
  • 文/蒼蘭香墨 我猛地睜開眼秦忿,長(zhǎng)吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼麦射!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起灯谣,我...
    開封第一講書人閱讀 37,719評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤潜秋,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后胎许,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體峻呛,經(jīng)...
    沈念sama閱讀 44,186評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,516評(píng)論 2 327
  • 正文 我和宋清朗相戀三年辜窑,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了钩述。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,650評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡穆碎,死狀恐怖牙勘,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情所禀,我是刑警寧澤方面,帶...
    沈念sama閱讀 34,329評(píng)論 4 330
  • 正文 年R本政府宣布,位于F島的核電站色徘,受9級(jí)特大地震影響葡幸,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜贺氓,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,936評(píng)論 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望床蜘。 院中可真熱鬧辙培,春花似錦、人聲如沸邢锯。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,757評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽丹擎。三九已至尾抑,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間蒂培,已是汗流浹背再愈。 一陣腳步聲響...
    開封第一講書人閱讀 31,991評(píng)論 1 266
  • 我被黑心中介騙來泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留护戳,地道東北人翎冲。 一個(gè)月前我還...
    沈念sama閱讀 46,370評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長(zhǎng)得像媳荒,于是被迫代替她去往敵國(guó)和親抗悍。 傳聞我的和親對(duì)象是個(gè)殘疾皇子驹饺,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,527評(píng)論 2 349

推薦閱讀更多精彩內(nèi)容