关于Kubernetes-v1.23.6-readinessProbe-就绪探针的效果演示及说明
Posted on 2023-09-07 23:12 520_1351 阅读(62) 评论(0) 编辑 收藏 举报1、本文还是先创建一个带有 readinessProbe-就绪探针 的yaml 文件, nginx-demo.yaml,内容如下:
apiVersion: v1 # api 文档版本 kind: Pod # 资源对象类型,也可以配置为像Deployment、StatefulSet这一类的对象 metadata: # Pod 相关的元数据,用于描述 Pod 的数据 name: nginx-demo # Pod 的名称 namespace: 'default' # 命名空间的配置 spec: # 期望 Pod 按照这里面的描述进行创建 containers: # 对于 Pod 中的容器描述 - name: nginx # 容器的名称 image: nginx:1.7.9 # 指定容器的镜像 imagePullPolicy: IfNotPresent # 镜像拉取策略,指定如果本地有就用本地的,如果没有就拉取远程的 startupProbe: # 应用启动探针配置 exec: command: - sh - -c - "sleep 1;echo success > /inited" failureThreshold: 3 # 失败多少次才算真正失败 periodSeconds: 10 # 间隔时间 successThreshold: 1 # 多少次监测成功才算真正的成功 timeoutSeconds: 5 # 请求的超时时间 readinessProbe: # 应用就绪探针配置 httpGet: path: /started.html port: 80 failureThreshold: 5 # 失败多少次才算真正失败 periodSeconds: 10 # 间隔时间 successThreshold: 1 # 多少次监测成功才算真正的成功 timeoutSeconds: 3 # 请求的超时时间 ports: - name: http # 端口名称 containerPort: 80 # 描述容器内要暴露什么端口 protocol: TCP # 描述该端口是基于哪种协议通信的 restartPolicy: OnFailure # 重启策略,只有失败的情况才会重启
2、然后再创建pod,使用 kubectl create -f nginx-demo.yaml 命令进行pod的创建
3、接下来我们观察状态的变化,pod的状态,始终没有READY ,一直是0/1
[root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-demo 0/1 Running 0 25s NAME READY STATUS RESTARTS AGE nginx-demo 0/1 Running 0 53s [root@k8s-master ~]# kubectl describe pod nginx-demo ......................省略部分.............................. Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 55s default-scheduler Successfully assigned default/nginx-demo to k8s-node2 Normal Pulled 54s kubelet Container image "nginx:1.7.9" already present on machine Normal Created 54s kubelet Created container nginx Normal Started 53s kubelet Started container nginx Warning Unhealthy 5s (x5 over 44s) kubelet Readiness probe failed: HTTP probe failed with statuscode: 404 [root@k8s-master ~]# [root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-demo 0/1 Running 0 8m59s [root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-demo 0/1 Running 0 9m [root@k8s-master ~]# kubectl describe pod nginx-demo Name: nginx-demo Namespace: default Priority: 0 Node: k8s-node2/192.168.113.122 Start Time: Thu, 07 Sep 2023 22:55:23 +0800 Labels: <none> Annotations: cni.projectcalico.org/containerID: b2a16d93bb97564900351dc36dbdc1b0714fa4d344bf8d0ec6361c647311d63e cni.projectcalico.org/podIP: 10.224.169.135/32 cni.projectcalico.org/podIPs: 10.224.169.135/32 Status: Running IP: 10.224.169.135 IPs: IP: 10.224.169.135 Containers: nginx: Container ID: docker://45572be22ee60b8f62143a3890308775562cede4c2c1828128dbbd693f8f9459 Image: nginx:1.7.9 Image ID: docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451 Port: 80/TCP Host Port: 0/TCP State: Running Started: Thu, 07 Sep 2023 22:55:25 +0800 Ready: False Restart Count: 0 Readiness: http-get http://:80/started.html delay=0s timeout=3s period=10s #success=1 #failure=5 Startup: exec [sh -c sleep 1;echo success > /inited] delay=0s timeout=5s period=10s #success=1 #failure=3 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-jq6wz (ro) Conditions: Type Status Initialized True Ready False ContainersReady False PodScheduled True Volumes: kube-api-access-jq6wz: Type: Projected (a volume that contains injected data from multiple sources) TokenExpirationSeconds: 3607 ConfigMapName: kube-root-ca.crt ConfigMapOptional: <nil> DownwardAPI: true QoS Class: BestEffort Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 9m2s default-scheduler Successfully assigned default/nginx-demo to k8s-node2 Normal Pulled 9m1s kubelet Container image "nginx:1.7.9" already present on machine Normal Created 9m1s kubelet Created container nginx Normal Started 9m kubelet Started container nginx Warning Unhealthy 3m52s (x34 over 8m51s) kubelet Readiness probe failed: HTTP probe failed with statuscode: 404 [root@k8s-master ~]# [root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-demo 0/1 Running 0 9m7s [root@k8s-master ~]#
4、此时,我们可以执行 ,kubectl cp started.html nginx-demo:/usr/share/nginx/html/ 改变就绪探针的结果,效果如下:
[root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-demo 0/1 Running 0 13m [root@k8s-master ~]# kubectl cp started.html nginx-demo:/usr/share/nginx/html/ [root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-demo 0/1 Running 0 13m [root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-demo 1/1 Running 0 13m [root@k8s-master ~]# kubectl describe pod nginx-demo Name: nginx-demo Namespace: default Priority: 0 Node: k8s-node2/192.168.113.122 Start Time: Thu, 07 Sep 2023 22:55:23 +0800 Labels: <none> Annotations: cni.projectcalico.org/containerID: b2a16d93bb97564900351dc36dbdc1b0714fa4d344bf8d0ec6361c647311d63e cni.projectcalico.org/podIP: 10.224.169.135/32 cni.projectcalico.org/podIPs: 10.224.169.135/32 Status: Running IP: 10.224.169.135 IPs: IP: 10.224.169.135 Containers: nginx: Container ID: docker://45572be22ee60b8f62143a3890308775562cede4c2c1828128dbbd693f8f9459 Image: nginx:1.7.9 Image ID: docker-pullable://nginx@sha256:e3456c851a152494c3e4ff5fcc26f240206abac0c9d794affb40e0714846c451 Port: 80/TCP Host Port: 0/TCP State: Running Started: Thu, 07 Sep 2023 22:55:25 +0800 Ready: True Restart Count: 0 Readiness: http-get http://:80/started.html delay=0s timeout=3s period=10s #success=1 #failure=5 Startup: exec [sh -c sleep 1;echo success > /inited] delay=0s timeout=5s period=10s #success=1 #failure=3 Environment: <none> Mounts: /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-jq6wz (ro) Conditions: Type Status Initialized True Ready True ContainersReady True PodScheduled True Volumes: kube-api-access-jq6wz: Type: Projected (a volume that contains injected data from multiple sources) TokenExpirationSeconds: 3607 ConfigMapName: kube-root-ca.crt ConfigMapOptional: <nil> DownwardAPI: true QoS Class: BestEffort Node-Selectors: <none> Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s node.kubernetes.io/unreachable:NoExecute op=Exists for 300s Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal Scheduled 13m default-scheduler Successfully assigned default/nginx-demo to k8s-node2 Normal Pulled 13m kubelet Container image "nginx:1.7.9" already present on machine Normal Created 13m kubelet Created container nginx Normal Started 13m kubelet Started container nginx Warning Unhealthy 3m25s (x68 over 13m) kubelet Readiness probe failed: HTTP probe failed with statuscode: 404 [root@k8s-master ~]# kubectl get po NAME READY STATUS RESTARTS AGE nginx-demo 1/1 Running 0 13m [root@k8s-master ~]#
尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/17686352.html
作者:一名卑微的IT民工
出处:https://www.cnblogs.com/5201351
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
由于博主的水平不高,文章没有高度、深度和广度,只是凑字数,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个卑微的IT民工!