簡體   English   中英

Kubernetes ClusterIP服務初始延遲或活躍

[英]Kubernetes ClusterIP service initial delay or liveness

我在GCP上有一個Kubernetes部署,還有一個ClusterIP服務來發現此部署中的Pod。 部署包含多個副本集容器,這些容器根據我們的水平容器標量配置(基於CPU利用率)來來去去。

現在,當創建新的副本集容器時,應用程序需要一些時間才能開始維修。 但是,在應用程序准備就緒之前,ClusterIP已經開始將請求分發到新的副本集pod,這將導致不為請求提供服務。

ClusterIP服務Yaml:

apiVersion: v1
kind: Service
metadata:
  labels:
    app: service-name
    tier: backend
    environment: "dev"
    creator: internal
  name: service-name
spec:
  clusterIP: None
  ports:
  - name: https
    protocol: TCP
    port: 7070
    targetPort: 7070
  selector:
    app: dep-name
    tier: "backend"
    environment: "dev"
    creator: "ME"
  type: ClusterIP

應用程序啟動后,如何通知ClusterIP開始將請求分發到新的pod? 為此可以設置任何初始延遲或活躍度探針嗎?

Kubernetes為此提供了准備情況調查。 使用就緒探針,Kubernetes不會將流量發送到Pod,直到探針成功為止。 更新部署時,它還將使舊副本運行,直到對新副本成功進行探測為止。 這意味着,如果您的新Pod以某種方式損壞,它們將永遠看不到流量,而您的舊Pod將繼續為部署提供所有流量。

您需要使用以下准備情況探針更新部署文件:

readinessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy
  initialDelaySeconds: 5
  periodSeconds: 5

如果您的應用程序具有http探針,那么您也可以在HTTP模式下設置就緒探針。

有關更多信息,如何使用就緒探針,請參考:

https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-readiness-probes

您應該具有https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-readiness-probes中的文檔中定義的就緒探針。

根據文檔中的定義,您應該能夠使用initialDelaySecondsperiodSeconds進行配置。

您當前的行為可能是因為服務負載平衡器已經看到Pod中的所有容器都已啟動。 您可以定義准備情況檢查,例如下面的示例(從文檔中挑選)。

kind: Pod
metadata:
  name: goproxy
  labels:
    app: goproxy
spec:
  containers:
  - name: goproxy
    image: k8s.gcr.io/goproxy:0.1
    ports:
    - containerPort: 8080
    readinessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 5
      periodSeconds: 10
    livenessProbe:
      tcpSocket:
        port: 8080
      initialDelaySeconds: 15
      periodSeconds: 20 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM