Kubernete Pod 容器探针

0
(0)

livenessProbe 用来检测容器是否存活。

readinessProbe 用来检测服务是否可用(就绪),

另外还有 startupProbe 用来探测服务启动。(用在启动时间比较长的情况,启动成功后才交给livenessProbe)

ExeAction 在容器内执行命令,返回码为0表示成功

 apiVersion: v1
 kind: Pod
 metadata:
   name: test-liveness-probe1
 spec:
   containers:
   - name: test-liveness-probe1
     image: busybox
     resources:
       limits:
         memory: "8Mi"
         cpu: "500m"
     command: ['/bin/sh','-c','echo ok > /tmp/health;sleep 10; rm -rf /tmp/health; sleep 600']
     livenessProbe:
       exec:
         command:
           - cat 
           - /tmp/health
       initialDelaySeconds: 15
       timeoutSeconds: 3  #命令超时时间,1.20之前无效
       periodSeconds: 5   #探测间隔
       failureThreshold: 3 # 重试几次表示失败

tcpSocket 通过端口测试TCP连接,能够建立连接表示成功

apiVersion: v1
kind: Pod
metadata:
  name: test-liveness-probe1
spec:
  containers:
  - name: test-liveness-probe1
    image: busybox
    resources:
      limits:
        memory: "8Mi"
        cpu: "500m"
    livenessProbe:
      tcpSocket:
          port: 8080
      initialDelaySeconds: 15
      timeoutSeconds: 1  #探测超时时间,默认1
      periodSeconds: 5   #循环间隔
      failureThreshold: 3 # 连续探测几次失败认为失败,默认3,最小1

Http 请求测试,返回的代码在200-400之间表示成功

apiVersion: v1
kind: Pod
metadata:
  name: test-liveness-probe1
spec:
  containers:
  - name: test-liveness-probe1
    image: busybox
    resources:
      limits:
        memory: "8Mi"
        cpu: "500m"
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
          - name: Custom-Header
            value: vvv
      initialDelaySeconds: 15
      timeoutSeconds: 3  #探测超时时间
      periodSeconds: 5   #循环间隔
      failureThreshold: 3 # 连续探测几次失败认为失败

readinessGates 这个没看懂怎么用通过外部Controller控制pods是否可用。

这篇文章有用吗?

平均评分 0 / 5. 投票数: 0

到目前为止还没有投票!成为第一位评论此文章。

很抱歉,这篇文章对您没有用!

让我们改善这篇文章!

告诉我们我们如何改善这篇文章?

分类: