1

I have a deployment.yaml which has a readiness probe on the container. (The readiness probe is intended to fail here)

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: {}

The pods in the deployment are served using a service of type ClusterIP.

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: {}

after applying these yamls using kubectl apply, container in the pods is never ready as the readiness probe is failing, which is expected.

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

So since these pods are not ready, they should not serve the traffic but when I do

kubectl port-forward services/nginx-service 8086:8080

I am able to get 200 response and nginx home page on http://127.0.0.1:8086/ and I can also see pods logs about serving traffic.

question is, why pods are serving traffic when readiness probe is failing.

PS: I have created cluster on my machine using Kind

saurabh_garg
  • 86
  • 1
  • 7
  • How is this question related to programming? It might be better suited for [DevOps](https://devops.stackexchange.com/) or [SF]. – Turing85 May 14 '21 at 14:54
  • Does this answer your question? [Does kubectl port-forward ignore loadBalance services?](https://stackoverflow.com/questions/59940833/does-kubectl-port-forward-ignore-loadbalance-services) – Jonas May 14 '21 at 15:40

1 Answers1

1

The port-forward api is for a Pod. The kubectl port-forward command just use service to make it easy to use, but your port are actually forwarded to a Pod - so the readiness status is not applicable.

Jonas
  • 121,568
  • 97
  • 310
  • 388