Kubernetes Service not reaching Pods: selector doesn’t match labels
If a Service times out or kubectl get endpoints shows none, the most common cause is that its selector doesn’t match the labels on your Pods. Kubernetes reports no error, because a Service with zero matching Pods is valid.
In this manifest the Service selects app=web while the Pods are labelled app=web-frontend. The traffic check marks the broken hop. Change either value in the editor so they agree and the link turns green. Paste your own manifest to check it the same way.
Will traffic reach the Pods?
Service web:80does not reachDeployment web-frontend. The selector doesn't match Deployment "web-frontend": the Service wants app=web, the Pods have app=web-frontend. The Service has no Pods to send traffic to. Fix: Make the Service's spec.selector and the Pod template's labels identical.
What this manifest does
This manifest defines 2 resources in the default namespace: the main thing it runs is 1 Deployment. Let’s walk through it.
Deployment web-frontend runs 2 Pods, running myorg/web-frontend:1.4.2.
Things to know before using it
No Pod in this manifest matches this Service’s selectorService web
This Service selects pods with
app=web, but no workload in this manifest has matching pod labels. That’s fine if the matching Deployment lives in another file — but if you expected to see them connected here, double-check the labels. Fix: Confirm a Deployment / StatefulSet exists withspec.template.metadata.labelsmatching every key in the Service’sspec.selector.No topology spread or anti-affinityDeployment web-frontend
Deployment "web-frontend" has 2 replicas but no spread rules. All Pods could land on one node, a single failure domain. Fix: Add topologySpreadConstraints or podAntiAffinity to spread across zones/nodes.
The full manifest
# The Service looks for app=web. The Pods are labelled app=web-frontend.
apiVersion: v1
kind: Service
metadata:
name: web
spec:
selector:
app: web
ports:
- port: 80
targetPort: 3000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: web-frontend
spec:
replicas: 2
selector:
matchLabels:
app: web-frontend
template:
metadata:
labels:
app: web-frontend
spec:
containers:
- name: web-frontend
image: myorg/web-frontend:1.4.2
ports:
- containerPort: 3000
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 256Mi
securityContext:
runAsNonRoot: true
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
readinessProbe:
httpGet:
path: /ready
port: 3000
livenessProbe:
httpGet:
path: /healthz
port: 3000
Stuck on a Kubernetes concept?
Ask anything and get a narrated visual lesson, pitched at your level. Free.
Try an example