Endpoints & EndpointSlice
Endpoints and EndpointSlice are Kubernetes resources that track which pod IP addresses a Service should route traffic to. When you create a Service with a selector, Kubernetes automatically creates Endpoints (or EndpointSlice) resources that list the IP addresses of all pods matching the selector. Understanding these resources helps you debug Service routing and understand how Services find and connect to pods.
What are Endpoints?
An Endpoints resource is automatically created for each Service with a selector. It contains a list of IP addresses and ports for all pods that match the Service’s selector. The Service uses this list to know where to route traffic.
How Endpoints Work
When you create a Service:
- Service defines selector - Labels that identify target pods
- Kubernetes watches pods - Continuously monitors pods in the cluster
- Matches pods to selector - Finds all pods with matching labels
- Creates/updates Endpoints - Lists pod IPs and ports
- Service uses Endpoints - Routes traffic to IPs listed in Endpoints
Viewing Endpoints
You can view Endpoints for a Service:
kubectl get endpoints <service-name>
Example output:
NAME ENDPOINTS AGE
web-service 10.244.1.5:8080,10.244.1.6:8080,10.244.2.3:8080 5m
The Endpoints resource shows:
- IP addresses of pods matching the selector
- Ports that pods are listening on
- Subsets grouping endpoints by port and readiness
Endpoints Resource Structure
Here’s what an Endpoints resource looks like:
apiVersion: v1
kind: Endpoints
metadata:
name: web-service # Same name as Service
namespace: default
subsets:
- addresses:
- ip: 10.244.1.5
nodeName: node-1
targetRef:
kind: Pod
name: web-pod-1
namespace: default
- ip: 10.244.1.6
nodeName: node-1
targetRef:
kind: Pod
name: web-pod-2
namespace: default
- ip: 10.244.2.3
nodeName: node-2
targetRef:
kind: Pod
name: web-pod-3
namespace: default
ports:
- port: 8080
protocol: TCP
Key fields:
addresses- List of pod IPs that are readynotReadyAddresses- Pod IPs that aren’t ready (if any)ports- Ports that pods are listening ontargetRef- Reference to the pod object
Readiness and Endpoints
Endpoints only include pods that are ready. Pods that fail readiness probes are excluded:
Ready pods → Included in addresses
Not ready pods → Included in notReadyAddresses (if Service has publishNotReadyAddresses: true)
EndpointSlice (Modern Approach)
EndpointSlice is the newer, more scalable alternative to Endpoints. It was introduced to address limitations of the Endpoints resource:
- Scalability - Endpoints can become large with many pods
- Performance - EndpointSlice is more efficient for large Services
- Network topology - Supports zone/region awareness
EndpointSlice Structure
EndpointSlice resources are automatically created (if the feature is enabled):
apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
name: web-service-abc123 # Generated name
namespace: default
labels:
kubernetes.io/service-name: web-service
addressType: IPv4
endpoints:
- addresses:
- "10.244.1.5"
conditions:
ready: true
targetRef:
kind: Pod
name: web-pod-1
namespace: default
zone: us-west-1a
- addresses:
- "10.244.1.6"
conditions:
ready: true
targetRef:
kind: Pod
name: web-pod-2
namespace: default
zone: us-west-1b
ports:
- name: http
port: 8080
protocol: TCP
Key differences from Endpoints:
- Multiple EndpointSlice resources per Service (split by size)
- Zone/region information for topology-aware routing
- More efficient for large Services
- Generated names (not same as Service name)
Viewing EndpointSlice
# List EndpointSlices for a Service
kubectl get endpointslice -l kubernetes.io/service-name=web-service
# Describe an EndpointSlice
kubectl describe endpointslice <endpointslice-name>
Endpoints vs EndpointSlice
Endpoints:
- Single resource per Service
- All pod IPs in one list
- Legacy, but still widely used
- Can become large with many pods
EndpointSlice:
- Multiple resources per Service
- Pods split across slices (max 100 per slice)
- Modern, scalable approach
- Better for Services with many pods
- Supports topology awareness
Service Without Selector
You can create a Service without a selector and manually manage Endpoints:
apiVersion: v1
kind: Service
metadata:
name: external-service
spec:
ports:
- port: 80
targetPort: 8080
---
apiVersion: v1
kind: Endpoints
metadata:
name: external-service # Must match Service name
subsets:
- addresses:
- ip: 192.168.1.100 # External IP
ports:
- port: 8080
This allows Services to route to external endpoints (databases, APIs, etc.) outside the cluster.
Debugging with Endpoints
Endpoints are invaluable for debugging Service issues:
Service Not Routing Traffic
# Check if Endpoints exist
kubectl get endpoints <service-name>
# If empty, Service has no pods to route to
# Check pod selector
kubectl get pods -l app=web
# Verify pods are ready
kubectl get pods -l app=web
Pods Not in Endpoints
- Check selector matches:
kubectl get pods -l app=web - Verify pod labels:
kubectl get pods --show-labels - Check pod readiness:
kubectl get pods -l app=web - Review Endpoints:
kubectl describe endpoints <service-name>
Endpoints Empty
If Endpoints are empty, possible causes:
- No pods match the selector
- Pods exist but aren’t ready
- Pods are in different namespace
- Selector labels don’t match pod labels
Monitoring Endpoints
You can monitor Endpoints to track Service health:
# Watch Endpoints changes
kubectl get endpoints <service-name> -w
# Count endpoints
kubectl get endpoints <service-name> -o jsonpath='{.subsets[0].addresses[*].ip}' | wc -w
# List all endpoint IPs
kubectl get endpoints <service-name> -o jsonpath='{.subsets[0].addresses[*].ip}'
Best Practices
- Monitor Endpoints - Regularly check that Services have expected Endpoints
- Use readiness probes - Ensure pods report readiness correctly
- Verify selectors - Double-check Service selectors match pod labels
- Check EndpointSlice - If using EndpointSlice, monitor multiple resources
- Debug with Endpoints - Use Endpoints to troubleshoot Service routing issues
- Understand readiness - Know that only ready pods are included
- Monitor changes - Watch for Endpoints changes during deployments
- Use external Endpoints - Leverage manual Endpoints for external services
Troubleshooting
Endpoints Empty
- Check pod selector:
kubectl get pods -l app=my-app - Verify labels match:
kubectl get pods --show-labels - Check pod readiness:
kubectl get pods -l app=my-app - Verify namespace: Ensure Service and pods are in same namespace
- Check Endpoints resource:
kubectl get endpoints <service-name> -o yaml
Endpoints Not Updating
- Check controller: Verify endpoints controller is running
- Check pod status: Ensure pods are actually ready
- Verify selector: Double-check Service selector
- Check events:
kubectl get events --field-selector involvedObject.name=<service-name>
Wrong Pods in Endpoints
- Review selector:
kubectl get service <service-name> -o yaml | grep selector - Check pod labels:
kubectl get pods --show-labels - Verify namespace: Ensure correct namespace
- Check for label conflicts: Multiple pods with same labels in different namespaces
EndpointSlice Not Created
- Check feature gate: Verify EndpointSlice feature is enabled
- Check Kubernetes version: EndpointSlice requires Kubernetes 1.17+
- Verify API enabled: Ensure discovery.k8s.io/v1 API is available
- Check controller: Verify endpoints controller is running
See Also
- Services Overview - Introduction to Kubernetes Services
- ClusterIP - How Services route traffic
- Headless Services - Services without ClusterIP
- Deployments - Managing pod replicas
- StatefulSets - Stateful workloads with stable identities