In this guide, we’ll walk through how to expose a Pod in Google Kubernetes Engine (GKE) using a Kubernetes LoadBalancer Service. This will make your application accessible externally (from the internet) with a public IP address provided by GCP.
🔹 Step 01: Expose a Pod with a Service
First, let’s create a Pod and then expose it with a LoadBalancer Service.
👉 Create a Pod
# Template
kubectl run <desired-pod-name> --image <Container-Image>
# Example
kubectl run my-first-pod --image ghcr.io/stacksimplify/kubenginx:1.0.0
👉 Expose the Pod as a Service
# Template
kubectl expose pod <Pod-Name> --type=LoadBalancer --port=80 --name=<Service-Name>
# Example
kubectl expose pod my-first-pod --type=LoadBalancer --port=80 --name=my-first-service
👉 Get Service Information
kubectl get service
kubectl get svc
Observations:
- Initially, the EXTERNAL-IP field will show as pending.
- After 2–3 minutes, GCP will provision a Cloud Load Balancer and assign an External IP.
- Once available, your Service will be accessible on that IP.
👉 Describe the Service
kubectl describe service my-first-service
👉 Access the Application
http://<External-IP-from-get-service-output>
curl http://<External-IP-from-get-service-output>
🔹 Step 02: Verify Additional Features in GKE
Once the LoadBalancer Service is created, you can also verify its presence in the GCP Console.
👉 Workloads Tab
- Go to Kubernetes Engine → Clusters → standard-public-cluster-1 → Workloads
👉 Services & Ingress Tab
- Go to Kubernetes Engine → Clusters → standard-public-cluster-1 → Networking → Gateway, Services & Ingress
👉 Cloud Load Balancer
- Go to Network Services → Load Balancing
- Verify:
- Backends (your Pods registered behind the Service)
- Frontends (the External IP created)
🔹 Step 03: Interact with a Pod
Now that your Pod is running, let’s interact with it directly.
👉 Verify Pod Logs
# Get Pod Name
kubectl get po
# Dump Pod logs
kubectl logs <pod-name>
kubectl logs my-first-pod
# Stream logs while accessing the app
kubectl logs -f my-first-pod
👉 Connect to the Container
# Open an interactive shell inside the container
kubectl exec -it <pod-name> -- /bin/bash
kubectl exec -it my-first-pod -- /bin/bash
# Run some commands inside the container
ls
cd /usr/share/nginx/html
cat index.html
exit
👉 Run Individual Commands
# Template
kubectl exec -it <pod-name> -- <COMMAND>
# Examples
kubectl exec -it my-first-pod -- env
kubectl exec -it my-first-pod -- ls
kubectl exec -it my-first-pod -- cat /usr/share/nginx/html/index.html
🔹 Step 04: Get YAML Output of Pod & Service
You can inspect the YAML definitions of your resources.
# Get Pod definition
kubectl get pod my-first-pod -o yaml
# Get Service definition
kubectl get service my-first-service -o yaml
🔹 Step 05: Clean-Up
Once you’re done testing, clean up the resources.
# List all objects in default namespace
kubectl get all
# Delete Service
kubectl delete svc my-first-service
# Delete Pod
kubectl delete pod my-first-pod
# Verify cleanup
kubectl get all
✅ Summary
In this demo, we:
- Created a Pod in GKE
- Exposed it using a Kubernetes LoadBalancer Service
- Verified the External IP and accessed the application
- Explored logs and exec commands inside the Pod
- Cleaned up the resources
With this setup, you can make your applications publicly accessible in Google Cloud via Kubernetes LoadBalancer Services.
🌟 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)