In this guide, weโll learn how to deploy a simple Pod in Google Kubernetes Engine (GKE) and expose it to the outside world using a LoadBalancer Service โ all in a declarative way (using YAML manifests).
Step 01: Understanding Kubernetes YAML Top-Level Objects
Every Kubernetes resource is defined in a YAML manifest.
The top-level objects youโll see in almost every YAML file are:
apiVersion: # Defines the API version to use (e.g., v1, apps/v1)
kind: # Type of Kubernetes resource (Pod, Service, Deployment, etc.)
metadata: # Information about the resource (name, labels, namespace)
spec: # Desired state (configuration details)
๐ Think of it like this:
- apiVersion โ which API group to use.
- kind โ what resource you want.
- metadata โ how Kubernetes identifies it.
- spec โ how it should behave.
Step 02: Create a Simple Pod Definition
Letโs create a Pod that runs a simple Nginx-based application.
๐ Create a directory for manifests:
mkdir kube-manifests
cd kube-manifests
๐ File: 01-pod-definition.yaml
apiVersion: v1
kind: Pod
metadata:
name: myapp-pod
labels:
app: myapp
spec:
containers:
- name: myapp
image: stacksimplify/kubenginx:1.0.0
ports:
- containerPort: 80
๐ Key points:
- We label the Pod with app: myapp.
- The container runs on port 80.
โ
Apply it:
kubectl apply -f 01-pod-definition.yaml
kubectl get pods
Step 03: Create a LoadBalancer Service
Now that we have a Pod, letโs expose it using a LoadBalancer Service.
This Service will provision a GCP external load balancer and route traffic to our Pod.
๐ File: 02-pod-LoadBalancer-service.yaml
apiVersion: v1
kind: Service
metadata:
name: myapp-pod-loadbalancer-service
spec:
type: LoadBalancer
selector:
app: myapp # matches our Pod label
ports:
- name: http
port: 80 # Service port (external entry point)
targetPort: 80 # Container port inside Pod
๐ Flow of traffic:
[Internet User] โ [GCP LoadBalancer] โ [K8s Service Port 80] โ [Pod Container Port 80]
โ
Apply it:
kubectl apply -f 02-pod-LoadBalancer-service.yaml
kubectl get svc
๐ Look for an External IP assigned to your Service.
โ
Test it:
curl http://<Load-Balancer-External-IP>
You should see the Nginx response page ๐
Step 04: Clean Up
When done, delete the resources:
kubectl delete -f 01-pod-definition.yaml
kubectl delete -f 02-pod-LoadBalancer-service.yaml
๐ฏ Summary
- Pods are the smallest deployable unit in Kubernetes.
- Services provide a stable endpoint to access Pods.
- A LoadBalancer Service in GKE creates a GCP Load Balancer and exposes your app to the internet.
This is the simplest way to expose a Pod to the outside world.
๐ 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)