Kubernetes

Kubernetes integration in Polycrate CLI: central artifacts/secrets/kubeconfig.yml, automatic KUBECONFIG in action runs, debug pod, and context switching.

Polycrate integrates tightly with Kubernetes: central kubeconfig management, automatic instrumentation of kubectl, helm, and Ansible during action runs, and a fast in-cluster debug pod.

Central Kubeconfig

Lookup Order

Polycrate resolves the kubeconfig for a workspace in the following priority order:

  1. Workspace secrets (recommended): artifacts/secrets/kubeconfig.yml — automatically encrypted by polycrate workspace encrypt.
  2. Explicit path: kubeconfig.filename in workspace.poly.
  3. Workspace root: kubeconfig.yml in the root directory (legacy).
  4. Block artifacts: artifacts/blocks/<block>/kubeconfig.yml (legacy).
  5. Global kubeconfig: ~/.kube/config (fallback).

Recommended Structure

acme-production-1/
├── workspace.poly
├── artifacts/
│   └── secrets/
│       └── kubeconfig.yml     # encrypted as kubeconfig.yml.age
└── blocks/

Automatic KUBECONFIG in Action Runs

On every polycrate run <block> <action>, Polycrate injects the resolved kubeconfig via two environment variables:

Variable Read by
KUBECONFIG kubectl, helm, cilium, velero, and other CLI tools inside the container
K8S_AUTH_KUBECONFIG Ansible collection kubernetes.core (k8s, k8s_info, helm, …)

Inside the container, both variables point to /workspace/artifacts/secrets/kubeconfig.yml; with --local, they point to the corresponding local host path.

# install.yml — no explicit kubeconfig parameters needed
- name: "Deploy {{ block.name }}"
  hosts: localhost
  gather_facts: false
  tasks:
    - name: Ensure namespace exists
      kubernetes.core.k8s:
        state: present
        definition:
          apiVersion: v1
          kind: Namespace
          metadata:
            name: "{{ block.config.namespace }}"

Cluster Debugging with polycrate k8s debug

With polycrate k8s debug, you launch a temporary debug pod with the full Polycrate toolchain directly inside the target cluster:

# Start a debug pod in the default namespace (kube-system)
polycrate k8s debug

# Start a debug pod in a specific namespace
polycrate k8s debug -n default

# Target a specific workspace
polycrate k8s debug -w "$HOME/.polycrate/workspaces/acme/acme-production-1"

How it works:

  1. Creates the polycrate-admin ServiceAccount with a cluster-admin binding if needed.
  2. Launches a pod using the Polycrate image (kubectl, helm, cilium, dig, curl, psql, jq, yq).
  3. Attaches your terminal interactively to the pod shell.
  4. Automatically deletes the debug pod when you exit (exit).

Switching Local Kubeconfig Contexts (set-context)

For working directly with multiple contexts in your local ~/.kube/config, the CLI provides fast context selection:

# Interactive TUI for context selection
polycrate k8s set-context

# Set context directly
polycrate k8s set-context acme-production-1

# List without TUI
polycrate k8s set-context --no-tui

Platform and Cluster Integrations

If you run workloads on a Software Delivery Platform, the Cluster Integrations page documents the four customer-facing Kubernetes integrations (cert-manager, external-dns, endpoint monitoring annotations for Ingress/Gateway API, and S3Bucket resources).

See Also