Understanding Kubernetes Service Types— A Beginner’s Guide
Practical Examples of ClusterIP, NodePort, and LoadBalancer for Kubernetes Service type

Find Complete mind map of A Beginner’s Guide to Kubernetes
In our previous post, we gained an overview of Kubernetes Services and different types of communication between pods in a cluster.
In this follow-up article, we will delve deeper into the practical aspects of Services , with a focus on different types such as ClusterIP, NodePort and LoadBalancer.
By exploring code examples and demonstrations, we aim to provide you with a hands-on understanding of how these Service types work and their practical applications. So, let’s dive right in and discover the power of Kubernetes Services!
Check out “Understanding Kubernetes — A Beginner’s Guide” for the comprehensive series🚀
What is ClusterIP?
ClusterIP is one of the fundamental Service types in Kubernetes. It provides a stable internal IP address to expose the Service within the cluster.
This type is suitable for scenarios where the Service needs to be accessible only within the cluster itself.
In other words, it allows communication between pods using their IP addresses, enabling seamless connectivity between different components of your application.
Code Example — Creating a ClusterIP Service:
To illustrate the usage of ClusterIP, let’s consider a scenario where we have three pods running in our cluster, each with its own unique IP address. Let’s assume the following IP addresses for our pods:
$ kubectl get pods
NAME READY STATUS RESTARTS AGE IP
pod-a 1/1 Running 0 5m 10.0.0.1
pod-b 1/1 Running 0 3m 10.0.0.2
pod-c 1/1 Running 0 2m 10.0.0.3
Now, let’s create a ClusterIP Service that targets these three pods, providing a single entry point to access them. Here’s an example of how the code would look:
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: my-app
type: ClusterIP
ports:
- name: http
port: 80
targetPort: 8080
In this example, we define a Service called my-service
that selects pods labeled with app: my-app
.
The Service is of type ClusterIP, meaning it will be assigned a stable internal IP address within the cluster.
The port
field represents the port on which the Service will be accessible, while targetPort
specifies the port on the pods (8080) to which the Service will forward the traffic.
Once you deploy this Service, Kubernetes will allocate a ClusterIP for it. Let’s say the allocated ClusterIP is 10.0.0.10
. Now, you can access the pods behind the Service by using the ClusterIP and the defined port.
For example, if you make a request to crul 10.0.0.10:80
, Kubernetes will route the traffic to one of the pods with port: 80880 (Pod A, Pod B, or Pod C).
This abstraction layer provided by Kubernetes simplifies the management and accessibility of your services within the cluster.
Key Takeaway
In summary, here are the key takeaways from our exploration of Kubernetes services:
- ClusterIP provides internal access to services within the Kubernetes cluster.
- Each service type serves a specific purpose and offers different levels of accessibility.
Stay tuned for our next article, where we will dive into Ingress — an essential concept for managing external access to Kubernetes services.
Don’t miss out on this important topic as we continue our journey of understanding Kubernetes!
🔔 Stay tuned or subscribe to my series: “Understanding Kubernetes — A Beginner’s Guide” to explore everything about Kubernetes. 🚀
➕Join the Medium Membership Program to support my work and connect with other writers.
📝 Have questions or suggestions? Leave a comment or message me through Medium. Let’s connect!
Thank you for your support! 🌟