Kubernetes 第七章 Configure Liveness and Readiness Probes

Configure Liveness and Readiness Probes

Define a liveness command

对Pod内个容器健康检查的设置,当探测无响应几次后将自动重启该容器,检查方法有exec、httpGet和tcpSocket,对一个容器只需设置其中一种方法即可

探针类型有三种:
 ExecAction、TCPSocketAction、HTTPGetAction

 在下面pod启动时报错,查询文档:https://feisky.gitbooks.io/kubernetes/content/troubleshooting/pod.html  ,删除网桥让kubelet 重新加载flannel ,重置后恢复

root@kube /]# ip link set cni0 down
[root@kube /]# ip link delete dev cni0

  

Warning  FailedCreatePodSandBox  4m30s (x26505 over 17h)  kubelet, kube.node2  (combined from similar events): Failed create pod sandbox: rpc error: code = Unknown desc = failed to set up sandbox container "a751a0c6891b9fc8b2f07cacfb7476a9bff9d7151c6f37073820cabec6a98a53" network for pod "liveness-exec": NetworkPlugin cni failed to set up pod "liveness-exec_default" network: failed to set bridge addr: "cni0" already has an IP address different from 10.244.1.1/24

  

exec 方式

root@kube test]# cat pod-liveness.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-exec
spec:
  containers:
  - name: liveness
    image: busybox
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30;rm -fr /tmp/healthy; sleep 600    //传递给 container 的参数,创建一个文件 30 后再删除
    livenessProbe:    //存活探测
      exec:            //类型命令执行
        command:    //执行命令
        - cat      
        - /tmp/healthy     //检查文件在不在
      initialDelaySeconds: 5
      periodSeconds: 5
[root@kube test]# 

  

 http 方式

[root@kube test]# cat liveness-http.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-http
spec:
  containers:
  - name: liveness-nginx
    image: nginx 
    livenessProbe:
      httpGet:
        path: / 
        port: 80
      initialDelaySeconds: 3
      periodSeconds: 3
[root@kube test]# 

  

tcp 方式

[root@kube test]# cat liveness-tcp.yaml 
apiVersion: v1
kind: Pod
metadata:
  labels:
    test: liveness
  name: liveness-tcp
spec:
  containers:
  - name: liveness-tcp
    image: nginx 
    ports:
    - containerPort: 80
    livenessProbe:
      tcpSocket:
        port: 80
      initialDelaySeconds: 3
      periodSeconds: 3
[root@kube test]# 

  

 

转载于:https://www.cnblogs.com/zy09/p/11249239.html

你可能感兴趣的:(Kubernetes 第七章 Configure Liveness and Readiness Probes)