Skip to content
Latchkey

How to Install a Pinned kubectl Version in GitHub Actions

Pinning kubectl with azure/setup-kubectl keeps the client within one minor of the cluster and makes deploy jobs reproducible across runs.

Add azure/setup-kubectl with an explicit version, then verify with kubectl version --client before deploying. This avoids version-skew warnings from a stale preinstalled client.

Steps

  • Add azure/setup-kubectl with a pinned version.
  • Run kubectl version --client to confirm the version.
  • Keep the client within one minor of the cluster server version.

Workflow

.github/workflows/deploy.yml
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: azure/setup-kubectl@v4
        with:
          version: v1.30.2
      - run: kubectl version --client
      - run: kubectl apply -f k8s/

Gotchas

  • Kubernetes supports a client at most one minor newer or older than the server; mind the skew policy.
  • GitHub runners ship a kubectl already, but its version drifts, so pin it for stable deploys.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →