0
0
KubernetesDebug / FixBeginner · 4 min read

How to Fix Service Not Accessible in Kubernetes Quickly

If a Kubernetes Service is not accessible, first check if the Service and its Pods are correctly running and matched by labels. Also verify the Service type and port settings, and ensure network policies or firewall rules are not blocking access.
🔍

Why This Happens

This problem usually happens because the Service selector does not match any Pods, the Service type is incorrect for your access method, or network rules block traffic. For example, if the Service selector labels do not match the Pods labels, the service has no endpoints to route traffic to.

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: wrong-label
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
Output
kubectl get endpoints my-service NAME ENDPOINTS AGE my-service <none> 5m
🔧

The Fix

Update the Service selector to match the correct labels on the Pods. Also, confirm the Service type fits your use case (e.g., ClusterIP for internal access, NodePort or LoadBalancer for external). Check ports match between Service and Pods. Finally, verify no network policies or firewalls block traffic.

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
  type: ClusterIP
Output
kubectl get endpoints my-service NAME ENDPOINTS AGE my-service 10.244.1.5:8080 1m
🛡️

Prevention

Always keep Service selectors and Pod labels in sync. Use kubectl describe service and kubectl get endpoints to verify connectivity. Apply network policies carefully and test access after changes. Use readiness probes on Pods to ensure they only receive traffic when ready.

⚠️

Related Errors

  • Pods not ready: Service has no endpoints because pods are failing readiness checks.
  • Wrong port: Service port does not match pod container port.
  • NetworkPolicy blocks traffic: Network rules prevent access to service.

Key Takeaways

Ensure Service selectors exactly match Pod labels to create endpoints.
Verify Service type and ports match your access needs and Pod ports.
Check network policies and firewalls do not block Service traffic.
Use readiness probes to avoid routing traffic to unready Pods.
Regularly inspect Service and Endpoint status with kubectl commands.