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