Service Types: ClusterIP, NodePort, LoadBalancer
Learn the different ways to expose services within and outside your Kubernetes cluster.
Service Types: ClusterIP, NodePort, LoadBalancer is a free DevOps Bootcamp lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the DevOps Bootcamp learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Service Exposure Needs
In Kubernetes, Pods are ephemeral and have dynamic IP addresses. Services provide stable network access to your applications. But how do you expose them?
Depending on whether your application needs to be accessed from inside or outside your cluster, and how, Kubernetes offers different Service types. Let's explore the three main ones!
ClusterIP: Internal Access
The ClusterIP is the default Service type. It gives your Service a stable internal IP address, accessible only from within the Kubernetes cluster.
- Pods can reach other Pods using these ClusterIPs and the Service's name.
- It's perfect for backend services that don't need direct external exposure.
- Think of it as an internal load balancer for your Pods.
ClusterIP Service YAML
Here's how you define a Service of type ClusterIP. Notice the type: ClusterIP field, though it's optional as it's the default.
apiVersion: v1
kind: Service
metadata:
name: my-internal-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: ClusterIPAccessing ClusterIP Services
Once deployed, Kubernetes automatically assigns a unique internal IP address (the ClusterIP) to this service. Other Pods can then use the service name (e.g., my-internal-service) or its IP to connect.
Kubernetes' DNS service resolves the service name to its ClusterIP, making internal communication easy and reliable.
NodePort: External Access
What if you need to access your application from outside the cluster? That's where NodePort comes in.
A NodePort Service exposes your application on a static port on every node's IP address in the cluster. Any traffic sent to NodeIP:NodePort is routed to your Service.
- Useful for development and small deployments.
- The NodePort is usually in the range 30000-32767.
NodePort Service YAML
To create a NodePort Service, you explicitly set type: NodePort. Kubernetes will automatically pick an available port in the NodePort range if you don't specify one.
apiVersion: v1
kind: Service
metadata:
name: my-nodeport-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
nodePort: 30080 # Optional: K8s picks if omitted
type: NodePortConnect via NodePort
After deploying a NodePort Service, you can access your application from outside the cluster using <AnyNodeIP>:<NodePort>.
For example, if a node's IP is 192.168.1.100 and the assigned NodePort is 30080, you can reach your app at http://192.168.1.100:30080.
LoadBalancer: Cloud Integration
For production environments on cloud providers (AWS, GCP, Azure), the LoadBalancer Service type is often preferred. It automatically provisions an external cloud load balancer.
This load balancer gets a public IP address and distributes external traffic to your Service's Pods. It handles all the complex routing for you.
LoadBalancer Service YAML
Defining a LoadBalancer Service is straightforward. Your cloud provider does the heavy lifting to provision the external load balancer.
apiVersion: v1
kind: Service
metadata:
name: my-loadbalancer-service
spec:
selector:
app: my-app
ports:
- protocol: TCP
port: 80
targetPort: 8080
type: LoadBalancerExternal Access with LoadBalancer
Once deployed, your cloud provider will create a dedicated load balancer and assign it an external IP address or hostname. You can then use this public endpoint to access your application.
This provides a robust, scalable, and highly available way to expose your services to the internet.
Quick Check: Service Types
Which Kubernetes Service types allow direct external access to your application from outside the cluster?
Recap: Choosing Your Service
You've learned about the three main Kubernetes Service types:
- ClusterIP: For internal-only access within the cluster.
- NodePort: Exposes services on a static port on each node's IP, allowing external access.
- LoadBalancer: Integrates with cloud providers to provision an external load balancer with a public IP.
Choose the right type based on your application's exposure needs and your deployment environment!
Frequently asked questions
Is the “Service Types: ClusterIP, NodePort, LoadBalancer” lesson free?
Yes — the full text of “Service Types: ClusterIP, NodePort, LoadBalancer” is free to read here on the web, and the DevOps Bootcamp course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the DevOps Bootcamp course, upgrade to CoddyKit PRO.
What will I learn in “Service Types: ClusterIP, NodePort, LoadBalancer”?
Learn the different ways to expose services within and outside your Kubernetes cluster. You practise DevOps Bootcamp with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start DevOps Bootcamp?
No prior experience is required. DevOps Bootcamp on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Service Types: ClusterIP, NodePort, LoadBalancer” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this DevOps Bootcamp lesson?
Yes. Every DevOps Bootcamp lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Exposing Apps with Services
- Service Types: ClusterIP, NodePort, LoadBalancer
- Ingress for External Access
- DNS and Service Discovery