DEV Community

Cover image for Part-83: 🚀Expose a Pod with Google Kubernetes Engine Load balancer Service in GCP (Imperative way)
Latchu@DevOps
Latchu@DevOps

Posted on

Part-83: 🚀Expose a Pod with Google Kubernetes Engine Load balancer Service in GCP (Imperative way)

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
Enter fullscreen mode Exit fullscreen mode

👉 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
Enter fullscreen mode Exit fullscreen mode

👉 Get Service Information

kubectl get service
kubectl get svc
Enter fullscreen mode Exit fullscreen mode

s1

Observations:

  1. Initially, the EXTERNAL-IP field will show as pending.
  2. After 2–3 minutes, GCP will provision a Cloud Load Balancer and assign an External IP.
  3. Once available, your Service will be accessible on that IP.

👉 Describe the Service

kubectl describe service my-first-service
Enter fullscreen mode Exit fullscreen mode

s2

👉 Access the Application

http://<External-IP-from-get-service-output>
curl http://<External-IP-from-get-service-output>
Enter fullscreen mode Exit fullscreen mode

s3


🔹 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

s4

👉 Services & Ingress Tab

  • Go to Kubernetes Engine → Clusters → standard-public-cluster-1 → Networking → Gateway, Services & Ingress

s5

👉 Cloud Load Balancer

s6

  • Go to Network Services → Load Balancing
  • Verify:
  1. Backends (your Pods registered behind the Service)
  2. Frontends (the External IP created)

s7


🔹 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
Enter fullscreen mode Exit fullscreen mode

s8

👉 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
Enter fullscreen mode Exit fullscreen mode

s9

👉 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
Enter fullscreen mode Exit fullscreen mode

s10


🔹 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   
Enter fullscreen mode Exit fullscreen mode

s11


🔹 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
Enter fullscreen mode Exit fullscreen mode

s12


✅ 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)