亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

K8s之traefik(ingess)發布服務-實戰

發布時間:2020-08-11 10:47:12 來源:網絡 閱讀:912 作者:無鋒劍 欄目:云計算

K8s之traefik(ingess)發布服務實戰

上篇描述了基于k8s集群安裝部署traefik作為ingress服務,簡單演示了一下發布服務,本篇將細節講述如果結合traefik發布業務服務。

安裝部署參考:

https://blog.51cto.com/michaelkang/2429929

版本介紹

traefik:v1.7
k8s:v1.15.1

快速部署traefik

如果你的k8s集群已經部署完成,想快速部署traefik,執行命令如下:

kubectl create -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-rbac.yaml
kubectl create -f https://raw.githubusercontent.com/containous/traefik/v1.7/examples/k8s/traefik-ds.yaml

執行成功,在瀏覽器數據一個node節點的IP地址:8080 端口即可看到traefik的管理頁面。

實戰開始

編寫一個業務yaml文件

如果對yaml不太熟悉,看這邊:https://blog.51cto.com/michaelkang/2429745

---
#配置deployment
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
#設置dm名稱
  name: dm-pttest
#添加標簽 pttest
  labels:
    app: pttest
spec:
# 通過replicas聲明pod個數是2 
  replicas: 2
# 通過標簽選擇被控制的pod  
  selector:
    matchLabels:
      app: pttest
# 在template中定義pod 
  template:
    metadata:
# 給pod打上標簽app=pttest
      labels:
        app: pttest
    spec:
      containers:
# 聲明容器名稱,注意不是pod名稱,pod名稱應該定義在metadata中
      - name: myapp
        image: ikubernetes/myapp:v1
        ports:
        - containerPort: 80

---
#服務配置
apiVersion: v1
# 聲明一個Service資源對象
kind: Service
metadata:
#pod 名稱
  name: svcpttest
  labels:
    app: pttest
  annotations:
#檢查后端服務返回錯誤率,大于%50,踢出集群
    traefik.backend.circuitbreaker: "NetworkErrorRatio() > 0.5"
spec:
  ports:
  - name: http
    port: 80
  selector:
    app: pttest

---
#配置ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: myapp-traefik-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
spec:
  rules:
  - host: pttest.pt.com
    http:
      paths:
      - path: /
#指定后端服務
        backend:
          serviceName: svcpttest
          servicePort: 80

驗證服務

#查看服務
[root@kubm-02 traefik]# kubectl get svc -o wide
NAME         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)   AGE     SELECTOR

svcpttest    ClusterIP   10.245.148.114   <none>        80/TCP    2m12s   app=pttest  <==lable

#查看container
[root@kubm-02 traefik]# kubectl get pods  -o wide
NAME                         READY   STATUS    RESTARTS   AGE     IP             NODE         NOMINATED NODE   READINESS GATES
dm-pttest-6f6cd797f5-cdjk5   1/1     Running   0          63s     10.244.3.115   kubnode-01   <none>           <none>
dm-pttest-6f6cd797f5-tqh64   1/1     Running   0          63s     10.244.4.135   kubnode-02   <none>           <none>

#ingress 信息
[root@kubm-02 traefik]# kubectl get ingress                                
NAME                    HOSTS           ADDRESS   PORTS   AGE
myapp-traefik-ingress   pttest.pt.com             80      23s

#deployment
[root@kubm-02 traefik]# kubectl get deploy
NAME        READY   UP-TO-DATE   AVAILABLE   AGE

dm-pttest   2/2     2            2           12m

驗證訪問:

請求pttest.pt.com,?服務svcpttest會把請求負載給后端的pod。

#請求兩次分別返回兩個
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-cdjk5

[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-tqh64

擴容節點

kubectl edit deployment dm-pttest

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2019-08-16T10:13:49Z"
  generation: 1
  labels:
    app: pttest
  name: dm-pttest
  namespace: default
  resourceVersion: "3871589"
  selfLink: /apis/extensions/v1beta1/namespaces/default/deployments/dm-pttest
  uid: 153a60fb-66df-4884-aa9a-49ac47cebd2c
spec:
  progressDeadlineSeconds: 2147483647
  replicas: 5                             《=====pod數量,有默認2個,調整到5個

保存退出,k8s集群會自動執行;

驗證

kubectl get pods

[root@kubm-02 traefik]# kubectl get pods
NAME                         READY   STATUS    RESTARTS   AGE
dm-pttest-6f6cd797f5-cdjk5   1/1     Running   0          17m
dm-pttest-6f6cd797f5-qd4cl   1/1     Running   0          99s
dm-pttest-6f6cd797f5-r25dc   1/1     Running   0          99s
dm-pttest-6f6cd797f5-tbfmh   1/1     Running   0          99s
dm-pttest-6f6cd797f5-tqh64   1/1     Running   0          17m

#請求
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-r25dc
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-tbfmh
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-tqh64
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-cdjk5
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-qd4cl
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-r25dc
[root@kubm-02 traefik]# curl -H "HOST:pttest.pt.com" http://172.20.101.166/hostname.html
dm-pttest-6f6cd797f5-tbfmh

使用命令調整pod數量

調整pod數量為1;
kubectl scale deployment dm-pttest --replicas=1

調整pod數量為2;
kubectl scale deployment dm-pttest --replicas=2

參考文檔

https://kubernetes.io/zh/docs/concepts/services-networking/connect-applications-service/
https://blog.csdn.net/u010606397/article/details/90752262

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

高唐县| 永善县| 牡丹江市| 湖北省| 湖州市| 浦江县| 阿巴嘎旗| 建阳市| 澳门| 紫阳县| 噶尔县| 桐城市| 尼木县| 环江| 谷城县| 顺平县| 沾化县| 乐业县| 同德县| 龙井市| 平南县| 大邑县| 靖西县| 兴宁市| 开平市| 垦利县| 阳原县| 星座| 湟源县| 华蓥市| 湖北省| 秦皇岛市| 青铜峡市| 遂宁市| 东辽县| 松桃| 汶上县| 承德市| 石台县| 昭觉县| 调兵山市|