Services: ClusterIP in Kubernetes

In the full-stack web application, you may have a number of pods running a front-end, back-end, and database. The front-end pods need to communicate with the back-end pods, the back-end pods need to communicate to the database. So, what is the right way to establish connectivity between these services? The pods all have an IP address, but these IP addresses are not static. These pods can go down anytime and new pods are created all the time. Thus, you can not rely on these IP addresses for internal communication between the application. Also, what if the front-end pods need to connect to a back-end service which of the pods would it go to, and who makes that decision?

Communication between pods with Service

Kubernetes ClusterIP service can help us group the pod together and provide a single interface to access the pods in a group. For example, a service created for the back-end pod will help group all the back-end pods together and provide a single interface for other pods to access to service. The requests are forwarded to one of the pods under the service randomly. This enables us to easily and effectively deploy a microservices-based application on Kubernetes Cluster. Each layer can now scale or move as required without impacting communication between the various services. Each service gets an IP name assigned to it inside the cluster, and that is the name that should be used by other pods to access the service. This type of service is known as cluster IP to create such a service.

Cluster IP Service

apiVersion: v1
kind: Service
  name: nginx-clusterip-service

  type: ClusterIP
    - targetPort: 80
      port: 80
    app: nginx
$ kubectl create -f nginx-clusterip-service.yaml 
service/nginx-clusterip-service created

$ kubectl get services
NAME                      TYPE        CLUSTER-IP      EXTERNAL-IP   PORT(S)        AGE
kubernetes                ClusterIP       <none>        443/TCP        80m
nginx-clusterip-service   ClusterIP   <none>        80/TCP         28s

$ kubectl get ep nginx-clusterip-service
NAME                      ENDPOINTS                                               AGE
nginx-clusterip-service,, + 1 more...   8m12s
# If you are using minikube
minikube ip

minikube ssh
docker@minikube:~$ curl
docker@minikube:~$ curl
docker@minikube:~$ curl
docker@minikube:~$ curl
<!DOCTYPE html>
<title>Welcome to nginx!</title>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href=""></a>.<br/>
Commercial support is available at
<a href=""></a>.</p>

<p><em>Thank you for using nginx.</em></p>

Leave a Reply

Your email address will not be published.