Kubernetes Labs · Lab 7 of 9
Google GKE Autopilot: Managed Nodes, Gateway API and Workload Identity
Create a GKE Autopilot cluster where Google runs both the control plane and the nodes, push an image to Artifact Registry, expose the app with GKE's Gateway controller, and give pods Google Cloud permissions without key files.
- Environment
- Google Cloud
- Level
- Intermediate
- Time
- About 50 min
- Cost
- About $0.10 per hour; free tier credit may cover it
You will build
A regional Autopilot cluster serving the app through a Google Cloud external Application Load Balancer created from a Gateway, with the image in Artifact Registry and the pods using Workload Identity Federation.
Before you start
- Lab: Services, DNS and the Gateway API: Getting Traffic to Pods
A Google Cloud project with billing enabled
gcloud CLI, kubectl and Docker installed
GKE Autopilot goes one step further than other managed clusters: Google runs the control plane and the nodes. You never size or patch nodes; you are billed for the CPU and memory your pods request. Autopilot also enforces good defaults (no privileged pods, requests required), so manifests that cut corners are rejected.
The components
- Autopilot cluster (regional): control plane and nodes spread over three zones of
europe-west1, managed by Google, including upgrades. - Artifact Registry: Google's registry; nodes pull images from it with their own identity.
- GKE Gateway controller: turns Gateway API objects into Google Cloud load balancers. The class
gke-l7-global-external-managedcreates a global external Application Load Balancer that sends traffic to pods through network endpoint groups (NEGs), which hold pod IPs. - Workload Identity Federation for GKE: IAM trusts the pod's Kubernetes service account directly, so pods get short-lived Google credentials with no key files.
Cost: the cluster management fee is $0.10 per hour, and GKE's free tier gives each billing account a monthly credit that covers one Autopilot cluster. The pods' requested resources and the load balancer add a few cents per hour. Delete everything when you finish.
About the outputs: the manifests in this lab were validated against a real Kubernetes 1.37 API server
(kubectl apply --dry-run=server), and the dry-run output shown is real. The cloud commands were not run for you:
they need your own account, and their output contains account IDs, names and addresses that differ for everyone. Those
steps tell you what to check instead.
Project structure
gke/ └── app.yaml # namespace, service account, Deployment, Service, Gateway, HTTPRoute
Steps
-
1Set up gcloud and enable the APIs
Run gcloud auth login gcloud config set project PROJECT_ID gcloud services enable container.googleapis.com artifactregistry.googleapis.comCheck:gcloud config listshows your project, and the services command finishes without errors. -
2Create the Autopilot cluster
Takes about 10 minutes. There are no node settings: Autopilot adds nodes when pods need them.
Run gcloud container clusters create-auto shop-gke --location=europe-west1 gcloud container clusters get-credentials shop-gke --location=europe-west1 kubectl get nodes kubectl get gatewayclassCheck:The cluster shows
RUNNING,kubectl get nodeslists a fewgk3-shop-gke-…nodes (more appear as you deploy), andkubectl get gatewayclasslistsgke-l7-global-external-managedamong others: Autopilot comes with the GKE Gateway controller. -
3Push the image to Artifact Registry
Production clusters pull from your own registry, not Docker Hub: no rate limits, vulnerability scanning, and access controlled by IAM.
Run gcloud artifacts repositories create shop --repository-format=docker --location=europe-west1 gcloud auth configure-docker europe-west1-docker.pkg.dev docker pull traefik/whoami:v1.11.0 docker tag traefik/whoami:v1.11.0 europe-west1-docker.pkg.dev/PROJECT_ID/shop/whoami:v1.11.0 docker push europe-west1-docker.pkg.dev/PROJECT_ID/shop/whoami:v1.11.0Check:gcloud artifacts docker images list europe-west1-docker.pkg.dev/PROJECT_ID/shoplistswhoami. -
4The app, its Gateway and its route
Replace
PROJECT_IDin the image. On Autopilot,resources.requestsdecide what you pay, so they are set explicitly. The Gateway and HTTPRoute are the same Gateway API objects as in lab 2; only the class changes.app.yaml apiVersion: v1 kind: Namespace metadata: name: shop --- # Workload Identity: pods using this service account get Google credentials for it, no key files. apiVersion: v1 kind: ServiceAccount metadata: name: web namespace: shop --- apiVersion: apps/v1 kind: Deployment metadata: name: web namespace: shop spec: replicas: 2 selector: matchLabels: app: web template: metadata: labels: app: web spec: serviceAccountName: web containers: - name: whoami image: europe-west1-docker.pkg.dev/PROJECT_ID/shop/whoami:v1.11.0 ports: - name: http containerPort: 80 readinessProbe: httpGet: path: /health port: http resources: # Autopilot bills by these requests requests: cpu: 250m memory: 512Mi limits: memory: 512Mi --- apiVersion: v1 kind: Service metadata: name: web namespace: shop spec: selector: app: web ports: - name: http port: 80 targetPort: http --- # GKE's Gateway controller creates a global external Application Load Balancer for this Gateway. apiVersion: gateway.networking.k8s.io/v1 kind: Gateway metadata: name: shop namespace: shop spec: gatewayClassName: gke-l7-global-external-managed listeners: - name: http protocol: HTTP port: 80 --- apiVersion: gateway.networking.k8s.io/v1 kind: HTTPRoute metadata: name: web namespace: shop spec: parentRefs: - name: shop rules: - backendRefs: - name: web port: 80 -
5Validate before applying
Run kubectl apply --dry-run=client -f app.yamlExpected output
namespace/shop created (dry run) serviceaccount/web created (dry run) deployment.apps/web created (dry run) service/web created (dry run) gateway.gateway.networking.k8s.io/shop created (dry run) httproute.gateway.networking.k8s.io/web created (dry run)
-
6Apply and wait for the load balancer
Run kubectl apply -f app.yaml kubectl -n shop get gateway shop --watchCheck:After about 5 minutes
ADDRESSshows a public IP andPROGRAMMEDisTrue. Press Ctrl+C.Hint
If pods stay Pending for a minute, Autopilot is adding a node for them; that's normal.
-
7Call the app
Run GW=$(kubectl -n shop get gateway shop -o jsonpath='{.status.addresses[0].value}') for i in 1 2 3 4; do curl -s http://$GW/ | grep Hostname; doneCheck:Both pod names appear. The first requests may return 404 or 502 for a minute while the load balancer is programmed.
-
8Give the pods Google Cloud permissions without keys
Grant a role to the principal that stands for service account
webin namespaceshop. Pods using that service account can then call the API: the GKE metadata server exchanges their Kubernetes token for a Google access token. FindPROJECT_NUMBERwithgcloud projects describe PROJECT_ID --format='value(projectNumber)'.Run gcloud projects add-iam-policy-binding PROJECT_ID --role=roles/storage.objectViewer \ --member=principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/shop/sa/web \ --condition=None kubectl -n shop run wi-test --rm -i --restart=Never --image=google/cloud-sdk:slim \ --overrides='{"spec":{"serviceAccountName":"web"}}' -- gcloud storage buckets list --format='value(name)'Check:The test pod lists the project's buckets (or prints nothing if there are none) instead of a permission error.
Clean up
kubectl delete namespace shop # the Gateway controller deletes the load balancer
gcloud container clusters delete shop-gke --location=europe-west1 --quiet
gcloud artifacts repositories delete shop --location=europe-west1 --quiet
gcloud projects remove-iam-policy-binding PROJECT_ID --role=roles/storage.objectViewer \
--member=principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/shop/sa/web
Check Network services → Load balancing in the console: no load balancer from the lab should remain.
In production
Autopilot removes node management, but not the decisions about networking, identity and releases.
What changes
| In this lab | In production |
|---|---|
Cluster created with gcloud |
Terraform (google provider) with the cluster, node settings, networks and IAM in code |
| Default VPC, public control-plane endpoint | A dedicated VPC (or Shared VPC), private cluster, authorized networks or DNS-based endpoint access |
| HTTP on the Gateway | HTTPS with Google-managed certificates, Cloud Armor policies, HTTP redirect |
| Image pushed from a laptop | Cloud Build or CI pushes signed, scanned images; Binary Authorization admits only those |
roles/storage.objectViewer on the whole project |
Least-privilege roles on specific buckets or secrets |
| One cluster | Separate projects (and clusters) per environment; release channels for controlled upgrades |
Autopilot or Standard?
Choose Autopilot unless you need what it restricts: special node types (some GPUs or TPU set-ups), privileged agents, or tight control over node configuration and bin-packing. Standard clusters give you node pools and that control, and with it the patching and capacity work.
Production checklist
- Cluster, network and IAM defined in Terraform; changes go through reviewed plans
- Private control plane access; humans authenticate with Google identities and RBAC groups
- Workload Identity Federation for every pod that calls Google APIs; no service account keys anywhere
- HTTPS with managed certificates and Cloud Armor on public Gateways
- Images only from Artifact Registry, scanned, ideally enforced by Binary Authorization
- Release channel chosen deliberately, with maintenance windows and exclusions
- Cloud Monitoring/Logging dashboards and alerts; budget alerts on the project
Learn the concepts
- Ingress and the Gateway API · Kubernetes Tutorial
- Services · Kubernetes Tutorial
- Google Cloud in Production · Course
- Kubernetes in Production · Course
Preparing for the CKA or CKS exam? Practice tests and mock exams →