简体   繁体   中英

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). 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 . From the docs here

readinessProbe : Indicates whether the Container is ready to service requests. If the readiness probe fails, the endpoints controller removes the Pod's IP address from the endpoints of all Services that match the Pod. The default state of readiness before the initial delay is Failure. If a Container does not provide a readiness probe, the default state is 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. 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.

Finally expose the pod via Kubernetes Service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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