0
0
KubernetesConceptBeginner · 3 min read

What Are Endpoints in Kubernetes Service Explained

In Kubernetes, endpoints are objects that list the IP addresses and ports of the pods matched by a Service. They act like a directory that connects the service to the actual pods, enabling network traffic routing.
⚙️

How It Works

Think of a Kubernetes Service as a receptionist who answers calls but doesn't do the work themselves. The endpoints are like a phone book that tells the receptionist which workers (pods) to connect the calls to. When a service receives a request, it looks up its endpoints to find the pods that can handle the request.

Under the hood, Kubernetes automatically creates and updates Endpoints objects to keep track of the pods that match the service's selector. This way, the service always knows where to send traffic, even if pods are added, removed, or restarted.

💻

Example

This example shows a service and its endpoints listing the pods it routes to.

yaml
apiVersion: v1
kind: Service
metadata:
  name: my-service
spec:
  selector:
    app: my-app
  ports:
  - protocol: TCP
    port: 80
    targetPort: 8080
---
apiVersion: v1
kind: Endpoints
metadata:
  name: my-service
subsets:
- addresses:
  - ip: 10.1.1.5
  - ip: 10.1.1.6
  ports:
  - port: 8080
Output
kubectl get endpoints my-service NAME ENDPOINTS AGE my-service 10.1.1.5:8080,10.1.1.6:8080 5m
🎯

When to Use

You use endpoints automatically when you create a Kubernetes Service. They are essential for routing traffic to the right pods. If you want to manually specify which IPs a service should send traffic to, you can create or edit Endpoints objects directly.

Real-world use cases include:

  • Connecting a service to pods that match a label selector.
  • Manually defining endpoints for external services outside the cluster.
  • Debugging network issues by inspecting which pods a service routes to.

Key Points

  • Endpoints link services to pods by listing their IPs and ports.
  • Kubernetes manages endpoints automatically for services with selectors.
  • Manual endpoints can be used for external or special cases.
  • Endpoints ensure traffic reaches the correct pods behind a service.

Key Takeaways

Endpoints are the IP addresses and ports of pods a Kubernetes service routes to.
Kubernetes automatically updates endpoints to match pods selected by the service.
You can manually create endpoints to connect services to external resources.
Endpoints are crucial for directing network traffic inside a Kubernetes cluster.