示例:livenessProbe和HTTPGetAction: [root@localhost7C ~]#cat nginx-http.yml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx-linux39 template: metadata: labels: app: nginx-linux39 spec: containers: - name: nginx image: harbor.linux39.com/baseimages/nginx:1.14.2 ports: - containerPort: 80 livenessProbe: httpGet: #path: /monitor/monitor.html path: /index.html port: 80 initialDelaySeconds: 5 periodSeconds: 3 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 #readinessProbe: #探针类型 # httpGet: #探针方式 # #path: /monitor/monitor.html #测试地址 # path: /index.html # port: 80 # initialDelaySeconds: 5 #参数 # periodSeconds: 3 # timeoutSeconds: 5 # successThreshold: 1 # failureThreshold: 3 --- kind: Service apiVersion: v1 metadata: labels: app: magedu-nginx-service-label name: magedu-nginx-service namespace: default spec: type: NodePort ports: - name: http port: 80 protocol: TCP targetPort: 80 nodePort: 30004 selector: app: nginx-linux39 #说明重启过多次。目前状态为CrashLoopBackOff [root@localhost7C ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-deployment-67c7cf88-m5nqt 0/1 CrashLoopBackOff 4 2m24s 10.10.3.54 localhost7f.localdomain <none> <none>
示例:readinessProbe和HTTPGetAction: apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx-linux39 template: metadata: labels: app: nginx-linux39 spec: containers: - name: nginx image: harbor.linux39.com/baseimages/nginx:1.14.2 ports: - containerPort: 80 readinessProbe: httpGet: #path: /monitor/monitor.html #测试 path: /index.html port: 80 initialDelaySeconds: 5 periodSeconds: 3 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 #livenessProbe: # httpGet: # #path: /monitor/monitor.html # path: /index.html # port: 80 # initialDelaySeconds: 5 # periodSeconds: 3 # timeoutSeconds: 5 # successThreshold: 1 # failureThreshold: 3 --- kind: Service apiVersion: v1 metadata: labels: app: magedu-nginx-service-label name: magedu-nginx-service namespace: default spec: type: NodePort ports: - name: http port: 80 protocol: TCP targetPort: 80 nodePort: 30004 selector: app: nginx-linux39 #容器正常 [root@localhost7C ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES nginx-deployment-6b9856b557-cnsvd 0/1 Running 0 3m12s 10.10.3.55 localhost7f.localdomain <none> <none> #Endpoints:删除 [root@localhost7C ~]# kubectl describe services -n default magedu-nginx-service Name: magedu-nginx-service Namespace: default Labels: app=magedu-nginx-service-label Annotations: kubectl.kubernetes.io/last-applied-configuration: {"apiVersion":"v1","kind":"Service","metadata":{"annotations":{},"labels":{"app":"magedu-nginx-service-label"},"name":"magedu-nginx-servic... Selector: app=nginx-linux39 Type: NodePort IP: 10.20.101.71 Port: http 80/TCP TargetPort: 80/TCP NodePort: http 30004/TCP Endpoints: Session Affinity: None External Traffic Policy: Cluster Events: <none> #显示错误 [root@localhost7C ~]# kubectl describe pod nginx-deployment-6b9856b557-cnsvd ... ... Warning Unhealthy 57s (x48 over 3m18s) kubelet, localhost7f.localdomain Readiness probe failed: HTTP probe failed with statuscode: 404
#TCPSocketAction处理方式,结果一样。 [root@localhost7C case5]# cat nginx-tcp.yml apiVersion: apps/v1 kind: Deployment metadata: name: nginx-deployment labels: app: nginx spec: replicas: 1 selector: matchLabels: app: nginx-linux39 template: metadata: labels: app: nginx-linux39 spec: containers: - name: nginx image: harbor.linux39.com/baseimages/nginx:1.14.2 ports: - containerPort: 80 livenessProbe: tcpSocket: #tcp方式 port: 80 #port: 8080 initialDelaySeconds: 5 periodSeconds: 3 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 readinessProbe: tcpSocket: #tcp方式 port: 80 #port: 8080 initialDelaySeconds: 5 periodSeconds: 3 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 --- kind: Service apiVersion: v1 metadata: labels: app: magedu-nginx-service-label name: magedu-nginx-service namespace: default spec: type: NodePort ports: - name: http port: 80 protocol: TCP targetPort: 80 nodePort: 30004 selector: app: nginx-linux39
#ExecAction:处理方式,结果一样。 [root@localhost7C case5]# cat redis-ExecAction.yml apiVersion: apps/v1 kind: Deployment metadata: name: redis-deployment labels: app: redis spec: replicas: 1 selector: matchLabels: app: redis-linux39 template: metadata: labels: app: redis-linux39 spec: containers: - name: redis image: redis:4.0.14 ports: - containerPort: 6379 livenessProbe: exec: #ExecAction:处理方式 command: #- /apps/redis/bin/redis-cli - /usr/local/bin/redis-cli - quit initialDelaySeconds: 5 periodSeconds: 3 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 readinessProbe: exec: #ExecAction:处理方式 command: #- /apps/redis/bin/redis-cli #错误路径 - /usr/local/bin/redis-cli - quit initialDelaySeconds: 5 periodSeconds: 3 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 --- kind: Service apiVersion: v1 metadata: labels: app: magedu-redis-service-label name: magedu-redis-service namespace: default spec: type: NodePort ports: - name: http port: 80 protocol: TCP targetPort: 6379 nodePort: 30005 selector: app: redis-linux39
k8s在Pod出现异常的时候会自动将Pod重启以恢复Pod中的服务,Pod重启策略。 restartPolicy: Always: 当容器异常时,k8s自动重启该容器,ReplicationController/Replicaset/Deployment。 OnFailure: 当容器失败时(容器停止运行且退出码不为0),k8s自动重启该容器。 Never: 不论容器运行状态如何都不会重启该容器,Job或CronJob。 [root@localhost7C case5]# cat redis-ExecAction.yml apiVersion: apps/v1 kind: Deployment metadata: name: redis-deployment labels: app: redis spec: replicas: 1 selector: matchLabels: app: redis-linux39 template: metadata: labels: app: redis-linux39 spec: containers: - name: redis image: redis:4.0.14 ports: - containerPort: 6379 livenessProbe: exec: #ExecAction:处理方式 command: - /apps/redis/bin/redis-cli #错误路径 #- /usr/local/bin/redis-cli - quit initialDelaySeconds: 5 periodSeconds: 3 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 readinessProbe: exec: #ExecAction:处理方式 command: - /apps/redis/bin/redis-cli #错误路径 #- /usr/local/bin/redis-cli - quit initialDelaySeconds: 5 periodSeconds: 3 timeoutSeconds: 5 successThreshold: 1 failureThreshold: 3 restartPolicy: Always --- kind: Service apiVersion: v1 metadata: labels: app: magedu-redis-service-label name: magedu-redis-service namespace: default spec: type: NodePort ports: - name: http port: 80 protocol: TCP targetPort: 6379 nodePort: 30005 selector: app: redis-linux39 #当配合两种探针时,一直循环重启 [root@localhost7C ~]# kubectl get pod -o wide NAME READY STATUS RESTARTS AGE IP NODE NOMINATED NODE READINESS GATES redis-deployment-6c594c6dd6-8dpst 0/1 CrashLoopBackOff 12 21m 10.10.3.63 localhost7f.localdomain <none> <none>
我们在日常的集群维护中经常使用 kubectl get pod 查看pod的状态。 状态值 含义 CrashLoopBackOff 容器退出,kubelet正在将它重启 Terminating 结束 completed job资源正常启动 InvalidImageName 无法解析镜像名称 ImageInspectError 无法校验镜像 ErrImageNeverPull 策略禁止拉取镜像 ImagePullBackOff 正在重试拉取 RegistryUnavailable 连接不到镜像仓库(如:harbor) ErrImagePull 拉取镜像出错 CreateContainerConfigError 不能创建kubelet使用的容器配置 CreateContainerError 创建容器失败 m.internalLifecycle.PreStartContainer 执行hook报错 RunContainerError 启动容器失败 PostStartHookError 执行hook报错 ContainersNotInitialized 容器没有初始化完毕 ContainersNotReady 容器没有准备完毕 ContainerCreating 容器创建中 PodInitializing pod 初始化中 DockerDaemonNotReady docker还没有完全启动 NetworkPluginNotReady 网络插件还没有完全启动 Evicted 即驱赶(当节点出现异常时,kubernetes将有相应的 Pending: #正在创建Pod但是Pod中的容器还没有全部被创建完成,处于此状态的Pod应该检查Pod依赖的存储是否有权限挂载、镜像是否可以下载、调度是否正常等。 Failed #Pod中有容器启动失败而导致pod工作异常。 Unknown #由于某种原因无法获得pod的当前状态,通常是由于与pod所在的node节点通信错误。 Succeeded #Pod中的所有容器都被成功终止即pod里所有的containers均已terminated。 Unschedulable: #Pod不能被调度,kube-scheduler没有匹配到合适的node节点 PodScheduled #pod正处于调度中,在kube-scheduler刚开始调度的时候,还没有将pod分配到指定的pid,在筛选出合适的节点后就会更新etcd数据,将pod分配到指定的pod Initialized #所有pod中的初始化容器已经完成了 ImagePullBackOff:#Pod所在的node节点下载镜像失败 Running #Pod内部的容器已经被创建并且启动。 Ready #表示pod中的容器已经可以提供访问服务
标签:name,80,探针,app,redis,nginx,pod,重启 From: https://www.cnblogs.com/Yuanbangchen/p/17191568.html