Skip to content
Install the CLI

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.)

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 managed metrics-server (metricsApi role, exclusive).
  • GKE Dataplane V2 (cni and network-policy-enforcer roles, exclusive).
  • Cluster DNS (kube-dns in kube-system), GCP Network Load Balancers for LoadBalancer Services, and the Persistent Disk CSI driver with standard-rwo as the default StorageClass.
  • 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.

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 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:

clusters/gke.nix
{ kix, packages }:
kix.buildCluster {
specialArgs = { inherit kix packages; };
modules = [
kix.flavors.gke # or kix.flavors.gke-autopilot
{
cluster.kubernetes.uid = "4d7b1c2e-9f3a-4b8e-a1c5-6d2e8f0a9b3c";
}
];
}

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>

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 in kube-system. The gke-autopilot flavor places its platform import records in the gke-managed namespace (which Kix creates) and writes nothing to kube-system. If your cluster declares _-prefixed instances such as instances._cluster, change cluster.recordNamespace from its kube-system default to an existing user namespace.
  • Baseline Pod Security and host restrictions. GKE’s admission webhook enforces the baseline Pod Security Standard and blocks privileged containers, host namespaces such as hostNetwork, and writable hostPath volumes. The flavor sets privilegedContainers = false and podSecurityEnforcement = "baseline", so kix check rejects hostNetwork and privileged workloads before deploy.
  • No critical PriorityClasses. GKE allows system-node-critical and system-cluster-critical only in namespaces that have a matching ResourceQuota. On GKE Standard, kube-system has that quota, so kix.flavors.gke sets criticalPriorityNamespaces = [ "kube-system" ] and fails with [K7426] in other namespaces. Because Autopilot also blocks user workloads in kube-system, gke-autopilot sets criticalPriorityNamespaces = [ ] 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-autopilot binds loadBalancer as exclusive rather than shadowable, 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 32Mi memory request to 52Mi) and adds an ephemeral-storage request on the Deployment object. After deployment, kix plan shows no differences, while kix plan --reconcile lists 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”
  1. Declare the identity in Kix. Pass kix.cloudIdentity.gcp { } to external-dns. In this snippet, the local externalDns helper sets provider = "google", policy = "upsert-only", txtOwnerId, and extraArgs ("--google-project=my-project" and "--domain-filter=example.com"):

    clusters/test-cloud-identity-gke.nix
    instances.external-dns.clouddns = {
    package = packages.experimental.external-dns;
    deps.providerCredentials = kix.cloudIdentity.gcp { };
    config = externalDns "cloud-identity-gke/direct";
    };

    View source on GitHub ↗

    Kix omits iam.gke.io/gcp-service-account on the clouddns ServiceAccount because Google Cloud grants roles directly to the Kubernetes ServiceAccount’s principal.

  2. 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>"] in subjectPlaceholders.

  3. Bind the Google Cloud IAM role. Look up your project number, replace <project-id> (my-project) and <project-number> (123456789012) in the Subject string, 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
  4. Deploy and confirm. Apply the cluster and check the controller log:

    ❱ kix deploy <cluster>
    ❱ kubectl logs -n external-dns deploy/clouddns

    Once the IAM binding propagates, external-dns logs DNS records being created. You can also confirm the active identity from inside the pod by querying the GKE metadata server (use kubectl debug -n external-dns <pod> --image=<image-with-curl> for an ephemeral container if the workload image lacks curl):

    ❱ curl -H 'Metadata-Flavor: Google' http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/email

    For a direct IAM grant, the metadata server answers my-project.svc.id.goog.

  1. Declare the Google service account in Kix. Pass serviceAccount in kix.cloudIdentity.gcp:

    clusters/test-cloud-identity-gke.nix
    instances.external-dns-linked.clouddns = {
    package = packages.experimental.external-dns;
    deps.providerCredentials = kix.cloudIdentity.gcp {
    serviceAccount = "[email protected]";
    };
    config = externalDns "cloud-identity-gke/linked";
    };

    View source on GitHub ↗

    Kix writes iam.gke.io/gcp-service-account: [email protected] on the clouddns ServiceAccount.

  2. Inspect the required IAM member. Run kix list resources <cluster> to get the roles/iam.workloadIdentityUser member 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>"] in subjectPlaceholders.

  3. 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 grant roles/iam.workloadIdentityUser on that Google service account to the Subject member 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]'
  4. Deploy and confirm. Apply the cluster and check the controller log:

    ❱ kix deploy <cluster>
    ❱ kubectl logs -n external-dns-linked deploy/clouddns

    Querying http://169.254.169.254/computeMetadata/v1/instance/service-accounts/default/email with -H 'Metadata-Flavor: Google' from inside the pod returns [email protected], and the clouddns log 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):

clusters/test-cloud-identity-velero-gke.nix
velero = {
package = packages.experimental.velero;
# One server: Velero has no leader election.
availability = "none";
deps.cloudCredentials = kix.cloudIdentity.gcp {
serviceAccount = "[email protected]";
};
config = {
awsPlugin.enabled = false;
extraPlugins.velero-plugin-for-gcp = {
repository = "docker.io/velero/velero-plugin-for-gcp";
tag = "v1.14.4";
};
backupStorageLocation = {
provider = "velero.io/gcp";
objectStorage.bucket = "cloud-identity-velero-gke";
# The account the plugin signs download URLs as.
config.serviceAccount = "[email protected]";
};
};
};

View source on GitHub ↗

  • No deploy-time pod check on GKE. GKE injects no identity environment variables into containers, so kix deploy cannot check whether a pod received its identity and never raises CloudIdentityNotApplied on GKE. A workload with missing or broken IAM bindings deploys cleanly and reports ok in kix 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.workloadIdentityUser on the Google service account (linked form): the Kubernetes ServiceAccount cannot impersonate the Google service account, and pods log Permission '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.
  • Host-network pods refused at kix check ([K2669]). Workload Identity Federation for GKE does not grant cloud identities to pods with hostNetwork: 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 check rejects it with [K2669]:

    <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-identity onto 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.

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: Set provider = "google" and pass "--google-project=my-project" in extraArgs. Packaged external-dns 0.24 reads external-dns.kubernetes.io/hostname and ignores the older external-dns.alpha.kubernetes.io/hostname annotation unless you add "--enable-legacy-annotation-prefix" to extraArgs. See Publish DNS records with external-dns.
  • cert-manager DNS-01: Set deps.controllerIdentity on cert-manager and omit serviceAccountSecretRef on the dns01.cloudDNS solver. Use a real address for the ACME account email (Let’s Encrypt rejects example.com), and set hostedZoneName on the cloudDNS solver if cert-manager cannot locate your zone by SOA lookup. See Configure cert-manager issuers.

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.

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.

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:

clusters/test-netpol-gke.nix
networkPolicy.enable = true;
cluster.network = {
apiServer.cidrs = [ "10.0.0.2/32" ];
nodeCidrs = [ "10.128.0.0/20" ];
};

View source on GitHub ↗

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 a Role or ClusterRole. Dataplane V2 evaluates ipBlock rules after Service address translation, so the kubernetes Service ClusterIP never matches; set the API server’s endpoint /32 addresses instead. Look them up with:

    ❱ kubectl get endpointslices -n default -l kubernetes.io/service-name=kubernetes -o jsonpath='{.items[*].endpoints[*].addresses[*]}'

    Append /32 to 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 deploy succeeds 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 scraping node-exporter on the host network). Kix also excludes this range from outbound world rules 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 the konnectivity-agent pods in kube-system, which deliver the API server’s admission webhook and aggregated API calls.

  • cluster.network.podCidr and cluster.network.serviceCidr: Leave unset. Dataplane V2 never matches ipBlock rules 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.

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.network setting can narrow the rule (for example, setting cluster.network.nodeCidrs so outbound world rules exclude cluster nodes), kix check prints a warning naming that setting.
  • When the wider rule is a platform limit that no Kix setting can change (for example, world ingress on a LoadBalancer Service also accepting traffic from cluster nodes), kix check hides it by default and lists it under kix 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.

  • Google Cloud Managed Service for Prometheus. Enabled by default on new GKE clusters, it reads monitoring.googleapis.com custom resources and ignores the ServiceMonitor and PrometheusRule resources generated by kix.monitor. Deploy the Kix monitoring stack when using kix.monitor.
  • Containerd registry mirrors. kix.flavors.gke sets cluster.containerd.registryConfigPath = "/etc/containerd/hosts.d" and discardUnpackedLayers = true. Default GKE nodes do not configure containerd to read /etc/containerd/hosts.d unless 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.serviceCidr defaults to null.
  • Removing Kix from the cluster. Kix has no single uninstall command. Delete cloud-side objects managed by controllers (Cloud DNS records, Velero backups, or Certificate objects created with kubectl) while their controllers still run. Then reduce your cluster definition to the flavor module and run kix deploy <cluster> --prune. Kix removes workloads, policies, and claims while keeping Namespace and CustomResourceDefinition objects, its Activation records, and the flavor’s import records in kube-system (or gke-managed on Autopilot). See Remove everything a Kix cluster deployed.

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-agent pods in kube-system) may not match.
  • Cloud DNS for GKE as cluster DNS: The gke and gke-autopilot flavors include the 169.254.169.254/32 and 169.254.20.10/32 DNS peer rules documented by Google, though replacing kube-dns with 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/32 based 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, and velero on GKE Standard (in both direct and linked forms), and external-dns on GKE Autopilot.