Choose the Cluster Operating Model and Supported Features
Three contracts are settled before the first apply. Operating mode, cluster location and network attachment are create-time properties of a GKE cluster. Change your mind later and the honest answer is a second cluster with a migration, not an in-place edit of the first.
Autopilot trades node control for a smaller surface. GKE provisions nodes from pod requests, bills the requested capacity rather than the machine, and blocks privileged containers, host paths and most DaemonSets outside its allowlist. It also turns Workload Identity on for you, which removes a whole class of node-credential mistakes.
Standard keeps the node contract in your hands. You choose machine families, zones, taints, labels, autoscaling bounds and surge settings, and you can run the privileged agents that Autopilot refuses. That control is also the obligation: an unset node service account, an unbounded pool or an ignored upgrade window is now your incident.
The mode is a flag the API enforces. Autopilot arrives as enable_autopilot, and a default pool or node configuration submitted alongside it is rejected rather than merged. Pick the mode from how much node-level work the platform team actually wants to own.
The network attachment crosses a project boundary in a shared VPC. The cluster lives in the service project while the subnet and its secondary ranges live in the host project, which makes the attachment a contract between two owners. The host team grants the cluster's service agent and node account network rights on that subnet, and the cluster root only references what it was given.
Regional is the default worth choosing. A regional cluster spreads control-plane replicas across zones in the region, so a zone loss does not take the API with it. A zonal cluster has one control plane, and brief API unavailability during control-plane maintenance is expected rather than exceptional.
A release channel is an ownership decision, not a version lock. The release_channel block moves on Google's schedule, and the provider can report the default version for a channel. A pinned minor version is supported for a window and then upgraded anyway, so a pin buys preparation time, not a freeze.
Node pools belong in their own resources. A pool declared inside the cluster block cannot be removed without recreating the cluster, while a separate pool resource can be drained and replaced. Remove the default pool with remove_default_node_pool, then own each pool explicitly with bounds, taints and surge settings.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
W["Workload shape
and team skills"] --> MODE{"Who runs
the nodes?"}
MODE -->|"platform team"| AUTO["Autopilot
pods billed by request"]
MODE -->|"application team"| STD["Standard
pools you size"]
AUTO --> LOC{"Zone loss must
not stop the API?"}
STD --> LOC
LOC -->|"yes"| REG["Regional cluster
replicas across zones"]
LOC -->|"no"| ZON["Zonal cluster
one control plane"]
REG --> CH{"Who owns
upgrades?"}
ZON --> CH
CH -->|"named owner"| OK["Release channel
plus maintenance window"]
CH -->|"nobody"| PIN["Pinned version ages out
GKE upgrades anyway"]
OK --> POOL["Pools as separate resources
bounds, taints, surge"]
PIN -.->|"later symptom"| SKEW["Add-on and node image
disagree after a patch"]
POOL --> FROZEN["Create-time contracts
mode, location, network"]
FROZEN -.->|"change of mind"| REBUILD["Second cluster
and a migration"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class W,POOL primary;
class AUTO,STD,REG,ZON secondary;
class OK ok;
class MODE,LOC,CH,FROZEN warn;
class PIN,SKEW,REBUILD danger;
Plan API Reachability Before Kubernetes Provider Initialization
The provider is a client that connects before the graph exists. Provider configuration is evaluated during plan, so a cluster created in the same run does not exist yet. No dependency edge can order a process that has to start first, which is why one root cannot both build the API and talk to it.
Authorized networks are a list of caller addresses. A public endpoint is closed to everything not in master_authorized_networks_config, so the runner's egress range has to be there before the first plan. That range changes when the runner moves to a different subnet or a managed CI pool, and the failure looks like a timeout rather than a permission error.
Private nodes and a private endpoint are separate switches. enable_private_nodes strips public addresses from nodes; enable_private_endpoint strips the public address from the API. Enabling both is the strict shape, and it puts the plan inside the VPC, behind a bastion, or behind a proxy.
The master range is a peering reservation. The master_ipv4_cidr_block must not overlap anything in the network, and only one cluster can claim a given block. Treat it like the secondary ranges: allocated by the network root, recorded, and never reused by hand.
A DNS endpoint removes the bastion from the diagram. The control plane can be reached by name through dns_endpoint_config, which fronts the private address, and external traffic can be allowed when authorized networks also permit it. Token and certificate auth over that endpoint are separate switches, so enable the ones your client actually uses.
Connect Gateway is the other way in. A cluster registered to a fleet can be reached through it, which authorizes the caller in Google IAM rather than by network position. It does not remove the readiness gate, but it does let a runner outside the VPC reach a private endpoint without a jump host, and the authorization is auditable in the same place as everything else.
Tokens expire in the middle of a long apply. google_client_config returns an access token with roughly an hour of life, and a cluster apply followed by a workload apply can cross that boundary. The failure arrives as an authentication error halfway through a run that had already planned cleanly.
Use an exec credential that mints per call. The Kubernetes provider can run gke-gcloud-auth-plugin as an exec credential instead of holding a static token. It reads application default credentials, so impersonation and federated runner credentials keep working without a key file in state.
Readiness has three gates, and the third is the one people skip. The cluster must report a running status, the API must answer a readiness probe, and the nodes plus system add-ons must be ready. A manifest that installs a custom resource needs the add-on that defines its type to exist first, or the plan fails on an unknown kind.
Put the gate in the pipeline between the two roots. Apply the infrastructure root, publish the endpoint, certificate and cluster name, probe readiness, then plan the workload root. Terraform orders resources inside a state, not across a hand-off between two runs.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
PLAN["terraform plan
workload root"] --> CFG["provider configuration
host, CA, credential"]
CFG --> REACH{"API endpoint
reachable from here?"}
REACH -->|"private endpoint,
runner outside VPC"| TMO["TCP timeout
no diff produced"]
REACH -->|"public endpoint,
runner not listed"| DENY["Connection refused
or blocked at the edge"]
REACH -->|"yes"| AUTH{"Credential still
valid?"}
AUTH -->|"static token
older than an hour"| EXP["401 midway
apply aborts"]
AUTH -->|"exec plugin
mints per call"| READY{"Cluster running,
API answers,
nodes Ready?"}
READY -->|"no"| EARLY["Plan against a
half-built cluster"]
READY -->|"yes"| APPLY["Apply namespace,
KSA and deployment"]
APPLY --> CHECK{"CRD from an add-on
already installed?"}
CHECK -->|"no"| KIND["Unknown kind
plan fails"]
CHECK -->|"yes"| OK["Objects reconciled
one digest, one identity"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class PLAN,APPLY primary;
class CFG secondary;
class OK ok;
class REACH,AUTH,READY,CHECK warn;
class TMO,DENY,EXP,EARLY,KIND danger;
Map Node and Workload Access to Google IAM
Four identities appear in one apply, and only one of them belongs to Google. The Terraform principal runs the apply, the GKE service agent acts for the control plane, the node service account belongs to the node, and a workload gets a Google identity through federation. Treating them as one service account is where GKE permission incidents start.
The deployer needs impersonation rights, which is the real privilege. Creating a node pool with a chosen service account requires roles/iam.serviceAccountUser on that account, and the same is true when wiring a workload identity. Granting it on a powerful account hands the account over, so scope it to the two or three identities the stack actually uses.
The GKE service agent is Google-managed but not invisible. It creates load balancers, forwarding rules, persistent disks and firewall rules on your behalf, and it is the identity that owns the cloud objects your Kubernetes Services ask for. In a shared network it needs a host-project grant, and the node account needs network rights on the subnet.
The node service account is node-wide by construction. Every pod scheduled on the node can reach what that account can reach unless something stands between them. Set it explicitly instead of inheriting the Compute Engine default account, and give it roles/artifactregistry.reader on one repository, log writes and metric writes, then stop.
Workload Identity replaces the node credential at the metadata server. A pod that asks the metadata server for a token is answered by GKE, which returns the federated Google identity rather than the node account. The node account stays invisible to the pod, which is the entire point of the feature.
The federation is a three-part subject. The binding grants roles/iam.workloadIdentityUser on the Google account for a subject built from the project pool, a namespace and a service account, and the annotation iam.gke.io/gcp-service-account points that account at the identity. A typo in any part fails the exchange with a message that rarely names the part you got wrong.
Grant on the target, not on the identity. The binding proves who the pod is; a role on a bucket, secret or dataset decides what it can touch. Keep that role on the resource, and keep the federated binding as a single-member grant so it does not replace every other holder of the account.
One credential path per cluster. Mounted key files, the legacy metadata concealment setting and the GKE metadata server are three different answers to the same question. Keep the supported federation path, remove the alternatives, and let the node account carry only what the node itself needs.
Autopilot and Standard reach the same place differently. Autopilot enables the workload pool and the metadata server for you; on Standard both workload_identity_config and the per-pool metadata mode are yours to set. A pool created without that mode silently breaks the chain, and the pod falls back to the node account.
Separate Artifact Registry Repositories from Image Builds
The registry outlives every cluster. An image is pushed many times a day while a cluster changes on a different schedule and may be rebuilt without losing a single artifact. Give the repository its own root and its own state file, and let clusters be consumers.
Builds belong to CI with a push identity. A build account with roles/artifactregistry.writer on one repository produces the artifact, and nothing in the cluster needs to know how it was produced. A server-side build also keeps a container daemon off the runner, which is one less privileged process in the pipeline.
A tag is a label; a digest is the release. Tags are mutable by design, so two builds can share one name and a rollback can silently land on different bytes. Promote the digest, put it in the deployment, and let the tag live in release notes and dashboards.
Immutability changes how you name releases. Turning on immutable_tags makes the repository refuse an overwrite of an existing tag, which turns a silent replacement into a failed push. That is the right default, but it also means a floating latest tag can be written exactly once, so plan the naming before you enable it.
Location is a latency and cost decision. A repository in the cluster's region keeps pulls on the short path; a cross-region or multi-region repository works but adds latency and egress. Pick the repository location with the cluster regions in mind, and treat a move as a migration rather than a field change.
Cleanup policy is part of the contract. A repository grows until someone says otherwise, and the policy that deletes untagged manifests or keeps the last few versions is a lifecycle decision. Run it in dry-run mode first, confirm what it would remove, then let it delete.
Pull access is one binding on the repository. The node account gets roles/artifactregistry.reader on the repository rather than the project, and no image pull secret is needed for the normal path. In a cross-project setup the binding lives in the repository's project, and private nodes still need a route to the registry endpoint.
Promotion is a retag or a shared digest, never a rebuild. Rebuilding from the same commit can produce different bytes, so the promoted artifact has to be the one that was tested. A retag preserves the digest and gives each environment a readable name.
Never build inside the registry apply. A local-exec provisioner that pushes an image puts registry credentials in the plan and makes the apply depend on a daemon that may not exist on the runner. The build is CI's job; Terraform records the repository, the policy and the permission.
Verify One Workload and Decommission in Dependency Order
Verify one workload, not a platform. One namespace, one deployment, one ClusterIP service and one federated identity prove the whole straight line: pull, schedule, token exchange and log delivery. Ingress, autoscaling and a mesh come after the line works.
Break one path at a time. Remove the repository binding to prove the pull path, then remove the federated binding to prove the identity path. A single test that fails tells you a boundary broke but not which one, and the messages look more similar than they should.
The pull failure has three distinct shapes. A missing repository binding fails authorization; a private node with no route to the registry times out; a tag that no longer exists reports a manifest unknown. Read the event before changing a permission, because the third shape is a lifecycle problem, not an IAM one.
Teardown follows the graph you wrote, then the graph GKE wrote. Workload objects go first, then the load balancers and addresses that Services created, then the pools and the cluster. Reversing that order strands cloud objects that no Terraform resource ever owned.
A load balancer Service is a cloud resource with a Kubernetes handle. The controller creates a forwarding rule, a backend and an address when the Service appears, and removes them when it disappears. Destroy the cluster first and the controller is gone, so the rule and the address can outlive the object that asked for them.
Persistent disks are the expensive orphan. A dynamically provisioned volume is deleted with its claim under the delete policy and retained under the retain policy, and both outcomes depend on the driver still running. Delete the cluster before the claims and the driver cannot finish, leaving disks that no state file mentions.
Deletion protection makes destroy a two-step operation. The flag has to be false in state before the destroy will proceed, which means an apply that changes only that field.
Registry destruction is data loss, so keep it out of the routine path. Deleting the repository deletes every image and every digest a rollback might need. Gate that change separately, and confirm the images are reproducible or archived before anyone runs it.
Verify One Workload and Decommission in Dependency Order
Execution status: design-only. These steps are a lab plan; no live project output is recorded here, and every identifier is written as a token rather than a real value.
Prerequisites. Terraform 1.17.1, hashicorp/google 8.10.0 and hashicorp/kubernetes 3.5.0, one sandbox project with billing enabled, a VPC with a subnet and secondary ranges, a repository in the cluster region, permission to push one image, and permission to create service accounts and role bindings. Use a digest you pushed yourself.
| Boundary | Owner root | Proof it holds |
|---|---|---|
| repository and digest | registry root | the deployment names a digest that exists in the repository |
| image pull | cluster root | the pod reaches Running with no pull event |
| workload token | workload root | one permitted call succeeds, one unrelated call is denied |
| namespaced objects | workload root | destroy removes the Service before the cluster is deleted |
- Create the repository with a cleanup policy in dry-run mode, push one image with the build identity, and record the digest. Confirm the cluster root plans no repository change.
- Consume the network root's outputs in the cluster root: subnet, pod and service ranges, and the master range. Choose Autopilot or Standard, a regional location and a release channel before the apply.
- Apply the cluster root with the workload pool enabled, one tainted system pool and one bounded user pool that sets the metadata mode. Read back the endpoint, certificate and workload pool.
- Add the runner's egress range to the authorized networks, or run from inside the VPC, and confirm a plan against the cluster succeeds before any object is declared.
- Probe readiness until the API answers and every node reports Ready. Confirm the add-on that defines your custom resource is present if the workload uses one.
- Apply the workload root: namespace, annotated service account, federated binding on one Google account, deployment by digest and a ClusterIP service.
- Exec into the pod and call one resource the role allows, then one it does not. Then remove the repository binding and confirm the next pod fails at pull, not at token exchange.
- Destroy the workload root, wait for the Service and its cloud objects to disappear, delete the claims, then the pools, then the cluster with deletion protection disabled, and leave the repository in place.
Expected observation. Each step moves one boundary. The identity test changes what the pod may call without touching the image, the pull test changes registry access without touching the federated binding, and the workload destroy removes Kubernetes objects before the cluster that hosts them.
Failure checks. The lab fails if the pod can call an API its identity does not grant, if a forwarding rule or address survives the workload destroy, if a persistent disk survives the claim destroy, if the cluster destroy leaves instance groups or disks behind, or if the repository disappears as part of cluster teardown.
Cleanup order. Workload objects, then load-balancer Services and their addresses, then claims and volumes, then node pools, then the cluster, then the repository, then the network ranges. Check the forwarding rule, address, disk and instance group views after each stage rather than only at the end, and give the controller time to finish before calling an object stranded.
Evidence to keep. The approved digest, the annotated service account and its federated subject, one permitted and one denied API result, the pull failure event, and the cleanup audit with the time each residual object disappeared.
Next in the Series
In Google Security and Telemetry: KMS, Secret Manager and Audit Evidence, we'll explore Trace access and data exposure through encryption, secret delivery, logs and organization controls.