<p>I have a Kubernetes deployment on GCP and a ClusterIP service to discover pods in this deployment. The deployment contains multiple replica set pods which come and go based on our horizontal pod scalar configuration (based on CPU Utilization). </p>

<p>Now, when a new replica set pod is created, it takes some time for the application to start servicing. But the ClusterIP already starts distributing requests to new replica set pod before the application is ready, which causes the requests to be not serviced.</p>

<p>ClusterIP service yaml:</p>

<pre><code>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
</code></pre>

<p>How can the ClusterIP be told to start distributing requests to the new pod after the application starts? Can there be any initial delay or liveness probe set for this purpose?</p>

user5155835
<p>Kubernetes provides readiness probe for it. With readiness probes, Kubernetes will not send traffic to a pod until the probe is successful. When updating a deployment, it will also leave old replica(s) running until probes have been successful on new replica. That means that if your new pods are broken in some way, they’ll never see traffic, your old pods will continue to serve all traffic for the deployment.</p>

<p>You need to update the deployment file with following readiness probe:</p>

<pre><code>readinessProbe:
  exec:
    command:
    - cat
    - /tmp/healthy
  initialDelaySeconds: 5
  periodSeconds: 5
</code></pre>

<p>If your application have http probe then you can set readiness probe in HTTP mode as well.</p>

<p>For more information how can you use readiness probe refer:</p>

<p><a href="https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-readiness-probes" rel="nofollow noreferrer">https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-probes/#define-readiness-probes</a></p>
