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-kubectlwith a pinnedversion. - Run
kubectl version --clientto 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
How to Authenticate to a Kubernetes Cluster From CI With a Kubeconfig SecretAuthenticate kubectl to any Kubernetes cluster from GitHub Actions by storing a base64 kubeconfig as a secret…
How to Wait for a Rollout to Finish From CI in GitHub ActionsMake a GitHub Actions deploy fail loudly when pods do not become ready by running kubectl rollout status with…