您好,登錄后才能下訂單哦!
Pod存活性探測(cè):用于判斷容器是否處理"運(yùn)行"狀態(tài),如果檢測(cè)未通過(guò),kubelet將會(huì)終止容器,根據(jù)啟動(dòng)策略(restartPolicy)決定是否重啟,如果未定義容器默認(rèn)為"Success"。存活性探測(cè)支持的方法有三種:ExecAction,TCPSocketAction,HTTPGetAction。
1.使用exec探測(cè)文件存在
[root@k8s01 yaml]# kubectl explain pods.spec.containers.livenessProbe
[root@k8s01 yaml]# vim execaction.yaml
apiVersion: v1 kind: Pod metadata: labels: test: exec-execaction name: execaction spec: containers: - name: execaction image: busybox:latest args: ["/bin/sh","-c","touch /tmp/test.txt"] --容器啟動(dòng)后創(chuàng)建test.txt文件 livenessProbe: exec: command: ["test","-e","/tmp/test.txt"] --檢查test.txt文件,如果存在Pod正常啟動(dòng),如果不存在Pod創(chuàng)建不成功
[root@k8s01 yaml]# kubectl apply -f execaction.yaml
pod/execaction created
[root@k8s01 yaml]#
2.使用tcp協(xié)議探測(cè)端口
[root@k8s01 yaml]# vim tcpaction.yaml
apiVersion: v1 kind: Pod metadata: labels: test: tcp-execaction name: tcpaction spec: containers: - name: tcpaction image: nginx:latest ports: - name: http containerPort: 80 --暴露80端口 livenessProbe: tcpSocket: --使用tcp探測(cè) port: http --這里可以寫(xiě)協(xié)議或者端口,http默認(rèn)為80端口
[root@k8s01 yaml]# kubectl apply -f tcpaction.yaml
pod/tcpaction created
[root@k8s01 yaml]#
3.使用http協(xié)議探測(cè)服務(wù)
[root@k8s01 yaml]# vim httpaction.yaml
apiVersion: v1 kind: Pod metadata: labels: test: http-execaction name: httpaction spec: containers: - name: httpaction image: nginx:latest ports: - name: http containerPort: 80 lifecycle: postStart: --容器啟動(dòng)之前啟動(dòng)以下命令 exec: command: ["/bin/sh","-c","echo 123 > /usr/share/nginx/html/test.html"] livenessProbe: httpGet: path: /test.html --探測(cè)nginx是否正常訪問(wèn)test.html頁(yè)面 port: http
[root@k8s01 yaml]# kubectl apply -f httpaction.yaml
pod/httpaction created
[root@k8s01 yaml]#
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。