Pod viability detection
Pod viability detection: used to determine whether the container handles the "running" state. If the test fails, kubelet will terminate the container and decide whether to restart according to the startup policy (restartPolicy). If the container is not defined, it defaults to "Success". There are three methods supported by survivor detection: ExecAction,TCPSocketAction,HTTPGetAction.
1. Use exec to detect the existence of files
[root@k8s01 yaml] # kubectl explain pods.spec.containers.livenessProbe
[root@k8s01 yaml] # vim execaction.yaml
ApiVersion: v1kind: Podmetadata: labels: test: exec-execaction name: execactionspec: containers:-name: execaction image: busybox:latest args: ["/ bin/sh", "- c", "touch / tmp/test.txt"]-- create test.txt file after container startup livenessProbe: exec: command: ["test", "- e", "/ tmp/test.txt"]-- check test.txt file If there is a Pod to start normally, if there is no Pod creation is not successful
[root@k8s01 yaml] # kubectl apply-f execaction.yaml
Pod/execaction created
[root@k8s01 yaml] #
two。 Probe ports using tcp protocol
[root@k8s01 yaml] # vim tcpaction.yaml
ApiVersion: v1kind: Podmetadata: labels: test: tcp-execaction name: tcpactionspec: containers:-name: tcpaction image: nginx:latest ports:-name: http containerPort: 80-- expose port 80 livenessProbe: tcpSocket:-- use tcp to detect port: http-- you can write protocols or ports here. Http defaults to port 80.
[root@k8s01 yaml] # kubectl apply-f tcpaction.yaml
Pod/tcpaction created
[root@k8s01 yaml] #
3. Probe services using the http protocol
[root@k8s01 yaml] # vim httpaction.yaml
ApiVersion: v1kind: Podmetadata: labels: test: http-execaction name: httpactionspec: containers:-name: httpaction image: nginx:latest ports:-name: http containerPort: 80 lifecycle: postStart:-- before the container starts, start the following command exec: command: ["/ bin/sh", "- c" "echo 123 > / usr/share/nginx/html/test.html"] livenessProbe: httpGet: path: / test.html-- probe whether nginx accesses the test.html page port: http
[root@k8s01 yaml] # kubectl apply-f httpaction.yaml
Pod/httpaction created
[root@k8s01 yaml] #