Member-only story
K8s Troubleshooting — Target Pod Selector Misconfig
Note, full K8s troubleshooting mind map is available at: “K8s Troubleshooting MindMap”
In K8s, a Service routes traffic to Pods based on a label selector. If there’s a misconfiguration with the selector, the Service will not be able to route traffic correctly.
For example, consider the following Service:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 9376
This Service is configured to route traffic to Pods with the label app: my-app
.
Now, let’s say you have a Deployment that creates Pods like this:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-deployment
spec:
replicas: 3
selector:
matchLabels:
app: my-app
template:
metadata:
labels:
app: my-app-wrong # Misconfigured label
spec:
containers:
- name: my-app
image: my-app:1.0
ports:
- containerPort: 9376
In the above Deployment, the Pods are created with the label app: my-app-wrong
instead of app: my-app
. Because the labels of the Pods don't match the selector of the Service, the Service won't…