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.

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 Kubernetes 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 API 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, withaz aks get-credentialsafter 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.
- 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 ValidityYou will see
Not BeforeandNot Afterlines. Record both. - Read the API server certificate expiry.
1curl https://{apiserver-fqdn} -k -v 2>&1 | grep expireThe
-kflag only skips verification for this read; it does not change anything. - Read a node’s kubelet client certificate. This runs a read-only
opensslcommand 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. - 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.
- 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. - 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--yesor--no-waiton 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. - 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. - Refresh kubectl.
1az aks get-credentials --resource-group <resource-group> --name <cluster-name> --overwrite-existing 2kubectl get nodesThe 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 YAML to stdout so you can update the secret without touching a local file.

#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 Beforedate should be the rotation date and theNot Afterdate should differ from the value you recorded. kubectl get nodesreturns every node asReady.kubectl get nodes -L kubernetes.azure.com/kubelet-serving-cashowsclusterin the label column for nodes with kubelet serving certificate rotation enabled.kubectl get csr --field-selector=spec.signerName=kubernetes.io/kubelet-servinglists serving requests in theApproved,Issuedstate. The upstream Kubernetes signerkubernetes.io/kubelet-servingis 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.

#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.
- If
az aks rotate-certsfails before completing, runaz 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. - If the cluster is in a failed state, rerun
az aks rotate-certsfor the same cluster. - Once it completes, refresh kubectl with
--overwrite-existingand run the proof checks again. - If a refreshed kubeconfig has lost other contexts you needed, restore them from
~/.kube/config.pre-rotation, keeping the new entry for this cluster. - 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-certsto 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
- The CA, API server and kubelet expiry dates are recorded.
- The same procedure has run on a non-production cluster built the same way.
- Every pipeline, dashboard and administrator holding a kubeconfig for the cluster is listed, with an owner.
- Kubeconfig files and pipeline secrets are backed up.
- Application owners know the nodes will be rebuilt and API access will drop for up to 30 minutes.
- Custom Azure roles used for kubelet client certificate issuance have been updated for the 30 November 2026 change.
- 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
Corrections
No corrections are listed for this page. Some review sweeps corrected pages without naming each one; those are in the corrections log.
Related articles
Multi-Cloud & Cross-Cloud Architectures
AWS Site-to-Site VPN Tunnel Down After BGP Flap to Azure: Fix
Fix an AWS Site-to-Site VPN tunnel to Azure that is down or flapping: check IKE phase 1/2 and BGP on both sides, change one setting at a time, and roll back safely.
ReadZero-Touch & Automation
Killing Expired Certificate Auth Failures with Auto-Renewal Hooks
Expired client certificates silently break VPN and Wi-Fi auth fleet-wide; this pipeline auto-renews and alerts before expiry causes an outage.
ReadArtificial Intelligence
India’s CERT-In Says Attackers Are Changing Payment Approval Records Instead of Breaking Payment Systems, and Agentic Attack Tools Are Doing the Reconnaissance
CERT-In says attackers change payee and approval records so payments pass every check, and agentic attack tools run the reconnaissance. The controls that stop it.
ReadSecurity
N-able’s Mail Assure Outage Was a Cyberattack on One Server, and Partners Lost Portal and API Access for Days
N-able says hackers reached one server behind Mail Assure and SpamExperts, and the outage first blamed on configuration was a security incident. Mail kept flowing; the portal and API did not. What partners and their customers should check.
ReadDiscover more
Graduate Learning
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.
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.