0
0
Kubernetesdevops~5 mins

Endpoints and endpoint slices in Kubernetes - Commands & Configuration

Choose your learning style9 modes available
Introduction
When you run applications in Kubernetes, you often need to connect services to the right pods. Endpoints and endpoint slices help Kubernetes keep track of which pods belong to a service, so traffic goes to the right places.
When you want to see which pods are connected to a service in your cluster.
When you need to debug why a service is not routing traffic correctly.
When you want to understand how Kubernetes manages network connections between services and pods.
When you want to optimize network performance by using endpoint slices for large services.
When you want to monitor or troubleshoot service discovery in your Kubernetes cluster.
Commands
This command lists all the endpoints in the current namespace. Endpoints show which pods are linked to each service.
Terminal
kubectl get endpoints
Expected OutputExpected
NAME ENDPOINTS AGE kubernetes 10.96.0.1:443 10d
This command lists all endpoint slices in the current namespace. Endpoint slices are a newer, scalable way to track service endpoints.
Terminal
kubectl get endpointslices
Expected OutputExpected
NAME ADDRESSTYPE PORTS ENDPOINTS AGE kubernetes-abc123 IPv4 443 10.96.0.1 10d
This command shows detailed information about the endpoints for the 'kubernetes' service, including the IP addresses and ports of pods.
Terminal
kubectl describe endpoints kubernetes
Expected OutputExpected
Name: kubernetes Namespace: default Endpoints: 10.96.0.1:443 Age: 10d
This command shows detailed information about a specific endpoint slice, including addresses and ports it covers.
Terminal
kubectl describe endpointslice kubernetes-abc123
Expected OutputExpected
Name: kubernetes-abc123 Namespace: default AddressType: IPv4 Ports: Name: https Port: 443 Endpoints: 10.96.0.1 Age: 10d
Key Concept

Endpoints and endpoint slices map services to the pods that serve them, enabling Kubernetes to route traffic correctly.

Common Mistakes
Trying to edit endpoints directly to change service pods.
Endpoints are managed automatically by Kubernetes and manual edits will be overwritten.
Change the service selector or pod labels to update which pods belong to a service.
Ignoring endpoint slices and only using endpoints for large services.
Endpoints can become inefficient and slow with many pods; endpoint slices scale better.
Use endpoint slices for services with many pods to improve performance.
Summary
Use 'kubectl get endpoints' to see which pods are linked to services.
Use 'kubectl get endpointslices' to view scalable endpoint information.
Describe endpoints or endpoint slices to get detailed pod IPs and ports.