KB:Kubernetes Endpoints
In Kubernetes, an endpoint refers to the set of network addresses (IP addresses and ports) that are associated with a Kubernetes service. Endpoints are used to keep track of the Pods that are dynamically assigned to a service. Here's a more detailed breakdown of what endpoints are and how they work:
Key Concepts:
Services:
- A Kubernetes Service is an abstraction that defines a logical set of Pods and a policy by which to access them. Services enable network access to a group of Pods in a Kubernetes cluster.
- Services can be exposed internally within the cluster (ClusterIP), externally to the internet (LoadBalancer or NodePort), or can be headless (without a stable IP address).
Pods:
- Pods are the smallest and simplest Kubernetes objects. A Pod represents a single instance of a running process in your cluster.
- Pods are ephemeral, meaning they can be created and destroyed dynamically.
Endpoints:
- Endpoints in Kubernetes are the objects that associate a service with the actual Pod IP addresses and ports.
- When a service is created, an endpoint object is also created and updated dynamically as Pods are created, destroyed, or moved.
How Endpoints Work:
- When a service is defined, Kubernetes automatically creates an associated endpoint object.
- The endpoint object lists all the IP addresses and ports of the Pods that are part of the service.
- Whenever a Pod is added or removed from the service, the endpoint object is updated accordingly.
- This allows the service to dynamically keep track of the current set of Pods it should route traffic to.
Types of Endpoints:
Regular Endpoints:
- These are the standard endpoints created for each service, mapping the service to the IP addresses and ports of the associated Pods.
Headless Services:
- When a service is created without a cluster IP (by setting the
clusterIPfield to "None"), it is known as a headless service. - For headless services, Kubernetes does not create a standard endpoint object. Instead, DNS entries are created for each Pod, allowing direct access to the Pods.
Endpoints in Kubernetes are not directly exposed externally. Instead, they are used internally within the Kubernetes cluster to keep track of the IP addresses and ports of the Pods that are associated with a service. Here's a deeper look at how endpoints interact with external exposure:
Internal vs. External Exposure
Internal Exposure:
- Endpoints are primarily used for internal service discovery. Kubernetes services use these endpoints to route traffic to the appropriate Pods within the cluster.
- The endpoints object itself is not accessible from outside the cluster; it is managed by the Kubernetes control plane to maintain the mapping between services and Pods.
External Exposure:
- To expose services externally, Kubernetes provides different types of services:
- NodePort: Exposes the service on each Node’s IP at a static port. This makes the service accessible externally through
<NodeIP>:<NodePort>. - LoadBalancer: Creates an external load balancer (if supported by the underlying infrastructure) and assigns a public IP to the service.
- Ingress: Manages external access to services, typically HTTP and HTTPS, providing features like load balancing, SSL termination, and name-based virtual hosting.
Summary:
- Endpoints in Kubernetes are not directly exposed externally.
- They are used internally to manage the mapping between services and Pods.
- To expose services externally, Kubernetes provides mechanisms like NodePort, LoadBalancer, and Ingress, which handle the external routing while relying on the internal endpoint objects to distribute traffic to the Pods.
- Endpoints are updated whenever the set of Pods associated with a service changes, not specifically when the service is exposed.
- The service’s exposure method (ClusterIP, NodePort, LoadBalancer, Ingress) determines how the traffic reaches the service but does not directly trigger endpoint updates.
- Endpoint updates are driven by changes in the Pods (creation, deletion, rescheduling) that match the service's selector.
Comments
Post a Comment