k8s系列(14)--探针检测

apiVersion: v1
kind: Pod
metadata:
name: readiness-httpget-pod
namespace: default
spec:
containers:

  • name: readiness-httpget-container
    image: 192.168.68.253:8253/library/nginx:latest
    imagePullPolicy: IfNotPresent
    readinessProbe:
    httpGet:
    port: 80
    path: /index1.html
    initialDelaySeconds: 1
    periodSeconds: 3
    进入容器
    kubectl exec readiness-httpget-pod -it -- /bin/sh
    exit退出
    文件已经存在,但是检测还是失败了

存活检测
apiVersion: v1
kind: Pod
metadata:
name: liveness-exec-pod
namespace: default
spec:
containers:

  • name: livness-exec-container
    image: 192.168.68.253:8253/library/busybox:latest
    imagePullPolicy: IfNotPresent
    command: ["/bin/sh","-с", "touch /tmp/live ; sleep 60; rm -rf /tmp/live; sleep 3600"]
    livenessProbe:
    exec:
    command: ["test","-е","/tmp/live"]
    initialDelaySeconds: 1
    periodSeconds: 3
    不知道为什么,文件夹没删掉,又失败了,拼写错误,rm -rf没有空格,上面也是拼写失败,index1.html后面多了个I

apiVersion: v1
kind: Pod
metadata:
name: liveness-httpget-pod
namespace: default
spec:
containers:

  • name: liveness-httpget-container
    image: 192.168.68.253:8253/library/nginx:latest
    imagePullPolicy: IfNotPresent
    ports:
    • name: http
      containerPort: 80
      livenessProbe:
      httpGet:
      port: http
      path: /index.html
      initialDelaySeconds: 1
      periodSeconds: 3
      timeoutSeconds: 10

kubectl exec podname -it -- rm -rf /usr/share/nginx/html/index/html

apiVersion: v1
kind: Pod
metadata:
name: probe-tcp
spec:
containers:

  • name: nginx
    image: 192.168.68.253:8253/library/nginx:latest
    imagePullPolicy: IfNotPresent
    livenessProbe:
    initialDelaySeconds: 5
    timeoutSeconds: 1
    tcpSocket:
    port: 80

start/end

apiVersion: v1
kind: Pod
metadata:
name: lifecycle-demo
spec:
containers:

  • name: lifecycle-demo-container
    image: 192.168.68.253:8253/library/nginx:latest
    lifecycle:
    postStart:
    exec:
    command: ["/bin/sh", "-с", "echo Hello from the poststart handler > /usr/share/message"]
    prestop:
    exec:
    command: ["/bin/sh","-с", "echo Hello from the poststop handler > /usr/share/message"]

status的值
挂起(Pending):Pod己被Kubernetes系统接受,但有一个或者多个容器镜像尚未创建。等待时间包括调度Pod的时间和通过网络下载镜像的时间,这可能需要花点时间
运行中(Running):该Pod已经绑定到了一个节点上,Pod 中所有的容器都已被创建。至少有一个容器正在运行,或者正处于启动或重启状态
成功(Succeeded):Pod 中的所有容器都被成功终止,并且不会再重启
失败(Failed):Pod 中的所有容器都已终止了,并且至少有一个容器是因为失败终止。也就是说,容器以非0状态退出或者被系统终止
未知(Unknown):因为某些原因无法取得Pod的状态,通常是因为与Pod所在主机通信失败

命令式编程:重复调用重复执行,一步一步走
声明式编程:只要最终结果一致就不会重新执行,告诉结果,自动执行,数据库就是声明式编程

posted @ 2025-09-22 20:52  再练习两年半  阅读(7)  评论(0)    收藏  举报