简体   繁体   English

Kubernetes pod - 何时准备好服务流量?

[英]Kubernetes pod - when it's ready to serve traffic?

I am currently building a distributed consensus system such that it is important to know exactly when a Kubernetes pod can serve traffic (accept http requests).我目前正在构建一个分布式共识系统,因此准确了解 Kubernetes pod 何时可以提供流量非常重要(接受 http 请求)。 Any ideas as to how I can do that apart from setting a timer to keep making requests to itself?除了设置计时器以继续向自身发出请求之外,关于我如何做到这一点的任何想法?

You can use readiness probe and kubernetes service .您可以使用就绪探针和kubernetes 服务 From the docs here这里的文档

readinessProbe : Indicates whether the Container is ready to service requests. readinessProbe :指示容器是否准备好为请求提供服务。 If the readiness probe fails, the endpoints controller removes the Pod's IP address from the endpoints of all Services that match the Pod.如果就绪探测失败,端点 controller 从与 Pod 匹配的所有服务的端点中删除 Pod 的 IP 地址。 The default state of readiness before the initial delay is Failure.初始延迟前准备就绪的默认 state 是失败。 If a Container does not provide a readiness probe, the default state is Success如果 Container 不提供就绪探测,则默认 state 为 Success

From the guide here这里的指南

apiVersion: v1
kind: Pod
metadata:
  name: goproxy
  labels:
    app: goproxy
spec:
  containers:
  - name: goproxy
    image: k8s.gcr.io/goproxy:0.1
    ports:
    - containerPort: 8080
    readinessProbe:
      httpGet:
        path: /readiness
        port: 8888
      initialDelaySeconds: 300
      periodSeconds: 30

Your application need to have HTTP endpoint /readiness which should return 200 OK response.Kubelet will probe the endpoint that you define in the readiness probe.您的应用程序需要有 HTTP 端点/readiness应该返回200 OK响应。Kubelet 将探测您在就绪探针中定义的端点。 Once kubelet get a 200 OK response back from the endpoint then pod will be marked ready to accept traffic and Kubernetes service will start sending traffic to the backend pod.一旦 kubelet 从端点收到200 OK响应,则 Pod 将被标记为准备接受流量,并且 Kubernetes 服务将开始向后端 Pod 发送流量。

Finally expose the pod via Kubernetes Service.最后通过 Kubernetes 服务暴露 pod。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM