Pod存活性探测

  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]#

相关文章

今天小编给大家分享一下excel图案样式如何设置的相关知识点,...
这篇文章主要讲解了“win10设置过的壁纸如何删除”,文中的讲...
这篇“Xmanager怎么显示远程linux程序的图像”文章的知识点大...
今天小编给大家分享一下xmanager怎么连接linux的相关知识点,...
这篇“如何重置Linux云服务器的远程密码”文章的知识点大部分...
本篇内容介绍了“Linux云服务器手动配置DNS的方法是什么”的...