参考 https:
在pod之上 添加一个探针, kubelet通过探针去检查应用
容器式运行的应用类似于“黑盒”,默认不会配置探针时 所以kublet只会监视pod的存活状态(但是无法检查是否处于正常的服务 对于pod不处理请求的情况无法检查 不能执行一些高级的检查)
为了便于k8s对其进行监测,云原生应用应该输出用于监视自身的API
initialDelaySeconds
periodSeconds: 执行探测动作的时间间隔,默认是 10 秒探测一次。
timeoutSeconds: 探测动作的超时时间,如果超时就认为探测失败,默认是 1 秒。successThreshold: 连续几次探测成功才认为是正常,对于 startupProbe 和 livenessProbe 来说它只能是 1。
failureThreshold: 连续探测失败几次才认为是真正发生了异常,默认是 3 次。
同时定义了三种探针
测试效果
Always 无论本地是否有相关的镜像 总是要到registry上下载 - 缺点 浪费带宽 - 好处 避免本地污染
if not present 本地不存在相关的image是 才去registry上下载 - 好处 运行快 - 缺点 可能被污染 never 从不下载
特殊情况 image 的tag是latest
apiVersion: v1 kind: Pod metadata: name: pod-probe-demo namespace: default spec: containers: - name: demo image: ikubernetes/demoapp:v1.0 imagePullPolicy: IfNotPresent startupProbe: exec: command: ['/bin/sh','-c','test','"$(curl -s 127.0.0.1/livez)"=="OK"'] initialDelaySeconds: 0 failureThreshold: 3 periodSeconds: 2 livenessProbe: httpGet: path: '/livez' port: 80 scheme: HTTP initialDelaySeconds: 3 timeoutSeconds: 2 readinessProbe: httpGet: path: '/readyz' port: 80 scheme: HTTP initialDelaySeconds: 15 timeoutSeconds: 2 restartPolicy: Always