手机看片福利永久国产日韩-手机看片369-手机精品在线-手机国产乱子伦精品视频-国产精品嫩草影院在线观看免费-国产精品嫩草影院在线播放

首頁 房產(chǎn) > 正文

Kubernetes中容器探測,你都了解了嗎?

1、概述

容器探測用于檢測容器中的應(yīng)用實(shí)例是否正常工作,是保障業(yè)務(wù)可用性的一種傳統(tǒng)機(jī)制。如果經(jīng)過探測,實(shí)例的狀態(tài)不符合預(yù)期,那么kubernetes就會把該問題實(shí)例" 摘除 ",不承擔(dān)業(yè)務(wù)流量。kubernetes提供了兩種探針來實(shí)現(xiàn)容器探測,分別是:


【資料圖】

liveness probes:存活性探針,用于檢測應(yīng)用實(shí)例當(dāng)前是否處于正常運(yùn)行狀態(tài),如果不是,k8s會重啟容器readiness probes:就緒性探針,用于檢測應(yīng)用實(shí)例當(dāng)前是否可以接收請求,如果不能,k8s不會轉(zhuǎn)發(fā)流量

livenessProbe 決定是否重啟容器,readinessProbe 決定是否將請求轉(zhuǎn)發(fā)給容器。

上面兩種探針目前均支持三種探測方式:

Exec命令:在容器內(nèi)執(zhí)行一次命令,如果命令執(zhí)行的退出碼為0,則認(rèn)為程序正常,否則不正常
……  livenessProbe:    exec:      command:      - cat      - /tmp/healthy……
TCPSocket:將會嘗試訪問一個用戶容器的端口,如果能夠建立這條連接,則認(rèn)為程序正常,否則不正常
……        livenessProbe:    tcpSocket:      port: 8080……
HTTPGet:調(diào)用容器內(nèi)Web應(yīng)用的URL,如果返回的狀態(tài)碼在200和399之間,則認(rèn)為程序正常,否則不正常
……  livenessProbe:    httpGet:      path: / #URI地址      port: 80 #端口號      host: 127.0.0.1 #主機(jī)地址      scheme: HTTP #支持的協(xié)議,http或者h(yuǎn)ttps……
2、存活性探針(1)Exec模式

創(chuàng)建pod-liveness-exec.yaml。

apiVersion: v1kind: Podmetadata:  name: pod-liveness-exec  namespace: devspec:  containers:  - name: nginx    image: nginx    ports:     - name: nginx-port      containerPort: 80    livenessProbe:      exec:        command: ["/bin/cat","/tmp/hello.txt"] # 執(zhí)行一個查看文件的命令

因為/tmp/hello.txt 文件不存在,導(dǎo)致反復(fù)重啟容器。

#進(jìn)入yaml目錄[root@k8s-master ~]# lsanaconda-ks.cfg  pod-liveness-exec.yaml[root@k8s-master ~]# clear[root@k8s-master ~]#[root@k8s-master ~]##查看當(dāng)前dev命名空間下無pod[root@k8s-master ~]# kubectl get pod -n devNo resources found in dev namespace.[root@k8s-master ~]##創(chuàng)建pod[root@k8s-master ~]# kubectl apply -f pod-liveness-exec.yamlpod/pod-liveness-exec created[root@k8s-master ~]##再次查看dev命名空間已創(chuàng)建pod[root@k8s-master ~]# kubectl get pod -n devNAME                READY   STATUS              RESTARTS   AGEpod-liveness-exec   0/1     ContainerCreating   0          5s#查看pod詳情[root@k8s-master ~]# kubectl describe pod pod-liveness-exec -n dev#在最下面Events中,容器創(chuàng)建過程報錯Events:  Type     Reason     Age   From               Message  ----     ------     ----  ----               -------  Normal   Scheduled  28s   default-scheduler  Successfully assigned dev/pod-liveness-exec to k8s-node2  Normal   Pulling    27s   kubelet            Pulling image "nginx"  Normal   Pulled     11s   kubelet            Successfully pulled image "nginx" in 15.48165061s  Normal   Created    11s   kubelet            Created container nginx  Normal   Started    11s   kubelet            Started container nginx  Warning  Unhealthy  7s    kubelet            Liveness probe failed: /bin/cat: /tmp/hello.txt: No such file or directory#再次頻繁查看dev下pod信息可以發(fā)現(xiàn) pod的重啟次數(shù)一直在增加[root@k8s-master ~]# kubectl get pod -n devNAME                READY   STATUS    RESTARTS      AGEpod-liveness-exec   1/1     Running   3 (53s ago)   2m54s[root@k8s-master ~]# kubectl get pod -n devNAME                READY   STATUS    RESTARTS      AGEpod-liveness-exec   1/1     Running   4 (20s ago)   3m1s

這個時候我們將 yaml改為查看已存在的文件。

apiVersion: v1kind: Podmetadata:  name: pod-liveness-exec  namespace: devspec:  containers:  - name: nginx    image: nginx    ports:     - name: nginx-port      containerPort: 80    livenessProbe:      exec:        command: ["/bin/cat","/usr/share/nginx/html/index.html"] # 執(zhí)行一個查看文件的命令 此文件為nginx歡迎頁面 因為我們的容器就是nginx所以這個文件肯定存在的

再看效果:

(2)TCPSocket模式

創(chuàng)建pod-liveness-tcpsocket.yaml。

apiVersion: v1kind: Podmetadata:  name: pod-liveness-tcpsocket  namespace: devspec:  containers:  - name: nginx    image: nginx    ports:     - name: nginx-port      containerPort: 80    livenessProbe:      tcpSocket:        port: 8080 # 嘗試訪問8080端口,端口不存在

因為容器中8080端口未開通,所以連接失敗。

[root@k8s-master ~]# lsanaconda-ks.cfg  pod-liveness-tcpsocket.yaml[root@k8s-master ~]##創(chuàng)建pod[root@k8s-master ~]# kubectl apply -f pod-liveness-tcpsocket.yamlpod/pod-liveness-tcpsocket created[root@k8s-master ~]##獲取pod[root@k8s-master ~]# kubectl get pod -n devNAME                     READY   STATUS    RESTARTS   AGEpod-liveness-tcpsocket   1/1     Running   0          12s#查看詳情可以看出最后一步 連接被拒絕[root@k8s-master ~]# kubectl describe pod pod-liveness-tcpsocket -n devEvents:  Type     Reason     Age               From               Message  ----     ------     ----              ----               -------  Normal   Scheduled  23s               default-scheduler  Successfully assigned dev/pod-liveness-tcpsocket to k8s-node2  Normal   Pulling    22s               kubelet            Pulling image "nginx"  Normal   Pulled     21s               kubelet            Successfully pulled image "nginx" in 475.556438ms  Normal   Created    21s               kubelet            Created container nginx  Normal   Started    21s               kubelet            Started container nginx  Warning  Unhealthy  2s (x2 over 12s)  kubelet            Liveness probe failed: dial tcp 172.17.169.138:8080: connect: connection refused#頻繁獲取pod詳情可以看出  重啟次數(shù)也在不斷增加[root@k8s-master ~]# kubectl get pod -n devNAME                     READY   STATUS    RESTARTS      AGEpod-liveness-tcpsocket   1/1     Running   3 (32s ago)   2m13s[root@k8s-master ~]#[root@k8s-master ~]# kubectl get pod -n devNAME                     READY   STATUS    RESTARTS      AGEpod-liveness-tcpsocket   1/1     Running   3 (46s ago)   2m27s[root@k8s-master ~]#[root@k8s-master ~]# kubectl get pod -n devNAME                     READY   STATUS    RESTARTS      AGEpod-liveness-tcpsocket   1/1     Running   4 (16s ago)   2m37s

然后將 tcpSocket.port 改為80 再重復(fù)以上步驟就會發(fā)現(xiàn),容器正常啟動。

(3)HTTPGet模式

創(chuàng)建pod-liveness-httpget.yaml。

apiVersion: v1kind: Podmetadata:  name: pod-liveness-httpget  namespace: devspec:  containers:  - name: nginx    image: nginx    ports:    - name: nginx-port      containerPort: 80    livenessProbe:      httpGet:  # 其實(shí)就是訪問http://127.0.0.1:80/hello          scheme: HTTP #支持的協(xié)議,http或者h(yuǎn)ttps        port: 80 #端口號        path: /hello #URI地址 此地址不存在
[root@k8s-master ~]##創(chuàng)建pod[root@k8s-master ~]# kubectl apply -f pod-liveness-httpget.yamlpod/pod-liveness-httpget created#獲取pod[root@k8s-master ~]# kubectl get pod -n devNAME                   READY   STATUS              RESTARTS   AGEpod-liveness-httpget   0/1     ContainerCreating   0          7s[root@k8s-master ~]# kubectl get pod -n devNAME                   READY   STATUS              RESTARTS   AGEpod-liveness-httpget   0/1     ContainerCreating   0          13s#查看pod詳情 發(fā)現(xiàn)最后HTTP執(zhí)行報404[root@k8s-master ~]# kubectl describe pod pod-liveness-httpget -n devEvents:  Type     Reason     Age   From               Message  ----     ------     ----  ----               -------  Normal   Scheduled  24s   default-scheduler  Successfully assigned dev/pod-liveness-httpget to k8s-node2  Normal   Pulling    23s   kubelet            Pulling image "nginx"  Normal   Pulled     8s    kubelet            Successfully pulled image "nginx" in 15.416092349s  Normal   Created    8s    kubelet            Created container nginx  Normal   Started    8s    kubelet            Started container nginx  Warning  Unhealthy  4s    kubelet            Liveness probe failed: HTTP probe failed with statuscode: 404#頻繁獲取pod,發(fā)現(xiàn)pod重啟次數(shù)不斷增加[root@k8s-master ~]# kubectl get pod -n devNAME                   READY   STATUS    RESTARTS   AGEpod-liveness-httpget   1/1     Running   0          36s[root@k8s-master ~]# kubectl get pod -n devNAME                   READY   STATUS    RESTARTS     AGEpod-liveness-httpget   1/1     Running   1 (3s ago)   43s[root@k8s-master ~]# kubectl get pod -n devNAME                   READY   STATUS    RESTARTS      AGEpod-liveness-httpget   1/1     Running   2 (47s ago)   117s

然后將 httpGet.path 改為/ 再重復(fù)以上步驟就會發(fā)現(xiàn),容器正常啟動。

至此,已經(jīng)使用liveness Probe演示了三種探測方式,但是查看livenessProbe的子屬性,會發(fā)現(xiàn)除了這三種方式,還有一些其他的配置,在這里一并解釋下:

[root@k8s-master01 ~]# kubectl explain pod.spec.containers.livenessProbeFIELDS:   exec      tcpSocket       httpGet         initialDelaySeconds    # 容器啟動后等待多少秒執(zhí)行第一次探測   timeoutSeconds         # 探測超時時間。默認(rèn)1秒,最小1秒   periodSeconds          # 執(zhí)行探測的頻率。默認(rèn)是10秒,最小1秒   failureThreshold       # 連續(xù)探測失敗多少次才被認(rèn)定為失敗。默認(rèn)是3。最小值是1   successThreshold       # 連續(xù)探測成功多少次才被認(rèn)定為成功。默認(rèn)是1	  
		
    

關(guān)鍵詞:

最近更新

關(guān)于本站 管理團(tuán)隊 版權(quán)申明 網(wǎng)站地圖 聯(lián)系合作 招聘信息

Copyright © 2005-2023 創(chuàng)投網(wǎng) - www.extremexp.net All rights reserved
聯(lián)系我們:39 60 29 14 2@qq.com
皖I(lǐng)CP備2022009963號-3

主站蜘蛛池模板: 日韩精品一区二区三区在线观看| 大学生男男澡堂69gaysex| 欧美精品亚洲精品| 美女的胸www又黄的网站| 18男男gay同性视频| 久久国产精品99精品国产| 天天摸天天摸色综合舒服网| 一级毛片看**在线视频| 娇小枯瘦日本xxxx| 篠田优在线播放| 久久99精品国产麻豆不卡| 女人张开腿让男人桶免费网站| 日韩手机视频| 久久久久久中文字幕| 免费大片黄在线观看| 四虎永久在线精品国产馆v视影院| www.henhenai| 精品国产欧美一区二区| 国产理论片在线观看| 波多野结衣女教师6bd| 全彩无翼口工漫画大全3d| 夜夜操夜夜爱| 九九热爱视频精品| 女人与大拘交在线播放| 久久4k岛国高清一区二区| 孕交动漫h无遮挡肉| 国产午夜精品一区二区三区不卡| 国产麻豆剧果冻传媒一区| 国产美女mm131爽爽爽毛片| 亚洲不卡1卡2卡三卡2021麻豆| 大女小娟二女小妍| 欧美黑人巨大videos精品| 欧美yw193.c㎝在线观看| 国产一区福利| 国产成人综合久久亚洲精品| 欧美aa在线观看| 国产精品一级二级三级| 国产免费全部免费观看| 国产三级在线播放线| 国产精品自产拍在线观看| 免费看美女脱衣服|