GCP DevOps Project
Sprint 06
Sprint 06
In this lesson, you’ll learn how to expose your containerized application on Google Kubernetes Engine (GKE) by extending your existing Deployment manifest with a Service resource. By the end of this sprint, you’ll be able to access your app through a stable, load-balanced endpoint.
Prerequisites
- A running GKE cluster
kubectlconfigured to point at your GKE cluster- An existing
gke-deployment.yamlthat successfully deploys your container
Previously, we deployed our container to GKE, but the application wasn’t reachable from outside the cluster.

Why You Need a Service
A Kubernetes Service
- Provides a stable IP or DNS name for your Pods
- Handles load balancing across Pod replicas
- Supports multiple types of exposure (ClusterIP, NodePort, LoadBalancer)
Note
A Service decouples the network policy from your Pods. Even if your Pods get rescheduled or replaced, the Service IP/DNS remains constant.
Comparing Service Types
| Service Type | Description | Use Case |
|---|---|---|
| ClusterIP | Internal access within the cluster | Microservices communication |
| NodePort | Opens a port on each node’s IP | Quick testing, on-prem clusters |
| LoadBalancer | Provisions a cloud load balancer (GCP, AWS, Azure) | Exposing applications to the public internet automatically |
For GKE, LoadBalancer is the most straightforward way to get an external IP.
Updating gke-deployment.yaml
Add the following Service manifest below your existing Deployment spec in gke-deployment.yaml:
apiVersion: v1
kind: Service
metadata:
name: my-app-service
labels:
app: my-app
spec:
type: LoadBalancer # Exposes the Service via a cloud load balancer
ports:
- port: 80 # External port
targetPort: 8080 # Container port
protocol: TCP
selector:
app: my-app # Matches Deployment pods
Then apply the changes:
kubectl apply -f gke-deployment.yaml
Run kubectl get svc my-app-service to retrieve the external IP:
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
my-app-service LoadBalancer 10.96.5.123 34.68.12.34 80:31234/TCP 2m
Your application is now accessible at http://34.68.12.34.
Warning
Provisioning a LoadBalancer can incur additional GCP costs. Be sure to delete unused Services when you’re done.
Links and References
Watch Video
Watch video content