AKS kubernetes - services type and use cases :)

NHAILA Achraf
3 min readMar 24, 2023

--

Kubernetes provides a wide range of services that are designed to help developers and operations teams manage containerized applications in a distributed environment. Here are the 3 types of services provided by Kubernetes along with their use cases:

1-NodePort: A NodePort service exposes a containerized application on a static port on each worker node in the cluster. This allows external traffic to access the application via any node’s IP address and the static port number. This service is typically used for development or testing purposes when the application needs to be accessed from outside the cluster.

Use case: Suppose you have a web application running on multiple containers in a Kubernetes cluster. You want to expose this application to external traffic so that users can access it from outside the cluster. You can create a NodePort service that exposes the web application on a static port on each worker node in the cluster. Users can then access the application using any node’s IP address and the static port number.

Example of nodePort service :

apiVersion: v1
kind: Service
metadata:
name: my-app
spec:
type: NodePort
selector:
app: my-app
ports:
- name: http
port: 80
targetPort: 8080

This service exposes the web application on port 80 of each worker node in the cluster.
External traffic can access the application using any worker node's IP address and the static port number.

2-ClusterIP: A ClusterIP service exposes a containerized application on an internal IP address that is only accessible within the cluster. This service is used to provide internal communication between different services in the cluster.

Use case: Suppose you have a microservices architecture where each service is running in a separate container. You want to allow these services to communicate with each other over the internal network of the cluster. You can create a ClusterIP service for each service that exposes it on an internal IP address that is only accessible within the cluster. Other services in the cluster can then communicate with this service using the internal IP address.

Example of ClusterIP service :

apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
type: ClusterIP
selector:
app: my-service
ports:
- name: http
port: 80
targetPort: 8080

This service exposes the my-service application on an internal IP address that is only accessible within the cluster.
Other services in the cluster can communicate with my-service using this internal IP address.

3-LoadBalancer: A LoadBalancer service exposes a containerized application on a publicly accessible IP address that is managed by a cloud provider’s load balancer service. This service is used to provide external access to the application and distribute traffic across multiple instances of the application.

Use case: Suppose you have a containerized web application that needs to be accessible from the public internet. You can create a LoadBalancer service that exposes the application on a publicly accessible IP address that is managed by a cloud provider’s load balancer service. The load balancer distributes traffic across multiple instances of the application, ensuring that the application remains highly available and can handle large amounts of traffic.

Example of LoadBalancer service :

apiVersion: v1
kind: Service
metadata:
name: my-webapp
spec:
type: LoadBalancer
selector:
app: my-webapp
ports:
- name: http
port: 80
targetPort: 8080

This service exposes the my-webapp application on a publicly accessible IP address that is managed by a cloud provider's load balancer service.
The load balancer distributes traffic across multiple instances of the application, ensuring that the application remains highly available and can handle large amounts of traffic.
list of services type (clusterIP & loadBalancer…)

Hope this will help!
NHAILA Achraf

--

--