How-to guide / Start and inspect a Kix project
Deploy to GKE
These docs describe Kix's main branch, which can include changes not yet released. Read the docs for the latest release.
Deploy a Kix cluster definition to an existing Google Kubernetes Engine (GKE) Standard or Autopilot cluster. This guide covers choosing the right GKE flavor, binding the definition to your cluster’s UID, granting Google Cloud IAM roles to workloads, and setting the IP ranges Kix needs to generate NetworkPolicy objects for GKE Dataplane V2.
This guide assumes Kix, kubectl, and gcloud are installed, and that your current kubectl context points to your GKE cluster. (The Kix library also includes kix.flavors.aks for Azure Kubernetes Service, which has not been tested on a live AKS cluster yet and does not support generated network policies.)
Choose a flavor and check your cluster
Section titled “Choose a flavor and check your cluster”Include kix.flavors.gke for GKE Standard, or kix.flavors.gke-autopilot for GKE Autopilot, as the first module in kix.buildCluster.
Both flavors assume your cluster has:
- A managed control plane, multiple nodes (
multiNode = true), and GKE’s managedmetrics-server(metricsApirole,exclusive). - GKE Dataplane V2 (
cniandnetwork-policy-enforcerroles,exclusive). - Cluster DNS (
kube-dnsinkube-system), GCP Network Load Balancers forLoadBalancerServices, and the Persistent Disk CSI driver withstandard-rwoas the defaultStorageClass. - Workload Identity Federation for GKE enabled.
Confirm that your cluster runs Dataplane V2 and Workload Identity Federation:
❱ gcloud container clusters describe <cluster> --location <location> --format='value(networkConfig.datapathProvider)'❱ gcloud container clusters describe <cluster> --location <location> --format='value(workloadIdentityConfig.workloadPool)' datapathProvider prints ADVANCED_DATAPATH when Dataplane V2 is active (required for Kix’s generated network policies on GKE), and workloadPool prints my-project.svc.id.goog.
Size small Standard clusters
Section titled “Size small Standard clusters”kix.flavors.gke and kix.flavors.gke-autopilot set cluster.capabilities.multiNode = true and leave availabilityZones unset, which sets cluster.availability.default to "node". Packages that scale with availability then run at least two replicas per controller (for example, cert-manager and external-secrets each run six pods across three Deployments). On a small Standard cluster such as two 2-vCPU nodes, deploying several controllers can exhaust CPU requests and leave pods such as Velero’s node agent Pending, which kix deploy and kix status report as 0/2 nodes are available: 2 Insufficient cpu. On small test clusters, set cluster.availability.default = "none"; cluster-wide or availability = "none"; on individual instances (see Set the cluster availability level).
Bind the definition and deploy
Section titled “Bind the definition and deploy”Bind every live cluster definition to its Kubernetes cluster with cluster.kubernetes.uid (the UID of the cluster’s kube-system Namespace). Once set, Kix refuses to apply the build to any other cluster if your kubeconfig points somewhere else.
Read the UID from your GKE cluster:
❱ kubectl get namespace kube-system -o jsonpath='{.metadata.uid}' Add the flavor and your cluster’s UID to your cluster file:
1{ kix, packages }:2kix.buildCluster {3 specialArgs = { inherit kix packages; };4 modules = [5 kix.flavors.gke # or kix.flavors.gke-autopilot6 {7 cluster.kubernetes.uid = "4d7b1c2e-9f3a-4b8e-a1c5-6d2e8f0a9b3c";8 }9 ];10}If you run kix plan or kix deploy before setting cluster.kubernetes.uid, Kix prints the active context, API server address, and the exact cluster.kubernetes.uid line to paste into your definition. See Bind a cluster definition to its Kubernetes cluster for version pinning with k8sVersion and moving a definition to a rebuilt cluster.
Evaluate, preview, deploy, and check your cluster:
❱ kix check <cluster>❱ kix plan <cluster>❱ kix deploy <cluster>❱ kix status <cluster> What differs on GKE Autopilot
Section titled “What differs on GKE Autopilot”Switch the first module to kix.flavors.gke-autopilot on Autopilot clusters. Autopilot changes several behaviors:
- No writes in
kube-system. Autopilot blocks user-managed objects inkube-system. Thegke-autopilotflavor places its platform import records in thegke-managednamespace (which Kix creates) and writes nothing tokube-system. If your cluster declares_-prefixed instances such asinstances._cluster, changecluster.recordNamespacefrom itskube-systemdefault to an existing user namespace. - Baseline Pod Security and host restrictions. GKE’s admission webhook enforces the
baselinePod Security Standard and blocks privileged containers, host namespaces such ashostNetwork, and writablehostPathvolumes. The flavor setsprivilegedContainers = falseandpodSecurityEnforcement = "baseline", sokix checkrejectshostNetworkand privileged workloads before deploy. - No critical PriorityClasses. GKE allows
system-node-criticalandsystem-cluster-criticalonly in namespaces that have a matchingResourceQuota. On GKE Standard,kube-systemhas that quota, sokix.flavors.gkesetscriticalPriorityNamespaces = [ "kube-system" ]and fails with[K7426]in other namespaces. Because Autopilot also blocks user workloads inkube-system,gke-autopilotsetscriticalPriorityNamespaces = [ ]and rejects both classes in every namespace. - DaemonSets and node provisioning. Autopilot allows DaemonSets (
daemonSets = true) and schedules them on every node. First deploys take 2 to 3 minutes while Autopilot provisions nodes for pending pods, and a DaemonSet runs on every node Autopilot adds, increasing cluster cost. - Load balancer role.
gke-autopilotbindsloadBalancerasexclusiverather thanshadowable, so packages cannot replace GKE’s load balancer controller. - Adjusted resource requests. Autopilot raises container resource requests that fall below its minimums (for example, raising a
32Mimemory request to52Mi) and adds anephemeral-storagerequest on the Deployment object. After deployment,kix planshows no differences, whilekix plan --reconcilelists each field Autopilot modified. Set container requests at or above Autopilot’s minimums to avoid those adjustments.
Grant Google Cloud identities to workloads
Section titled “Grant Google Cloud identities to workloads”Kix configures Kubernetes ServiceAccounts for Workload Identity Federation for GKE, and you create the Google Cloud IAM bindings or Google service accounts in your Google Cloud project (my-project with project number 123456789012 in the examples below).
On GKE, these packages accept kix.cloudIdentity.gcp:
external-dns(deps.providerCredentials)cert-manager(deps.controllerIdentity)external-secrets(deps.controllerCredentials)velero(deps.cloudCredentials)
tempo and cnpg-cluster support only S3 cloud identities today; passing kix.cloudIdentity.gcp to either package fails kix check with Google Cloud is not supported yet.
Each package’s upstream documentation defines the Google Cloud IAM permissions it requires. For the external-dns examples below, grant the Cloud DNS permissions described in the ExternalDNS GKE tutorial.
kix.cloudIdentity.gcp supports two forms: granting IAM roles directly to the Kubernetes ServiceAccount (kix.cloudIdentity.gcp { }), or linking the Kubernetes ServiceAccount to a Google service account (kix.cloudIdentity.gcp { serviceAccount = "..."; }).
Grant IAM roles directly to the ServiceAccount
Section titled “Grant IAM roles directly to the ServiceAccount”-
Declare the identity in Kix. Pass
kix.cloudIdentity.gcp { }toexternal-dns. In this snippet, the localexternalDnshelper setsprovider = "google",policy = "upsert-only",txtOwnerId, andextraArgs("--google-project=my-project"and"--domain-filter=example.com"):clusters/test-cloud-identity-gke.nix 32instances.external-dns.clouddns = {33package = packages.experimental.external-dns;34deps.providerCredentials = kix.cloudIdentity.gcp { };35config = externalDns "cloud-identity-gke/direct";36};Kix omits
iam.gke.io/gcp-service-accounton theclouddnsServiceAccount because Google Cloud grants roles directly to the Kubernetes ServiceAccount’s principal. -
Inspect the required IAM principal. Run
kix list resources <cluster>to print the IAM principal under Cloud identities (this reads the local build and does not connect to the cluster):❱ kix list resources <cluster> Cloud identities: Subject Mechanism Identity principal://iam.googleapis.com/projects/<project-number>/locations/global/workloadIdentityPools/<project-id>.svc.id.goog/subject/ns/external-dns/sa/clouddns gke Kubernetes ServiceAccount Replace <project-id> and <project-number> with the cluster's Google Cloud project ID and project number before using a subject in IAM.In
kix list resources <cluster> -o json(for Terraform), this entry lists["<project-number>", "<project-id>"]insubjectPlaceholders. -
Bind the Google Cloud IAM role. Look up your project number, replace
<project-id>(my-project) and<project-number>(123456789012) in theSubjectstring, and grant the IAM<role>the package requires:❱ gcloud projects describe my-project --format='value(projectNumber)'❱ gcloud projects add-iam-policy-binding my-project --role=<role> --member=principal://iam.googleapis.com/projects/123456789012/locations/global/workloadIdentityPools/my-project.svc.id.goog/subject/ns/external-dns/sa/clouddns -
Deploy and confirm. Apply the cluster and check the controller log:
❱ kix deploy <cluster>❱ kubectl logs -n external-dns deploy/clouddnsOnce the IAM binding propagates,
external-dnslogs DNS records being created. You can also confirm the active identity from inside the pod by querying the GKE metadata server (usekubectl debug -n external-dns <pod> --image=<image-with-curl>for an ephemeral container if the workload image lackscurl):❱ curl -H 'Metadata-Flavor: Google' http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/emailFor a direct IAM grant, the metadata server answers
my-project.svc.id.goog.
Link a Google service account
Section titled “Link a Google service account”-
Declare the Google service account in Kix. Pass
serviceAccountinkix.cloudIdentity.gcp:clusters/test-cloud-identity-gke.nix 40instances.external-dns-linked.clouddns = {41package = packages.experimental.external-dns;42deps.providerCredentials = kix.cloudIdentity.gcp {4344};45config = externalDns "cloud-identity-gke/linked";46};Kix writes
iam.gke.io/gcp-service-account: [email protected]on theclouddnsServiceAccount. -
Inspect the required IAM member. Run
kix list resources <cluster>to get theroles/iam.workloadIdentityUsermember string under Cloud identities:❱ kix list resources <cluster> Cloud identities: Subject Mechanism Identity serviceAccount:<project-id>.svc.id.goog[external-dns-linked/clouddns] gke [email protected] Replace <project-id> and <project-number> with the cluster's Google Cloud project ID and project number before using a subject in IAM.In
kix list resources <cluster> -o json, this entry lists["<project-id>"]insubjectPlaceholders. -
Grant the package role and allow impersonation in Google Cloud. Ensure the Google service account
[email protected]exists and holds the Google Cloud<role>the package needs, then grantroles/iam.workloadIdentityUseron that Google service account to theSubjectmember with<project-id>replaced:❱ gcloud iam service-accounts add-iam-policy-binding [email protected] --role=roles/iam.workloadIdentityUser --member='serviceAccount:my-project.svc.id.goog[external-dns-linked/clouddns]' -
Deploy and confirm. Apply the cluster and check the controller log:
❱ kix deploy <cluster>❱ kubectl logs -n external-dns-linked deploy/clouddnsQuerying
http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/emailwith-H 'Metadata-Flavor: Google'from inside the pod returns[email protected], and theclouddnslog shows DNS records created.
Velero’s GCP plugin also signs download and log URLs using backupStorageLocation.config.serviceAccount, so pass the same Google service account email there alongside deps.cloudCredentials (see Deploy Velero):
27 velero = {28 package = packages.experimental.velero;29 # One server: Velero has no leader election.30 availability = "none";31 deps.cloudCredentials = kix.cloudIdentity.gcp {3233 };34 config = {35 awsPlugin.enabled = false;36 extraPlugins.velero-plugin-for-gcp = {37 repository = "docker.io/velero/velero-plugin-for-gcp";38 tag = "v1.14.4";39 };40 backupStorageLocation = {41 provider = "velero.io/gcp";42 objectStorage.bucket = "cloud-identity-velero-gke";43 # The account the plugin signs download URLs as.4445 };46 };47 };When GKE identity setup is wrong
Section titled “When GKE identity setup is wrong”-
No deploy-time pod check on GKE. GKE injects no identity environment variables into containers, so
kix deploycannot check whether a pod received its identity and never raisesCloudIdentityNotAppliedon GKE. A workload with missing or broken IAM bindings deploys cleanly and reportsokinkix status; check the pod logs and metadata server to diagnose failures. -
Log messages that distinguish IAM failures:
- Missing Google Cloud permissions on the principal or Google service account: API calls fail with HTTP 403 (for
external-dns,failed to list zones: googleapi: Error 403: Forbidden). - Missing
roles/iam.workloadIdentityUseron the Google service account (linked form): the Kubernetes ServiceAccount cannot impersonate the Google service account, and pods logPermission 'iam.serviceAccounts.getAccessToken' denied. A newly created IAM binding can take a minute or two to apply, during which pods log this same error before succeeding.
- Missing Google Cloud permissions on the principal or Google service account: API calls fail with HTTP 403 (for
-
Host-network pods refused at
kix check([K2669]). Workload Identity Federation for GKE does not grant cloud identities to pods withhostNetwork: true, which GKE runs with the node pool’s service account instead. If a host-network workload uses a ServiceAccount that carries a cloud identity,kix checkrejects it with[K2669]:1<workload> sets `hostNetwork: true` and uses ServiceAccount `<sa>`, which has a cloud identity from `deps.<dep>`. GKE Workload Identity Federation does not grant cloud identities to host-network pods, so they would run with the node's credentials. Kix rejected <workload>.Use a separate ServiceAccount without a cloud identity, or remove
hostNetwork: true. -
Workloads without an identity and pod restarts. With Workload Identity Federation enabled, a pod whose ServiceAccount has no cloud identity runs as its own Kubernetes ServiceAccount principal, which holds no Google Cloud roles unless you grant them. Kix writes
checksum/cloud-identityonto Kix-built pod templates so changing an identity restarts Deployment, StatefulSet, and DaemonSet pods on deploy. Pods created at runtime by an operator (such as StackGres) keep their previous identity until recreated.
DNS, storage, and load balancers
Section titled “DNS, storage, and load balancers”Cluster DNS and Cloud DNS
Section titled “Cluster DNS and Cloud DNS”GKE enables NodeLocal DNSCache by default starting in 1.34, and Autopilot always runs it. Both GKE flavors list all four GKE DNS peers (kube-dns and node-local-dns pods in kube-system, 169.254.169.254/32, and 169.254.20.10/32), so cluster DNS works automatically under generated network policies.
For public records in Google Cloud DNS:
external-dns: Setprovider = "google"and pass"--google-project=my-project"inextraArgs. Packagedexternal-dns0.24 readsexternal-dns.kubernetes.io/hostnameand ignores the olderexternal-dns.alpha.kubernetes.io/hostnameannotation unless you add"--enable-legacy-annotation-prefix"toextraArgs. See Publish DNS records with external-dns.cert-managerDNS-01: Setdeps.controllerIdentityoncert-managerand omitserviceAccountSecretRefon thedns01.cloudDNSsolver. Use a real address for the ACME accountemail(Let’s Encrypt rejectsexample.com), and sethostedZoneNameon thecloudDNSsolver if cert-manager cannot locate your zone by SOA lookup. See Configure cert-manager issuers.
Persistent storage
Section titled “Persistent storage”Both flavors import standard-rwo (pd.csi.storage.gke.io, WaitForFirstConsumer) as the cluster’s default StorageClass, so persistent-volume-claim instances with no storageClassName use standard-rwo automatically. On a newly created Autopilot cluster, built-in StorageClass objects can take a few minutes to appear. GKE clusters also include classes such as premium-rwo, standard, and Filestore classes when enabled; import another existing class or declare new ones as shown in Configure storage classes and PVCs.
Load balancers
Section titled “Load balancers”A Service with type: LoadBalancer receives a GCP Network Load Balancer IP in roughly 30 seconds. kix deploy waits until status.loadBalancer.ingress contains an address, and kix status reports the Service unready until then. GKE’s webhook adds cloud.google.com/neg annotations to Services without causing drift in kix plan --read-only.
Turn on generated network policy
Section titled “Turn on generated network policy”Dataplane V2 always enforces standard Kubernetes NetworkPolicy objects (networking.k8s.io/v1), so there is nothing to enable in GKE. Because both flavors bind network-policy-enforcer as exclusive to Dataplane V2, Kix writes NetworkPolicy manifests directly and rejects a cilium instance. Kix omits <namespace>-default-deny in kube-system so GKE’s own pods keep running undisturbed. See Enable generated network policy for how Kix derives rules from service connections.
Enable policy generation and supply your cluster’s IP ranges under cluster.network:
30 networkPolicy.enable = true;31 cluster.network = {32 apiServer.cidrs = [ "10.0.0.2/32" ];33 nodeCidrs = [ "10.128.0.0/20" ];34 };Standard NetworkPolicy has no built-in selectors for the API server or cluster nodes. When a generated policy needs those addresses and the corresponding cluster.network option is unset, Kix stops the build and names the option to set:
-
cluster.network.apiServer.cidrs: Required when any workload’s ServiceAccount is bound to aRoleorClusterRole. Dataplane V2 evaluatesipBlockrules after Service address translation, so thekubernetesService ClusterIP never matches; set the API server’s endpoint/32addresses instead. Look them up with:❱ kubectl get endpointslices -n default -l kubernetes.io/service-name=kubernetes -o jsonpath='{.items[*].endpoints[*].addresses[*]}'Append
/32to each IPv4 address returned, and update this list whenever you rotate the control plane IP. Kix does not verify these addresses against the live cluster: if an address is wrong,kix deploysucceeds and existing connections stay open, so pods lose API server access only after they restart. -
cluster.network.nodeCidrs: Required when a policy targets nodes (for example, Prometheus scrapingnode-exporteron the host network). Kix also excludes this range from outboundworldrules on GKE so internet egress does not open node kubelets. Set it to your node subnet’s primary IPv4 range. Look up your cluster’s subnetwork path (projects/<project>/regions/<region>/subnetworks/<subnet>), where<location>is your cluster’s region or zone, then read that subnet’s primary range:❱ gcloud container clusters describe <cluster> --location <location> --format='value(networkConfig.subnetwork)'❱ gcloud compute networks subnets describe <subnet> --region <region> --format='value(ipCidrRange)' -
cluster.network.apiServer.sources: Leave at its default on public GKE clusters. Both GKE flavors set it to thekonnectivity-agentpods inkube-system, which deliver the API server’s admission webhook and aggregated API calls. -
cluster.network.podCidrandcluster.network.serviceCidr: Leave unset. Dataplane V2 never matchesipBlockrules against pod IPs and translates Service IPs before policy evaluation.
Workloads with a GKE cloud identity automatically receive outbound access to the node-local metadata server (169.254.169.254/32 on TCP ports 80 and 8080). Outbound world rules (0.0.0.0/0 and ::/0) always exclude link-local ranges (169.254.0.0/16 and fe80::/10), keeping the metadata server closed to pods without an identity.
Check widened-policy warnings
Section titled “Check widened-policy warnings”Because standard NetworkPolicy uses CIDR blocks for nodes and external traffic, some generated rules allow more traffic than intended. Kix marks affected policies with the kix.run/network-policy-widened annotation:
- When a
cluster.networksetting can narrow the rule (for example, settingcluster.network.nodeCidrsso outboundworldrules exclude cluster nodes),kix checkprints a warning naming that setting. - When the wider rule is a platform limit that no Kix setting can change (for example,
worldingress on aLoadBalancerService also accepting traffic from cluster nodes),kix checkhides it by default and lists it underkix check -v:
❱ kix check <cluster>❱ kix check <cluster> -v Kix applies NetworkPolicy objects before the workloads they select. Although Kubernetes NetworkPolicy has no readiness status for kix deploy to wait on, Dataplane V2 filters a new pod’s first packet with no startup gap.
Known limits and cleanup
Section titled “Known limits and cleanup”- Google Cloud Managed Service for Prometheus. Enabled by default on new GKE clusters, it reads
monitoring.googleapis.comcustom resources and ignores theServiceMonitorandPrometheusRuleresources generated bykix.monitor. Deploy the Kix monitoring stack when usingkix.monitor. - Containerd registry mirrors.
kix.flavors.gkesetscluster.containerd.registryConfigPath = "/etc/containerd/hosts.d"anddiscardUnpackedLayers = true. Default GKE nodes do not configure containerd to read/etc/containerd/hosts.dunless you enable it through GKE’s containerd configuration or a node startup script. - Default Service range. Since GKE 1.27, GKE’s default Service CIDR uses a Google-owned range outside RFC 1918 private space, so
cluster.network.serviceCidrdefaults tonull. - Removing Kix from the cluster. Kix has no single uninstall command. Delete cloud-side objects managed by controllers (Cloud DNS records, Velero backups, or
Certificateobjects created withkubectl) while their controllers still run. Then reduce your cluster definition to the flavor module and runkix deploy <cluster> --prune. Kix removes workloads, policies, and claims while keepingNamespaceandCustomResourceDefinitionobjects, itsActivationrecords, and the flavor’s import records inkube-system(orgke-managedon Autopilot). See Remove everything a Kix cluster deployed.
What has not been tested
Section titled “What has not been tested”Live GKE testing covered a zonal GKE Standard 1.36 cluster (Container-Optimized OS, Dataplane V2, and Workload Identity Federation) and a regional GKE Autopilot 1.36 cluster. These configurations have not been tested yet:
- Private GKE clusters (private control-plane endpoint) and clusters without Konnectivity: How the API server routes webhook calls on these clusters has not been tested, so the default
cluster.network.apiServer.sources(konnectivity-agentpods inkube-system) may not match. - Cloud DNS for GKE as cluster DNS: The
gkeandgke-autopilotflavors include the169.254.169.254/32and169.254.20.10/32DNS peer rules documented by Google, though replacingkube-dnswith Cloud DNS for GKE has not been tested under Dataplane V2 network policy. - Metadata server TCP port 8080: Kix opens TCP ports 80 and 8080 to
169.254.169.254/32based on Google’s documentation; only port 80 was observed in live tests. - GPU node pools (
cluster.capabilities.gpu = true). - Every cloud-identity package on Autopilot: Live cloud-identity tests covered
external-dns,cert-manager,external-secrets, andveleroon GKE Standard (in both direct and linked forms), andexternal-dnson GKE Autopilot.