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

Members can save this page, take notes and track progress. See membership · Sign in

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.

UsersHTTP(S)Google Cloud projectGlobal external Application LBcreated from the GatewayArtifact Registryimages, pulled by the nodesGKE Autopilot cluster (regional)Gateway controllerGateway + HTTPRoute → LBControl planemanaged by GooglePods web × 2service account shop/webNodesmanaged by Google, billed per podCloud Storage, Secret Manager…Google APIsWorkload Identity Federationpod identity → IAMto pod IPs (NEGs)creates
GKE Autopilot: Google manages control plane and nodes; a Gateway creates the load balancer

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-managed creates 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.
Podservice account shop/webGKE metadata serveron every nodeIAMprincipal://…/ns/shop/sa/webGoogle APIshort-lived tokenNo key files: the pod's Kubernetes identity is trusted by IAM directlyGrant roles to the principal for namespace shop and service account web
Workload Identity Federation for GKE

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

Download starter filesDownload finished project

Steps

  1. 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.com
    
    Check:

    gcloud config list shows your project, and the services command finishes without errors.

  2. 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 gatewayclass
    
    Check:

    The cluster shows RUNNING, kubectl get nodes lists a few gk3-shop-gke-… nodes (more appear as you deploy), and kubectl get gatewayclass lists gke-l7-global-external-managed among others: Autopilot comes with the GKE Gateway controller.

  3. 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.0
    
    Check:

    gcloud artifacts docker images list europe-west1-docker.pkg.dev/PROJECT_ID/shop lists whoami.

  4. 4The app, its Gateway and its route

    Replace PROJECT_ID in the image. On Autopilot, resources.requests decide 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
    
  5. 5Validate before applying

    Run
    kubectl apply --dry-run=client -f app.yaml
    

    Expected 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)
  6. 6Apply and wait for the load balancer

    Run
    kubectl apply -f app.yaml
    kubectl -n shop get gateway shop --watch
    
    Check:

    After about 5 minutes ADDRESS shows a public IP and PROGRAMMED is True. Press Ctrl+C.

    Hint

    If pods stay Pending for a minute, Autopilot is adding a node for them; that's normal.

  7. 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; done
    
    Check:

    Both pod names appear. The first requests may return 404 or 502 for a minute while the load balancer is programmed.

  8. 8Give the pods Google Cloud permissions without keys

    Grant a role to the principal that stands for service account web in namespace shop. Pods using that service account can then call the API: the GKE metadata server exchanges their Kubernetes token for a Google access token. Find PROJECT_NUMBER with gcloud 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

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake