k8s健康检查配置yaml文件编写

    技术2022-07-21  82

    1,就绪检测,

    apiVersion: v1 kind: Pod metadata: name: readiness-httpget-pod namespace: default #放在那个空间下 spec: ontainers: - name: readiness-httpget-container image: wangyanglinux/myapp:v1 imagePullPolicy: IfNotPresent #镜像下载策略,如果有不下载,就算标签为最新版本,也不会下载 readinessProbe: #就绪检测 httpGet: #检测方案 port: 80 #检测80端口 path: /index1.html #检测路径访问的/下那个文件 initialDelaySeconds: 1 #初始化检测演延时间秒为单位 periodSeconds: 3 #如果失败再次检测时间秒为单位

    2,存活检测

    apiVersion: v1 kind: Pod metadata: name: liveness-exec-pod namespace: default spec: containers: - name: liveness-exec-container image: hub.atguigu.com/library/busybox imagePullPolicy: IfNotPresent command: ["/bin/sh","-c",“touch /tmp/live ; sleep 60; rm -rf /tmp/live; sleep 3600”] livenessProbe: #存活检测 exec: command: [“test”,"-e","/tmp/live"] #检测这个文件是不是存在存在为0不存在不为0 initialDelaySeconds: 1 #容器正常运行一秒以后开始第一次检测 periodSeconds: 3 #3秒以后再次检测

    3,httpget存活检测

    @省略了前面镜像名称什么的 ports: 给这个容器定义了一个端口 - name: http 端口名称 containerPort: 80 端口号 livenessProbe: 存活检测 httpGet: 使用httpget检测 port: http 检测的是http协议或者80端口 path: /index.html 检测的文件 initialDelaySeconds: 1 启动后一秒开始 periodSeconds: 3 每三秒检测一次 timeoutSeconds: 10 检测http超时时间秒为单位

    4,tcp检测

    apiVersion: v1 kind: Pod metadata: name: probe-tcp spec: containers: - name: nginx image: hub.atguigu.com/library/myapp:v1 livenessProbe: initialDelaySeconds: 5 启动后5秒开始检测 timeoutSeconds: 1 超时时间 periodSeconds: 3 重试时间 tcpSocket: #使用tcp的方式检测 port: 80 检测的端口是80端口

    Processed: 0.015, SQL: 9