Use it to choose how a workload is exposed, or when a Service is unreachable.
Service Types
Service types: ClusterIP (internal), NodePort (port on every node), LoadBalancer (cloud/MetalLB load balancer), ExternalName (DNS alias); headless Services return pod IPs.
1. kubectl get svc <s> -o wide — type, ports, external IP.
2. Endpoints present?
3. targetPort = container port?
4. LoadBalancer Pending → controller/MetalLB.
5. Test from inside and outside.
client → Service (ClusterIP/NodePort/LB) → endpoints
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Confirm endpoints exist, then test the Service from a Pod, then from outside for NodePort or LoadBalancer. A pending EXTERNAL-IP means no load balancer controller is handling the Service.
Step 2 Common failures Narrow the fault
A selector that does not match Pod labels gives a Service with no endpoints. targetPort must match the container port, not the Service port. LoadBalancer stays pending on bare metal without MetalLB or similar.
Endpoints must exist; targetPort must match the container port. LoadBalancer Pending → no load balancer provider.
kubectl get svc <s> -o wide— first check for this topickubectl get pods -o wide— pods, status, node, IPkubectl describe pod <pod>— events and conditionskubectl logs <pod> [-c <c>] [--previous]— container logs (incl. previous crash)kubectl get events --sort-by=.lastTimestamp— recent cluster events
ReferenceWhat it is1 section · depth on demand
How it works
The control plane assigns a cluster IP and keeps EndpointSlices of ready Pods that match the selector. kube-proxy (iptables or IPVS) or an eBPF data plane programs nodes to forward the virtual IP to those endpoints.
ReferenceImportant terms & boundaries3 sections · depth on demand
Service types
| Type | Reachable from | Use |
|---|---|---|
| ClusterIP | Inside cluster | Default internal services |
| NodePort | Node IP:30000–32767 | Simple external access, testing |
| LoadBalancer | Cloud/MetalLB external IP | Production external services |
| ExternalName | DNS CNAME | Alias to external names |
Headless (clusterIP: None) | DNS per Pod | StatefulSets |
kubectl get endpointslices -l kubernetes.io/service-name=web — no endpoints means the selector does not match Ready Pods.
In depth
A Service gives a stable virtual IP and DNS name to a changing set of Pods. The control plane keeps EndpointSlices listing the Pod IPs that match the selector and are Ready; kube-proxy (iptables, IPVS or nftables mode) or an eBPF data plane translates the Service IP to one of them.
Ports in one Service
ports:
- port: 80 # what clients connect to on the Service IP
targetPort: 8080 # container port (number or named port)
nodePort: 30080 # only for NodePort/LoadBalancer
Traffic policies
| Setting | Effect |
|---|---|
externalTrafficPolicy: Cluster (default) | Any node forwards to any Pod; client IP is SNATed |
externalTrafficPolicy: Local | Only nodes with a local Pod accept traffic; client IP preserved |
internalTrafficPolicy: Local | In-cluster traffic stays on the node (node-local agents) |
sessionAffinity: ClientIP | Same client → same Pod (timeout 3 h by default) |
Worked check — Service not answering
kubectl get svc web -o wide # selector and ports
kubectl get endpointslices -l kubernetes.io/service-name=web
# ENDPOINTS empty → selector mismatch or no Ready Pods
kubectl get pods -l app=web --show-labels
kubectl run t --rm -it --image=busybox:1.36 --restart=Never -- wget -qO- http://web:80
Empty endpoints with running Pods almost always means the selector labels differ, or readiness probes are failing. Endpoints present but no answer means targetPort points at the wrong container port.
Common mistakes
- NodePort services exposed unintentionally.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.