kubernetes probe

概述

readinessProbe主要探測服務是否就緒,若是你的應用的readinessProbe運行失敗,那麼就會從組成service的端點中刪除,這樣就不會有流量經過Kubernetes服務發現機制來發送給它 shell

livenessProbe探測服務是否可,不可用時重啓podtcp

參數google

  • initialDelaySeconds:容器啓動後,第一次執行探測須要等待多少秒
  • periodSeconds:執行探測的頻率,默認是10秒,最小1秒
  • timeoutSeconds:探測超時時間,告訴Kubernetes應該爲健康檢查等待多長時間,默認1秒,最小1秒

官方文檔: https://kubernetes.io/docs/ta...code

支持的類型

http 請求

spec:
  containers:
  - name: liveness
    args:
    - /server
    image: gcr.io/google_containers/liveness
    readinessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
          - name: X-Custom-Header
            value: Awesome
      initialDelaySeconds: 20
      periodSeconds: 10
      timeouteSeconds: 1
    livenessProbe:
      httpGet:
        path: /healthz
        port: 8080
        httpHeaders:
          - name: X-Custom-Header
            value: Awesome
      initialDelaySeconds: 20
      periodSeconds: 10
      timeouteSeconds: 1

tcp 端口

spec:
  containers:
  - name: goproxy
    image: gcr.io/google_containers/goproxy:0.1
    ports:
    - containerPort: 8080
    readinessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 20
      periodSeconds: 10
      timeoutSeconds: 1
    livenessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 20
      periodSeconds: 10
      timeoutSeconds: 1

sh命令或shell腳本

spec:
  containers:
  - name: liveness
    args:
    - /bin/sh
    - -c
    - touch /tmp/healthy; sleep 30; rm -rf /tmp/healthy; sleep 600
    image: gcr.io/google_containers/busybox
    livenessProbe:
      exec:
        command:
        - cat
        - /tmp/healthy
      initialDelaySeconds: 5
      periodSeconds: 5
相關文章
相關標籤/搜索