<p>I have a deployment.yaml which has a readiness probe on the container. (The readiness probe is intended to fail here)</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    app: nginx
  name: my-nginx-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        app: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        readinessProbe:
         exec:
          command:
            - cat
            - /server/xyz.txt
         initialDelaySeconds: 50
         periodSeconds: 10
        resources: {}
status: {}
</code></pre>
<p>The pods in the deployment are served using a service of type ClusterIP.</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  creationTimestamp: null
  labels:
    app: nginx-service
  name: nginx-service
spec:
  ports:
  - port: 8080
    protocol: TCP
    targetPort: 80
  selector:
    app: nginx
  type: ClusterIP
status:
  loadBalancer: {}
</code></pre>
<p>after applying these yamls using <code>kubectl apply</code>, container in the pods is never ready as the readiness probe is failing, which is expected.</p>
<pre><code>NAME                                     READY   STATUS    RESTARTS   AGE
my-nginx-deployment-6b788b89c6-f69j7   0/1     Running   0          9m50s
my-nginx-deployment-6b788b89c6-m5qf6   0/1     Running   0          9m50s
</code></pre>
<p>So since these pods are not ready, they should not serve the traffic but when I do</p>
<pre><code>kubectl port-forward services/nginx-service 8086:8080
</code></pre>
<p>I am able to get 200 response and nginx home page on <code>http://127.0.0.1:8086/</code> and I can also see  pods logs about serving traffic.</p>
<p>question is, why pods are serving traffic when readiness probe is failing.</p>
<p>PS: I have created cluster on my machine using Kind</p>

<p>The <code>port-forward</code> <a href="https://v1-17.docs.kubernetes.io/docs/reference/generated/kubernetes-api/v1.17/#create-connect-portforward-pod-v1-core" rel="nofollow noreferrer">api</a> is for a Pod. The <code>kubectl port-forward</code> command just use <em>service</em> to make it easy to use, but your port are actually forwarded to a Pod - so the <em>readiness</em> status is not applicable.</p>
