TExcelTAD
Home › Kubernetes › Cluster Upgrades & Maintenance

Cluster Upgrades & Maintenance

Kubernetes ships a new minor version about three times a year, and each one gets patch releases for roughly 14 months. A cluster that isn't upgraded falls out of support within a little over a year, so upgrading is routine work, not a project. Managed Kubernetes introduced the basic rule (one minor version at a time, control plane first). This lesson covers the full version-skew policy, the order of operations for a self-managed (kubeadm) cluster, draining nodes without downtime, removed APIs, and the other recurring maintenance a cluster needs.

The version-skew policy

During an upgrade, components of different versions must work together for a while. The policy says how far apart they may be (N is the API server's minor version):

Component Allowed versions Why
kube-apiserver (HA) All instances within 1 minor of each other Instances are upgraded one by one
kube-controller-manager, kube-scheduler, cloud-controller-manager Not newer than the API server; N or N-1 They are clients of the API server
kubelet Not newer than the API server; down to N-3 Lets you upgrade the control plane several times before touching nodes
kube-proxy Not newer than the API server; down to N-3; within 3 of the kubelet on its node Same reason
kubectl N-1 to N+1 Keep it close to the cluster

"The API server" means the oldest API server when several versions are running. That is why the order is always: API servers first, then controller-manager and scheduler, then the nodes. This checker applies the whole table to a cluster inventory taken in the middle of an upgrade:

python · try it yourself
def minor(v):
    return int(v.split(".")[1])

def check(inv):
    problems = []
    apis = [minor(v) for v in inv["kube-apiserver"]]
    oldest, newest = min(apis), max(apis)
    if newest - oldest > 1:
        problems.append(f"apiservers span {newest - oldest} minors (max 1)")
    for comp in ["kube-controller-manager", "kube-scheduler"]:
        for v in inv[comp]:
            if minor(v) > oldest:
                problems.append(f"{comp} {v} is newer than the oldest apiserver 1.{oldest}")
            elif oldest - minor(v) > 1:
                problems.append(f"{comp} {v} is more than 1 minor behind")
    for node, (kubelet, proxy) in inv["nodes"].items():
        k, p = minor(kubelet), minor(proxy)
        if k > oldest:
            problems.append(f"{node}: kubelet {kubelet} newer than apiserver 1.{oldest}")
        elif oldest - k > 3:
            problems.append(f"{node}: kubelet {kubelet} is {oldest - k} minors behind (max 3)")
        if p > oldest or oldest - p > 3 or abs(p - k) > 3:
            problems.append(f"{node}: kube-proxy {proxy} out of range")
    kubectl = minor(inv["kubectl"])
    if abs(kubectl - newest) > 1:
        problems.append(f"kubectl {inv['kubectl']} is more than 1 minor from the apiserver")
    return problems or ["all components within the skew policy"]

mid_upgrade = {
    "kube-apiserver": ["1.34.1", "1.33.5", "1.33.5"],
    "kube-controller-manager": ["1.33.5"], "kube-scheduler": ["1.33.5"],
    "nodes": {"node-a": ("1.33.5", "1.33.5"), "node-b": ("1.31.9", "1.31.9")},
    "kubectl": "1.34.1",
}
too_eager = dict(mid_upgrade, **{"kube-controller-manager": ["1.34.1"],
                 "nodes": {"node-a": ("1.34.1", "1.34.1"), "node-b": ("1.29.15", "1.29.15")}})
for name, inv in [("mid-upgrade", mid_upgrade), ("too eager", too_eager)]:
    print(name)
    for p in check(inv):
        print("  -", p)
mid-upgrade
  - all components within the skew policy
too eager
  - kube-controller-manager 1.34.1 is newer than the oldest apiserver 1.33
  - node-a: kubelet 1.34.1 newer than apiserver 1.33
  - node-a: kube-proxy 1.34.1 out of range
  - node-b: kubelet 1.29.15 is 4 minors behind (max 3)
  - node-b: kube-proxy 1.29.15 out of range

The "too eager" cluster upgraded the controller-manager and a kubelet while two API servers were still on 1.33, and it has a node four minors behind: each of those is a configuration the Kubernetes project doesn't test.

Upgrading a kubeadm cluster

Before you start: read the release's changelog ("Urgent upgrade notes"), take an etcd snapshot, check removed APIs (below), and make sure your add-ons (CNI, CSI drivers, ingress/Gateway controller) support the new version. The Kubernetes package repositories at pkgs.k8s.io are per minor version, so point apt/dnf at the new minor first.

bash
# 1. first control-plane node
sudo apt-get install -y kubeadm='1.34.1-1.1'
sudo kubeadm upgrade plan
sudo kubeadm upgrade apply v1.34.1
# 2. the other control-plane nodes
sudo kubeadm upgrade node
# 3. every node (control plane, then workers), one or a few at a time
kubectl drain node-a --ignore-daemonsets --delete-emptydir-data
sudo apt-get install -y kubelet='1.34.1-1.1' kubectl='1.34.1-1.1'
sudo kubeadm upgrade node            # on workers: refreshes the kubelet config
sudo systemctl daemon-reload && sudo systemctl restart kubelet
kubectl uncordon node-a

Sample output of kubeadm upgrade plan (shortened):

text
[upgrade/versions] Cluster version: 1.33.5
[upgrade/versions] kubeadm version: v1.34.1
[upgrade/versions] Target version: v1.34.1

Components that must be upgraded manually after you have upgraded the control plane with 'kubeadm upgrade apply':
COMPONENT   NODE       CURRENT   TARGET
kubelet     cp-1       v1.33.5   v1.34.1
kubelet     worker-1   v1.33.5   v1.34.1

Upgrade to the latest stable version:
COMPONENT                 NODE   CURRENT    TARGET
kube-apiserver            cp-1   v1.33.5    v1.34.1
kube-controller-manager   cp-1   v1.33.5    v1.34.1
kube-scheduler            cp-1   v1.33.5    v1.34.1
kube-proxy                       1.33.5     v1.34.1
CoreDNS                          v1.12.0    v1.12.1
etcd                      cp-1   3.5.21-0   3.6.4-0

kubeadm upgrade apply also renews the control-plane certificates, which is one reason clusters that upgrade regularly never hit the one-year certificate expiry.

Draining nodes safely

kubectl drain cordons the node (no new Pods) and evicts its Pods through the Eviction API, which respects PodDisruptionBudgets. An eviction that would take a workload below its budget is refused (HTTP 429) and drain retries until replacements are ready elsewhere. Managed node pools do the same with "surge" upgrades: add a new node, drain an old one, repeat.

python · try it yourself
REPLICAS = {"api": 3, "web": 2, "db": 1}
PDB_MIN_AVAILABLE = {"api": 2, "web": 1, "db": 1}      # db: a budget that can never be met
pods = {"node-a": ["api", "web", "db"], "node-b": ["api", "web"], "node-c": ["api"]}

def ready(app):
    return sum(p == app for node in pods.values() for p in node)

def drain(node, max_rounds=4):
    log = []
    for rnd in range(1, max_rounds + 1):
        for app in list(pods[node]):
            if ready(app) - 1 < PDB_MIN_AVAILABLE[app]:
                continue                          # eviction refused (429), try later
            pods[node].remove(app)
            target = min((n for n in pods if n != node), key=lambda n: len(pods[n]))
            pods[target].append(app)              # the ReplicaSet recreates it elsewhere
            log.append(f"round {rnd}: evicted {app}, replacement ready on {target}")
        if not pods[node]:
            return log + [f"{node} drained"]
        log.append(f"round {rnd}: cannot evict {pods[node]}: would violate PodDisruptionBudget, retrying")
    return log + [f"{node} NOT drained after {max_rounds} rounds"]

for line in drain("node-a", max_rounds=3):
    print(line)
print("placement:", pods)
round 1: evicted api, replacement ready on node-c
round 1: evicted web, replacement ready on node-b
round 1: cannot evict ['db']: would violate PodDisruptionBudget, retrying
round 2: cannot evict ['db']: would violate PodDisruptionBudget, retrying
round 3: cannot evict ['db']: would violate PodDisruptionBudget, retrying
node-a NOT drained after 3 rounds
placement: {'node-a': ['db'], 'node-b': ['api', 'web', 'web'], 'node-c': ['api', 'api']}

A single-replica workload with minAvailable: 1 blocks every drain of its node forever. Either run at least two replicas, or use maxUnavailable: 1 for workloads that can tolerate a short gap.

Removed APIs

Beta APIs are removed some releases after their stable replacement arrives, and manifests (or Helm charts) that still use them fail to apply after the upgrade. Objects already stored are converted automatically, but your Git repository is not. Scan before upgrading:

python · try it yourself
REMOVED = {  # (apiVersion, kind): (removed in, replacement)
    ("extensions/v1beta1", "Ingress"): (22, "networking.k8s.io/v1"),
    ("networking.k8s.io/v1beta1", "Ingress"): (22, "networking.k8s.io/v1"),
    ("batch/v1beta1", "CronJob"): (25, "batch/v1"),
    ("policy/v1beta1", "PodDisruptionBudget"): (25, "policy/v1"),
    ("policy/v1beta1", "PodSecurityPolicy"): (25, "Pod Security Admission"),
    ("autoscaling/v2beta2", "HorizontalPodAutoscaler"): (26, "autoscaling/v2"),
    ("storage.k8s.io/v1beta1", "CSIStorageCapacity"): (27, "storage.k8s.io/v1"),
    ("flowcontrol.apiserver.k8s.io/v1beta2", "FlowSchema"): (29, "flowcontrol.apiserver.k8s.io/v1"),
    ("flowcontrol.apiserver.k8s.io/v1beta3", "FlowSchema"): (32, "flowcontrol.apiserver.k8s.io/v1"),
}
manifests = [
    ("charts/legacy/cron.yaml", "batch/v1beta1", "CronJob"),
    ("apps/api/hpa.yaml", "autoscaling/v2", "HorizontalPodAutoscaler"),
    ("platform/apf.yaml", "flowcontrol.apiserver.k8s.io/v1beta3", "FlowSchema"),
    ("apps/web/ingress.yaml", "networking.k8s.io/v1", "Ingress"),
]

def scan(current, target):
    print(f"upgrade 1.{current} -> 1.{target}")
    for path, api, kind in manifests:
        hit = REMOVED.get((api, kind))
        if hit and hit[0] <= target:
            when = "ALREADY BROKEN" if hit[0] <= current else f"removed in 1.{hit[0]}"
            print(f"  {path:26} {kind} {api}: {when}, use {hit[1]}")

scan(31, 32)
scan(24, 26)
upgrade 1.31 -> 1.32
  charts/legacy/cron.yaml    CronJob batch/v1beta1: ALREADY BROKEN, use batch/v1
  platform/apf.yaml          FlowSchema flowcontrol.apiserver.k8s.io/v1beta3: removed in 1.32, use flowcontrol.apiserver.k8s.io/v1
upgrade 1.24 -> 1.26
  charts/legacy/cron.yaml    CronJob batch/v1beta1: removed in 1.25, use batch/v1

"ALREADY BROKEN" means the file can't be applied even to the current cluster: a sign that nobody has deployed that chart for a long time. In practice, use pluto or kubent against your repo and the live cluster, and watch the API server's apiserver_requested_deprecated_apis metric, which shows which deprecated APIs clients still call.

Routine maintenance

Task How often Tooling
Minor upgrade 2–3× a year kubeadm / provider console / Terraform
Patch upgrade Monthly Same, low risk
etcd snapshot Daily + before every upgrade etcdctl snapshot save, Velero for objects + volumes
Certificates Check quarterly (kubeadm certs last 1 year) kubeadm certs check-expiration, kubeadm certs renew
Node OS patches and reboots Weekly/monthly kured reboots nodes one at a time with drain
Add-on upgrades (CNI, CoreDNS, Gateway controller, cert-manager) With each minor Helm / GitOps
text
$ sudo kubeadm certs check-expiration
CERTIFICATE                EXPIRES                  RESIDUAL TIME   CERTIFICATE AUTHORITY   EXTERNALLY MANAGED
admin.conf                 Mar 02, 2027 09:14 UTC   135d            ca                      no
apiserver                  Mar 02, 2027 09:14 UTC   135d            ca                      no
apiserver-kubelet-client   Mar 02, 2027 09:14 UTC   135d            ca                      no
...
CERTIFICATE AUTHORITY   EXPIRES                  RESIDUAL TIME   EXTERNALLY MANAGED
ca                      Feb 28, 2035 09:14 UTC   8y              no

Tip: If every cluster is built from code and filled by GitOps, consider blue/green clusters for big jumps: build a new cluster on the target version, sync the same Git repository into it, and shift traffic gradually with the techniques from Multi-Cluster Kubernetes. Rolling back is just moving traffic back.

Learn more: Managed Kubernetes · Troubleshooting · Cluster Architecture

Test yourself

The API server runs 1.34. Which kubelet version is NOT allowed?

  1. 1.34
  2. 1.32
  3. 1.31
  4. 1.35

In which order do you upgrade a cluster?

  1. Nodes first, then the control plane
  2. API servers, then controller-manager and scheduler, then kubelets
  3. All components at the same time
  4. kubectl first

kubectl drain keeps retrying with 'Cannot evict pod as it would violate the pod's disruption budget'. What is the likely cause?

  1. The node is out of disk
  2. A PodDisruptionBudget whose minAvailable equals the replica count (e.g. 1 replica, minAvailable 1)
  3. kubectl is too old
  4. A NetworkPolicy blocks the eviction