Service
Each pod in the Kubernetes cluster is assigned an internal IP address. Since pods are created and deleted and their IP addresses change, it doesn't make sense to use IP addresses for pods directly. Use service to get permanent access to the pods and abandon internal IP addresses.
A service is a Kubernetes API object (Service)
If you use a service, you get a permanent IP address that exists throughout the service lifecycle, even if pods change their IP addresses. It also provides load balancing. Clients send requests to a single IP address, and their requests are balanced between the pods belonging to the service.
The set of pods belonging to the service is defined by a selector. The selector is configured by the user when creating the pod and allows filtering the list of resources based on labels (key-value pairs assigned to the resource). The pod belongs to the service if it has all the Kubernetes labels specified in the selector.
Depending on your task, you can use different types of services.
Service types
You can use various types of services in your Kubernetes clusters, including:
ClusterIP
- The service is accessible only within the Kubernetes cluster network via an internal IP address.
- It doesn't require any additional cloud resources.
NodePort
is aClusterIP
extensions.- It provides access to the service via internal or public Kubernetes cluster node IP addresses.
- It doesn't require any additional cloud resources.
LoadBalancer
is aNodePort
extension.- It provides access to the service through the created cloud network load balancer.
- It requires an additional cloud resource (network load balancer).
To publish your app, use a LoadBalancer
service based on a network load balancer with a public or internal IP address.
If you need DDoS protection, reserve a static IP address with protection enabled and specify it using the loadBalancerIP
option.
Read more about types of services in the Kubernetes documentation