π― Goal
Deploy an NGINX Pod, then expose it internally using a ClusterIP Service so other Pods inside the cluster can access it.
πͺ Step 1: Create the NGINX Pod YAML
Create a file named nginx-pod.yaml
You can use Cloud Shell editor (code nginx-pod.yaml) or nano nginx-pod.yaml.
apiVersion: v1
kind: Pod
metadata:
name: nginx-pod
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:latest
ports:
- containerPort: 80
π§± Step 2: Apply the Pod YAML
kubectl apply -f nginx-pod.yaml
β
Expected output:
pod/nginx-pod created
π Step 3: Verify the Pod
kubectl get pods -o wide
You should see:
NAME READY STATUS RESTARTS AGE IP NODE
nginx-pod 1/1 Running 0 15s 10.32.0.12 gke-mycluster-default-pool-xxxx
π Step 4: Create a ClusterIP Service
Now, letβs expose it internally with a Service.
Create a file named nginx-service.yaml:
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 80
type: ClusterIP
π Step 5: Apply the Service
kubectl apply -f nginx-service.yaml
β
Output:
service/nginx-service created
π§© Step 6: Verify the Service
kubectl get svc
Example output:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
nginx-service ClusterIP 10.12.8.47 <none> 80/TCP 10s
This means your Service is created inside the cluster β other Pods can now reach NGINX via http://nginx-service:80.
π§ͺ Step 7: Test the Service (Internally)
Weβll spin up a temporary test Pod inside the cluster and use curl:
kubectl run test-pod --image=busybox:latest --restart=Never -it -- /bin/sh
Once inside the pod shell, run:
wget -qO- http://nginx-service
You should see the default NGINX welcome page HTML:
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
</html>
Exit the shell:
exit
π§Ή Cleanup (Optional)
kubectl delete pod test-pod
kubectl delete svc nginx-service
kubectl delete pod nginx-pod
πΌοΈ Architecture Visualization
Hereβs the simple flow:
[test-pod] --> [ClusterIP Service: nginx-service] --> [nginx-pod]
π§ Service discovery: Kubernetes DNS automatically creates an internal DNS record
β nginx-service.default.svc.cluster.local β resolves to the Podβs IP.
π 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)