Kubernetes 101 : ClusterIP, NodePort and LoadBlancer services
There are in kubernetes different types of services that perform different functions.
Service are reached through their names.
Service are reached through their names.
The DNS service in the kubernetes cluster maps the names of the services to an IP address.
The ClusterIP service:
The ClusterIP service is an internal service only reachable from within the cluster.
Since the IP address of the pods changes when they crash for example and get re-deployed, services act as a static "entry point" to pods .
- Selector: it is how the service "latches on" to the pods which label matches it's selector.
- Ports: port 80 on the service maps to port 8080 on the pod.
- Ports: port 80 on the service maps to port 8080 on the pod.
Below is a Yaml file of a ClusterIP service:
To display the clusterIP service, we use the below command:
We can omit the "type: ClusterIP" because it is the default type and kubernetes will create a ClusterIP service if we don't mention the "type" part.
Displaying the IP address of pods:
Displaying the IP address of pods:
To display the IP addresses assigned to the pods, we use the below command:
The nodePort service:
The nodePort service is a kubernetes object that exposes an internal service to the "outside world" through ports on the host ranging from (30000 to 332767).
The port is open on all the worker nodes of the cluster.
Any of the workers could receive the request and redirect it to the right service and ultimately to the application running inside the pod.
When we create a nodePort service, a corresponding ClusterIP service will be created.
The ClusterIP service will handle the requests which are forwarded to it from the nodePort service.
Below is the Yaml file of the nodePort service:
- port: port 80 is the port of the ClusterIP service that is created automatically when we create a nodePort service.
- targetPort: is the port of the application running inside the pod.
- nodePort: is the port open on the host.
To display the services, we use the below command:
The loadBalancer opens the cluster to external requests through its external IP address.
Below is the Yaml file of a loadBalancer service:
The loadBalancer service will open a port in the range of (30000 - 332767) on the external IP address.
The loadBalancer could be used as below for example:
- Port "8080": the internal port.
- Port "30200": the external port opened by the loadBalancer.
- Port "30200": the external port opened by the loadBalancer.
Comments