DEV Community

Cover image for Part-104: How to Configure a ClusterIP Service in Google Kubernetes Engine (GKE)
Latchu@DevOps
Latchu@DevOps

Posted on

Part-104: How to Configure a ClusterIP Service in Google Kubernetes Engine (GKE)

Kubernetes ClusterIP Services allow internal communication between pods using a stable IP or DNS name. In this guide, we’ll set up a ClusterIP Service step by step.


Step 1: Introduction

We will deploy a simple Nginx app and expose it internally using a ClusterIP Service.


Step 2: Create a Deployment

Create a file named 01-kubernetes-deployment.yaml:

apiVersion: apps/v1
kind: Deployment 
metadata:
  name: myapp1-deployment
spec:
  replicas: 2
  selector:
    matchLabels:
      app: myapp1
  template:  
    metadata:
      name: myapp1-pod
      labels:
        app: myapp1
    spec:
      containers:
        - name: myapp1-container
          image: stacksimplify/kubenginx:1.0.0
          ports: 
            - containerPort: 80      
Enter fullscreen mode Exit fullscreen mode

This deployment creates 2 pods running Nginx.


Step 3: Create a ClusterIP Service

Create a file named 02-ClusterIP-Service.yaml:

apiVersion: v1
kind: Service
metadata:
  name: my-clusterip-service 
  labels:
    app: myapp1
spec:
  type: ClusterIP
  selector:
    app: myapp1
  ports:
    - name: http
      port: 80
      targetPort: 80
Enter fullscreen mode Exit fullscreen mode

This service exposes your pods internally within the cluster.


Step 4: Deploy the Manifests

# Deploy Deployment and Service
kubectl apply -f 01-kubernetes-deployment.yaml
kubectl apply -f 02-ClusterIP-Service.yaml

# Verify resources
kubectl get deploy      # List deployments
kubectl get po          # List pods
kubectl get svc         # List services
Enter fullscreen mode Exit fullscreen mode

c1


Step 5: Create a Pod for Testing (Optional)

Create a file 03-kube-manifests-curl.yaml to test access to your ClusterIP service:

apiVersion: v1
kind: Pod
metadata:
  name: curl-pod
spec:
  containers:
  - name: curl
    image: curlimages/curl 
    command: [ "sleep", "600" ]
Enter fullscreen mode Exit fullscreen mode

Step 6: Test ClusterIP Service

# Deploy test pod
kubectl apply -f 03-kube-manifests-curl.yaml

# Check the service IP
kubectl get svc

# Enter the pod
kubectl exec -it curl-pod -- sh

# Test using ClusterIP
curl http://<ClusterIP-svc-IP>/

# Test using DNS
curl http://my-clusterip-service
curl http://my-clusterip-service.default.svc.cluster.local
exit
Enter fullscreen mode Exit fullscreen mode

c2

✅ ClusterIP services provide a stable internal IP and DNS name, so your pods can always communicate even if pod IPs change.


Step 7: Clean Up

kubectl delete -f 01-kubernetes-deployment.yaml
kubectl delete -f 02-ClusterIP-Service.yaml
kubectl delete -f 03-kube-manifests-curl.yaml
Enter fullscreen mode Exit fullscreen mode

Key Takeaways

  • ClusterIP services are internal only; they are not exposed outside the cluster.
  • Use them to load balance traffic among pods.
  • Kubernetes handles DNS resolution automatically, so pods can always reach each other reliably.

🌟 Thanks for reading! If this post added value, a like ❤️, follow, or share would encourage me to keep creating more content.


— Latchu | Senior DevOps & Cloud Engineer

☁️ AWS | GCP | ☸️ Kubernetes | 🔐 Security | ⚡ Automation
📌 Sharing hands-on guides, best practices & real-world cloud solutions

Top comments (0)