<p>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?</p>

Brian Shih
<p>You can use readiness probe and <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">kubernetes service</a>. From the docs <a href="https://kubernetes.io/docs/concepts/workloads/pods/pod-lifecycle/" rel="nofollow noreferrer">here</a></p>
<blockquote>
<p><strong>readinessProbe</strong>: 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</p>
</blockquote>
<p>From the guide <a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/" rel="nofollow noreferrer">here</a></p>
<pre><code>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
</code></pre>
<p>Your application need to have HTTP endpoint <code>/readiness</code> which should return <code>200 OK</code> response.Kubelet will probe the endpoint that you define in the readiness probe. Once kubelet get a <code>200 OK</code> 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.</p>
<p>Finally expose the pod via Kubernetes Service.</p>
