Pod存活性探測:用于判斷容器是否處理"運行"狀態,如果檢測未通過,kubelet將會終止容器,根據啟動策略(restartPolicy)決定是否重啟,如果未定義容器默認為"Success"。存活性探測支持的方法有三種:ExecAction,TCPSocketAction,HTTPGetAction。
1.使用exec探測文件存在
[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"] --容器啟動后創建test.txt文件 livenessProbe: exec: command: ["test","-e","/tmp/test.txt"] --檢查test.txt文件,如果存在Pod正常啟動,如果不存在Pod創建不成功
[root@k8s01 yaml]# kubectl apply -f execaction.yaml
pod/execaction created
[root@k8s01 yaml]#
2.使用tcp協議探測端口
[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探測 port: http --這里可以寫協議或者端口,http默認為80端口
[root@k8s01 yaml]# kubectl apply -f tcpaction.yaml
pod/tcpaction created
[root@k8s01 yaml]#
3.使用http協議探測服務
[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: --容器啟動之前啟動以下命令 exec: command: ["/bin/sh","-c","echo 123 > /usr/share/nginx/html/test.html"] livenessProbe: httpGet: path: /test.html --探測nginx是否正常訪問test.html頁面 port: http
[root@k8s01 yaml]# kubectl apply -f httpaction.yaml
pod/httpaction created
[root@k8s01 yaml]#
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。