kubernetes probe

概述

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

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

參數

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

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

支持的類型

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章