Skip to main content

Rotate AKS Cluster Certificates Before They Expire Without Losing kubectl Access

AKS kubectl failing with x509 unknown authority? Check CA expiry, run az aks rotate-certs in a window and refresh every kubeconfig with get-credentials.

KBY Technologies11 min readTier L115 min
Rotate AKS Cluster Certificates Before They Expire Without Losing kubectl Access

Advertising disclosure: this article includes partner links. KBY may earn a commission if you sign up or buy through one, at no extra cost to you. How we make money.

Underlined words are defined in the KBY Lexicon. Tap or click one to see what it means.

To keep kubectl working through an AKS certificate change, check when your cluster CA expires, then run az aks rotate-certs in a planned window and immediately refresh every kubeconfig with az aks get-credentials --overwrite-existing. The key constraint is that the rotation recreates all of the cluster’s nodes, virtual machine scale sets and disks, and Microsoft says this can mean up to 30 minutes of downtime. Anything still holding the old CA then fails with:

1Unable to connect to the server: x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "ca")

Most certificates in AKS look after themselves. The cluster CA and your kubectl client certificates do not, and they are the two that lock people out.

#The usual workaround is waiting for the x509 error

On many teams, nobody owns the AKS cluster CA. The cluster was built years ago, kubectl works, and certificates only come up when a pipeline or an engineer suddenly gets the error above. At that point someone runs a rotation under pressure, outside a change window, and then spends the next hour working out which build agents, dashboards and laptops still have the old kubeconfig.

Microsoft splits AKS certificates into three groups, and knowing which is which removes most of the guesswork:

  • Rotated for you. On clusters with RBAC enabled, node client and serving certificates rotate automatically. Kubelet serving certificate rotation is on by default for new node pools on Kubernetes 1.27 or later, and existing pools get it after their first upgrade to 1.27 or later.
  • Refreshed when you rotate the CA. Service account tokens, the server certificate, kubelet client certificates and, where serving rotation is on, kubelet serving certificates.
  • Yours to rotate. The cluster CA, with az aks rotate-certs, and the kubectl client certificates, with az aks get-credentials after the CA has changed.

The CA lifetime depends on the cluster’s age. AKS clusters created before May 2019 have cluster CA certificates that expire after two years; clusters created after May 2019 get 30 years. So for a cluster that old, check the date now. For newer clusters the rotation is something you schedule for policy reasons, such as a rule that every certificate is replaced on a fixed cycle or after a suspected key exposure. AKS does not manage any certificate you created for your own workloads, so ingress and application certificates stay out of this process.

#A better workflow that checks first and refreshes clients straight away

The improved method treats a CA rotation as a planned change with three phases. First, read the expiry dates without touching anything. Second, rotate during an agreed window, because the nodes are rebuilt. Third, refresh every client that talks to the API server in the same window, from a list you prepared beforehand, rather than waiting for each one to fail.

Rendering diagram...

Each phase produces evidence you can attach to the change record: the old and new validity dates, the rotation start and end times, and the output of kubectl get nodes from each refreshed client. The trade-off is that you accept a short, announced outage of the control plane connection and a rebuild of the nodes, instead of an unplanned one later.

#Rolling it out on one cluster

Do this first on a non-production cluster created the same way as production. You need Azure CLI 2.0.77 or later (az --version shows it), rights to read and update the managed cluster, and access to the kubeconfig used by every pipeline that deploys to it.

  1. Read the CA expiry. Replace the name with the cluster entry in your kubeconfig:
    1kubectl config view --raw -o jsonpath="{.clusters[?(@.name == '<cluster-name>')].cluster.certificate-authority-data}" | base64 -d | openssl x509 -text | grep -A2 Validity

    You will see Not Before and Not After lines. Record both.

  2. Read the API server certificate expiry.
    1curl https://{apiserver-fqdn} -k -v 2>&1 | grep expire

    The -k flag only skips verification for this read; it does not change anything.

  3. Read a node’s kubelet client certificate. This runs a read-only openssl command on one instance of the node pool’s scale set:
    1az vmss run-command invoke \
    2  --resource-group <node-resource-group> \
    3  --name <vmss-name> \
    4  --command-id RunShellScript \
    5  --instance-id 1 \
    6  --scripts "openssl x509 -in /var/lib/kubelet/pki/kubelet-client-current.pem -noout -enddate" \
    7  --query "value[0].message"

    The output includes a notAfter= date.

  4. Decide. If the cluster predates May 2019, or your policy requires a new CA, book a window. Stop here if you can’t name every system that holds a kubeconfig for this cluster.
  5. Back up client configuration. Copy each kubeconfig you will refresh, for example cp ~/.kube/config ~/.kube/config.pre-rotation, and export any kubeconfig stored as a pipeline secret.
  6. Rotate, inside the window.
    1az aks get-credentials --resource-group <resource-group> --name <cluster-name>
    2az aks rotate-certs --resource-group <resource-group> --name <cluster-name>

    The CLI reference states that Kubernetes will be unavailable during the rotation, and the command asks for confirmation unless you pass --yes. Don’t add --yes or --no-wait on the first run: you want the prompt and you want to see the command finish. Stop condition: if the command returns an error, go to the recovery section before doing anything else.

  7. Confirm the old credentials are dead. Run kubectl get nodes. The x509 error shown at the top is the expected result here: it proves the CA changed.
  8. Refresh kubectl.
    1az aks get-credentials --resource-group <resource-group> --name <cluster-name> --overwrite-existing
    2kubectl get nodes

    The node list should come back with every node Ready. Repeat the refresh for each pipeline and each administrator on your list. For a pipeline secret, --file - prints the new kubeconfig as to stdout so you can update the secret without touching a local file.

Close-up of love padlocks clinging to a bridge in Wrocław, symbolizing romantic bonds.
Photo by Adrian Jozefowicz on Pexels

#Who can run a rotation and who can change kubeconfig

Because the rotation rebuilds the nodes and interrupts API access, it should sit with the same small group that can upgrade the cluster. As a recommendation, grant update rights on the managed cluster resource through Azure RBAC to that group only, and require a change record for every az aks rotate-certs run.

Treat az aks get-credentials --admin as a break-glass route. It returns cluster administrator credentials and needs the Azure Kubernetes Service Cluster Admin role; on clusters with Microsoft Entra ID integration it bypasses normal Entra authentication. Use it only if the normal user credentials fail after the rotation, and record when it was used. While you are reviewing who can reach the API server, check that your role bindings are still what you think they are; aggregated ClusterRole labels can grant RBAC permissions nobody reviewed.

There is one dated change to plan for. From 30 November 2026, AKS requires a dedicated Azure RBAC DataAction to authorise kubelet client certificate issuance. If you use a custom Azure role for external node bootstrap or kubelet client certificate renewal, update it before then, or external nodes may fail to join or renew. AKS-managed nodes are not expected to be affected.

#Prove the nodes and every client trust the new CA

Run these checks after the refresh, from a client you have just updated:

  • Repeat the CA expiry command. The Not Before date should be the rotation date and the Not After date should differ from the value you recorded.
  • kubectl get nodes returns every node as Ready.
  • kubectl get nodes -L kubernetes.azure.com/kubelet-serving-ca shows cluster in the label column for nodes with kubelet serving certificate rotation enabled.
  • kubectl get csr --field-selector=spec.signerName=kubernetes.io/kubelet-serving lists serving requests in the Approved,Issued state. The upstream Kubernetes signer kubernetes.io/kubelet-serving is never auto-approved by kube-controller-manager, so an issued request shows the cluster’s approval path worked.
  • Each pipeline on your list completes a harmless read, such as listing namespaces, using its refreshed kubeconfig.

Microsoft also notes that services running on top of AKS may need their own certificates updated. As a precaution, list anything that keeps its own copy of the cluster CA outside the cluster, such as a monitoring tool or deployment server, and refresh it in the same window.

#Where it goes wrong after a rotation

A pipeline fails hours later with the x509 error. Cause: its kubeconfig was not on the list. Diagnosis: the error names the unknown authority, and the pipeline’s stored kubeconfig contains the old certificate-authority-data. Fix: refresh it with az aks get-credentials --file - and update the secret. Then add the pipeline to the inventory.

Pods restart in unexpected places. Cause: every node was rebuilt. Workloads that kept state on a node’s local disk lose it, and applications without enough replicas go down while their nodes are replaced. Diagnosis: pod events and restarts during the window. Fix: this is why the window exists. If a workload then sits in CrashLoopBackOff after the nodes come back, read its logs before changing anything.

Images fail to pull on the new nodes. Fresh nodes pull images again. If a registry credential or network rule was only ever satisfied by a cached image, you will see ImagePullBackOff on the rebuilt nodes. Fix the pull path rather than the certificates.

Someone reaches for the admin credential and leaves it in place. The admin kubeconfig fixes the immediate access problem and then stays on a laptop. Remove it once normal credentials work.

A patterned array of industrial shipping containers stacked in a storage terminal.
Photo by Jan van der Wolf on Pexels

#Recover access when the rotation stalls or kubectl breaks

A CA rotation cannot be undone: once the new CA is issued, the old kubeconfigs will not work again, and the backups you took are only for reference and for restoring other contexts in the same file. Recovery means finishing the rotation and refreshing clients.

  1. If az aks rotate-certs fails before completing, run az aks show --resource-group <resource-group> --name <cluster-name> and read the cluster status. Microsoft documents that it shows Certificate Rotating while the operation is still in progress.
  2. If the cluster is in a failed state, rerun az aks rotate-certs for the same cluster.
  3. Once it completes, refresh kubectl with --overwrite-existing and run the proof checks again.
  4. If a refreshed kubeconfig has lost other contexts you needed, restore them from ~/.kube/config.pre-rotation, keeping the new entry for this cluster.
  5. If the rotation keeps failing, stop and raise a support case with Microsoft rather than trying workarounds on the nodes.

#What to track across your AKS clusters

Start with a baseline: for each cluster, its creation date, the CA Not After date and the date of the last rotation. Track:

  • the number of days to CA expiry, with a threshold that triggers planning (for example, the same notice period you use for other platform certificates);
  • the time from the start of az aks rotate-certs to the last client refreshed, which should fall with each run;
  • the count of x509 errors reported after the window closes, which should reach zero once the kubeconfig inventory is complete.

Review the inventory every quarter. If any cluster shows an x509 incident that was not caused by a planned rotation, treat it as an inventory gap rather than a one-off.

#Before you roll the CA on a production cluster

  1. The CA, API server and kubelet expiry dates are recorded.
  2. The same procedure has run on a non-production cluster built the same way.
  3. Every pipeline, dashboard and administrator holding a kubeconfig for the cluster is listed, with an owner.
  4. Kubeconfig files and pipeline secrets are backed up.
  5. Application owners know the nodes will be rebuilt and API access will drop for up to 30 minutes.
  6. Custom Azure roles used for kubelet client certificate issuance have been updated for the 30 November 2026 change.
  7. The person running the change can open a Microsoft support case if the rotation keeps failing.

If any item is not true, hold the rotation and fix that item first; for clusters created after May 2019, the CA itself gives you time to do it properly.

About this page

Credited to

Dates

Published

Sources

This page lists no external sources.

Corrections

No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.

Reader Interaction

Comments

Add a thoughtful note on Rotate AKS Cluster Certificates Before They Expire Without Losing kubectl Access. Comments are checked for spam and held for moderation before appearing.

Loading comments...

Discover more

Was this useful?

Reports go to the site owner and are used to correct pages. Corrections are listed at /corrections.

Operate smarter, with fewer recurring tickets.

Receive new operational playbooks, incident-prevention guidance, automation scripts and recovery runbooks.