Intro
Kubernetes relies on a container runtime to actually run containers on each node. The container runtime is a critical piece of infrastructure that directly affects the stability, performance, and security of your workloads. Over time, you may need to upgrade the runtime to a newer version to get bug fixes, security patches, and new features. In some cases, you may even decide to migrate from one runtime to another (for example, from Docker to containerd) due to deprecation or performance considerations.
This guide provides a practical, step-by-step approach to upgrading or migrating your Kubernetes container runtimes safely. It covers environment inventory, configuration changes, verification, failure recovery, and an operations checklist. We will use concrete commands and examples throughout, based on common runtimes like containerd and CRI-O, but the principles apply to any runtime that implements the Container Runtime Interface (CRI).
Upgrading a container runtime is not just a matter of installing new packages; it requires careful planning to avoid disrupting production workloads. We will discuss how to minimize risk through staging and rollout strategies, how to validate the new runtime before fully committing, and how to roll back if something goes wrong. By the end of this guide, you will have a clear, repeatable process for runtime changes in your Kubernetes clusters.
Version and Environment Inventory
Before you attempt an upgrade or migration, you need a complete picture of your current environment. This includes the Kubernetes version, the container runtime version, the node operating system, and the configuration of the kubelet and the runtime. This inventory will help you understand compatibility requirements and identify potential issues.
1.1 Identify Kubernetes and Runtime Versions
Start by listing all nodes and their kubelet versions:
kubectl get nodes -o wide
Expected output will show the Kubernetes version for each node, for example:
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
node-1 Ready <none> 10d v1.26.5 192.168.1.10 <none> Ubuntu 22.04.2 LTS 5.15.0-76-generic containerd://1.6.21
node-2 Ready <none> 10d v1.26.5 192.168.1.11 <none> Ubuntu 22.04.2 LTS 5.15.0-76-generic containerd://1.6.21
Note the container runtime column; in Kubernetes 1.24+, it typically shows the runtime and version. However, the exact format may vary. For detailed runtime information, you can query the kubelet's status on each node:
kubectl get --raw /api/v1/nodes/node-1/proxy/configz | jq
This returns the kubelet configuration, including the containerRuntime field. Alternatively, you can SSH into a node and run:
crictl version
Example output:
Version: 0.1.0
RuntimeName: containerd
RuntimeVersion: 1.6.21
RuntimeApiVersion: v1
Record these versions for each node. Also note the operating system and kernel version because runtime versions may have specific OS dependencies.
1.2 Check Runtime Configuration
The runtime configuration is typically stored in a file like /etc/containerd/config.toml for containerd or /etc/crio/crio.conf for CRI-O. Examine this file to understand current settings, such as the CRI plugin, CNI plugin paths, and storage drivers. For containerd, you can also use containerd config dump to see the effective configuration.
containerd config dump > current-containerd-config.toml
Keep a backup of the current configuration before making changes.
1.3 Validate Compatibility
Check the Kubernetes release notes for the supported container runtime versions. For example, Kubernetes v1.26 typically supports containerd v1.6.x and CRI-O v1.26.x. Upgrading to a runtime version that is not supported can cause compatibility issues.
Also, ensure that the kubelet is configured to use the CRI plugin. For containerd, this is usually enabled by default, but verify:
grep -A10 'plugins."io.containerd.grpc.v1.cri"' /etc/containerd/config.toml
If you are planning to migrate from Docker to containerd, note that Docker uses a shim (dockershim) that was removed in Kubernetes 1.24. Your cluster must already be on a CRI-compatible runtime or you will need to migrate.
1.4 Inventory of Workloads and Critical Nodes
Identify which nodes are critical (e.g., control plane nodes, nodes running stateful workloads) and which can tolerate disruption. Use labels or node lists to plan a rolling upgrade. Also consider any node selectors or taints that might affect scheduling during the upgrade.
1.5 Backup and Prerequisites
- Ensure you have a recent etcd backup if you are upgrading the control plane nodes (though runtime upgrade generally doesn't affect etcd).
- Verify that you have SSH access to nodes and sudo privileges.
- Ensure that the cluster is healthy:
kubectl get cs(deprecated) orkubectl get --raw='/readyz?verbose'. - Plan for sufficient capacity to drain nodes without impacting the overall workload.
Safe Configuration Path
Once you have the inventory, plan the upgrade or migration in a controlled manner. The general approach is to perform a rolling upgrade, node by node, with verification after each node. For a migration (changing runtime type), you may want to build a new node pool with the new runtime and migrate workloads, rather than trying to change the runtime in place on existing nodes. This is often safer and easier to roll back.
2.1 General Upgrade Strategy
- Upgrade one non-critical node first as a pilot. This validates the process and catches configuration issues early.
- Drain the node before changing the runtime. This ensures that no running pods are disrupted while the runtime is being replaced.
- Upgrade the runtime packages or configuration.
- Restart the runtime and kubelet, then uncordon the node.
- Monitor node health and pod behavior before moving to the next node.
For a migration that involves changing the runtime type (e.g., Docker to containerd), an in-place conversion is complex and error-prone. Instead, consider creating a new node group with the new runtime and using Kubernetes' built-in mechanisms to move workloads.
2.2 Example: Upgrading containerd on a Node
Assume we are upgrading containerd from 1.6.21 to 1.7.0 on an Ubuntu node. First, check the current status:
containerd --version
Then, update the package. The exact commands depend on your package manager. For apt:
sudo apt-get update
sudo apt-get install --only-upgrade containerd.io
After the upgrade, check the version again:
containerd --version
Expected output: containerd containerd.io 1.7.0 ...
Now, restart containerd:
sudo systemctl restart containerd
Verify that containerd is running:
sudo systemctl status containerd
Also restart the kubelet to ensure it reconnects to the runtime:
sudo systemctl restart kubelet
2.3 Configuration Changes for Migration
If you are changing runtime types, you may need to change the kubelet's --container-runtime-endpoint flag. This is typically set in the kubelet's configuration file (e.g., /var/lib/kubelet/config.yaml) or as a systemd drop-in. For containerd, the endpoint is usually unix:///run/containerd/containerd.sock. For CRI-O, it is unix:///run/crio/crio.sock. Modify the kubelet configuration accordingly and restart the kubelet.
For example, if migrating to CRI-O, install CRI-O packages, then update the kubelet configuration:
sudo sed -i 's|containerRuntimeEndpoint:.*|containerRuntimeEndpoint: "unix:///run/crio/crio.sock"|' /var/lib/kubelet/config.yaml
sudo systemctl restart kubelet
Important: Do not change the runtime on a node with running pods without draining first, as the pods will become orphaned and may fail.
2.4 Using Node Pools for Migration
If you are on a cloud provider, create a new node pool with the new runtime. Then, use kubectl cordon and kubectl drain on the old nodes to move pods to the new nodes. This approach minimizes downtime and allows easy rollback if issues arise. Once all workloads are on the new pool, decommission the old pool.
2.5 Pilot Approach
Always start with a pilot node. For example, pick a node running only a few non-critical pods. Drain it, upgrade, and then check that the pods rescheduled correctly and all probes pass. If successful, proceed to other nodes in batches. This is especially important for a migration because the new runtime may have subtle differences in how it handles certain container features.
Verification and Diagnostics
After upgrading or migrating a node, you must verify that the runtime is functioning correctly before moving on. This involves checking the runtime status, the node status in the cluster, and the behavior of running pods.
3.1 Node-Level Checks
Run the following commands on the upgraded node:
Check runtime version:
crictl version
Expected output shows the new version, for example, RuntimeVersion: 1.7.0.
Check runtime health:
sudo crictl info
This returns JSON with runtime information. Look for any error fields.
List running containers:
sudo crictl ps
This should list all containers managed by the runtime. If migration was successful, the containers from existing pods should be running (if not drained) or new containers for rescheduled pods.
Check kubelet status:
sudo systemctl status kubelet
Ensure it is active and no errors related to the runtime.
3.2 Cluster-Level Checks
From the control plane, check the node status:
kubectl get node node-1 -o wide
Expected output: Ready.
Inspect the node conditions:
kubectl describe node node-1 | grep -A5 Conditions
Ensure that RuntimeReady condition is True.
3.3 Pod-Level Checks
After uncordoning the node, verify that new pods can be scheduled and run. Create a test pod:
kubectl run runtime-test --image=nginx --restart=Never
Wait for it to be ready:
kubectl get pod runtime-test -o wide
Check the pod's logs to ensure the runtime is working:
kubectl logs runtime-test
If the pod fails to start, use kubectl describe pod runtime-test to see events that may indicate runtime issues.
3.4 Performance and Functionality Checks
Depending on your workloads, you may want to run additional checks:
- Test exec and logs: Ensure you can
kubectl execinto a pod and get logs. - Test restart policies: Delete a pod and ensure it gets recreated.
- Test resource limits: Run a pod with a CPU/memory limit and verify enforcement.
- Test image pulling: Use an image not present on the node to verify the runtime can pull images correctly.
For migration, also test features that may be runtime-specific, such as:
- Device plugins: If you use GPUs or other hardware, ensure the plugin works with the new runtime.
- Security contexts: Test
allowPrivilegeEscalation,readOnlyRootFilesystem, etc. - Networking: Verify that pod networking is functional (DNS resolution, cross-pod communication).
3.5 Monitoring and Logs
- Check the runtime logs: For containerd,
journalctl -u containerd -f; for CRI-O,journalctl -u crio -f. - Monitor node metrics such as CPU, memory, and disk usage to detect any leaks or abnormal behavior.
- Use Kubernetes events:
kubectl get events --all-namespaces --sort-by='.lastTimestamp'to see any warnings.
Common Pitfalls and How to Avoid Them
Even experienced engineers can stumble during runtime upgrades. Here are the most frequent mistakes and practical ways to prevent or recover from them.
4.1 Skipping the Pilot Node
Why it happens: Teams under time pressure may attempt to roll out the upgrade to all nodes at once. Consequence: A configuration error or incompatibility can take down the entire cluster simultaneously. How to avoid: Always perform a pilot upgrade on one non-critical node first. Wait at least 30 minutes and run thorough verification before proceeding. Appoint a single engineer (for example, the on-call platform engineer) as the accountable owner for the pilot decision, and review the outcome before batch upgrades.
4.2 Not Draining Nodes Properly
Why it happens: Operators may try to upgrade a node without draining, thinking the runtime restart is transparent. Consequence: Running pods get killed abruptly, potentially causing data loss for stateful applications or service downtime. How to avoid: Use kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data before touching the runtime. Ensure you have enough capacity elsewhere to reschedule the pods. The accountable owner for this step is the engineer executing the upgrade, but the cluster admin should verify capacity beforehand.
4.3 Ignoring Runtime Configuration Differences
Why it happens: A new runtime version may introduce changed default values (e.g., cgroup driver from cgroupfs to systemd). Consequence: Pods may fail to start with permission or resource errors. How to avoid: Diff the old and new configurations after upgrade. For containerd, compare containerd config dump outputs. Reconcile any incompatible settings with the kubelet configuration (--cgroup-driver=systemd is a common fix). If pods still fail, check runtime logs and kubelet logs.
4.4 Failing to Back Up Configuration Files
Why it happens: Configuration files are often managed by an external tool (Ansible, Puppet) and assumed to be reproducible. Consequence: If an upgrade corrupts the config or a rollback is needed, you may have no baseline to restore. How to avoid: Always back up /etc/containerd/config.toml, /etc/crio/crio.conf, and /var/lib/kubelet/config.yaml before changes. Store them in version control or a safe location. The engineer performing the upgrade owns this backup and should verify its integrity before restarting services.
4.5 Rushing the Rollout
Why it happens: Excitement to complete the upgrade or pressure to meet a maintenance window. Consequence: Issues that only appear under sustained load or after a period of time go undetected until they affect production. How to avoid: Roll out in small batches (e.g., 2-3 nodes at a time) and monitor for at least 24 hours between batches. Define a go/no-go decision point after each batch; a senior SRE or platform lead should be the accountable owner, and this decision should be revisited at a weekly operations review until the entire cluster is migrated.
Failure Modes and Recovery
Even with careful planning, upgrades and migrations can fail. Understanding common failure modes and having a rollback plan is essential.
5.1 Common Failure Modes
- Runtime fails to start after upgrade: This can be due to configuration incompatibility, missing dependencies, or a bug in the new version. Symptoms: node becomes
NotReady,kubectl describe nodeshowsRuntimeNotReady. - Pods fail to start or crash: The new runtime may have different default settings (e.g., seccomp profiles, cgroup driver). This can cause pods to fail with errors related to permissions or missing capabilities.
- Image pull failures: The new runtime may not be able to authenticate to the registry or may have a different snapshotter.
- Kubelet fails to connect to runtime: If the socket path changed or the runtime is not listening, the kubelet will report errors.
- Data corruption: Rare, but possible if the upgrade process incorrectly migrates container storage.
5.2 Rollback for an Upgrade
If you upgraded the runtime version and encounter issues, the simplest rollback is to downgrade to the previous version. On Debian/Ubuntu, you can install a specific version:
sudo apt-get install containerd.io=1.6.21-1
Then restart containerd and kubelet. Ensure that the configuration is compatible with the old version (some config parameters may have changed). If the configuration was modified during upgrade, restore from the backup you made earlier.
If the node is already drained, you can perform the rollback without impacting workloads. After rollback, uncordon the node and verify it becomes ready.
5.3 Rollback for a Migration
If you migrated to a different runtime (e.g., from containerd to CRI-O) and need to roll back, you have two options:
- Revert on the same node: This is only feasible if you kept the old runtime packages and configuration. You would reinstall the old runtime, restore the kubelet configuration, and restart services.
- Migrate back to the old node pool: If you used a new node pool, you can simply move workloads back to the old pool by cordoning and draining the new nodes and uncordoning the old ones, provided the old pool is still available. This is why keeping the old pool around temporarily is wise.
5.4 Recovery Steps After a Failed Upgrade
If the node is in a bad state, you may need to perform manual recovery:
- Cordon the node to prevent new pods from scheduling:
kubectl cordon node-1. - Drain the node if possible:
kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data. If drain fails because the node is not ready, you may need to force delete pods:kubectl delete pod --force --grace-period=0. - Repair the runtime: Fix the configuration or downgrade as above.
- Restart services and verify node readiness.
- Uncordon the node and monitor.
If the node cannot be recovered quickly, consider deleting the node from the cluster and adding a new one, especially in cloud environments where nodes are ephemeral.
5.5 Data Recovery for Stateful Workloads
If stateful pods were on the node and failed, ensure that their persistent volumes are intact. The runtime upgrade should not affect persistent storage, but if the container storage (e.g., overlay filesystems) is corrupted, the pods may lose their writable layer (but not the persistent volumes). In such cases, you can delete the pod and let it recreate, as the state should be in the volume. Always have backups for critical stateful applications.
Operations Checklist
Use this checklist to ensure a smooth and repeatable runtime upgrade or migration process. For each item, a single accountable owner is named (e.g., the engineer performing the upgrade or the platform lead), and the review frequency is specified.
6.1 Pre-Upgrade Checklist
- [ ] Inventory all nodes and their current runtime versions. (Owner: Platform Engineer, Jane Doe; review weekly before upgrade window)
- [ ] Verify Kubernetes version compatibility with target runtime version. (Owner: Platform Engineer, Jane Doe)
- [ ] Check for any known issues in the release notes of the target runtime. (Owner: Platform Engineer, Jane Doe)
- [ ] Ensure cluster health:
kubectl get nodesshows all Ready, no degraded conditions. (Owner: Cluster Admin, John Smith) - [ ] Backup runtime configuration files on each node. (Owner: Engineer performing upgrade, e.g., Alice Brown)
- [ ] Identify a pilot node and schedule a maintenance window if needed. (Owner: Platform Lead, Michael Chen; review at weekly ops meeting)
- [ ] For migration, prepare new node pool or have rollback plan. (Owner: Platform Lead, Michael Chen)
- [ ] Notify team members about the change window. (Owner: Platform Lead, Michael Chen)
6.2 During Upgrade Checklist
- [ ] Cordon the pilot node:
kubectl cordon node-1. (Owner: Engineer performing upgrade, Alice Brown) - [ ] Drain the node:
kubectl drain node-1 --ignore-daemonsets --delete-emptydir-data. (Owner: Engineer performing upgrade, Alice Brown) - [ ] Perform runtime upgrade commands. (Owner: Engineer performing upgrade, Alice Brown)
- [ ] Restart runtime and kubelet. (Owner: Engineer performing upgrade, Alice Brown)
- [ ] Uncordon the node:
kubectl uncordon node-1. (Owner: Engineer performing upgrade, Alice Brown) - [ ] Verify node is Ready and runtime version is updated. (Owner: Engineer performing upgrade, Alice Brown)
- [ ] Run a test pod and check logs, exec, and networking. (Owner: Engineer performing upgrade, Alice Brown)
- [ ] Monitor for at least 30 minutes before proceeding. (Owner: Engineer performing upgrade, Alice Brown; if issues, go/no-go decision by Platform Lead, Michael Chen)
- [ ] If successful, repeat for other nodes in small batches. (Owner: Engineer performing upgrade, Alice Brown)
- [ ] If failure, follow rollback procedures immediately. (Owner: Engineer performing upgrade, Alice Brown; notify Platform Lead, Michael Chen)
6.3 Post-Upgrade Checklist
- [ ] Verify all nodes show the new runtime version. (Owner: Platform Engineer, Jane Doe; run once after all nodes upgraded)
- [ ] Run cluster-wide tests (e.g.,
kubectl get pods --all-namespacesand check for errors). (Owner: Platform Engineer, Jane Doe) - [ ] Check application performance metrics for any regression. (Owner: Application SRE, David Lee; review at next daily standup and weekly performance review)
- [ ] Review logs for any runtime-related warnings. (Owner: Platform Engineer, Jane Doe)
- [ ] Update documentation and configuration management to reflect new runtime. (Owner: Platform Engineer, Jane Doe; review monthly)
- [ ] Monitor for 24-48 hours for any delayed issues. (Owner: On-call SRE, rotating; review at daily incident review)
6.4 Example Table: Runtime Upgrade Comparison
| Runtime | Current Version | Target Version | Supported Kubernetes | Notes |
|---|---|---|---|---|
| containerd | 1.6.21 | 1.7.0 | v1.24 - v1.27 | Fixes CVE-2023-...; improves performance |
| CRI-O | 1.26.1 | 1.26.2 | v1.26 | Bugfix for log rotation |
| Docker (dockershim) | 20.10.24 | N/A (migrate) | Not supported from 1.24 | Use containerd or CRI-O |
(Note: Version numbers are illustrative; always check official support matrix.)
Conclusion
Upgrading or migrating Kubernetes container runtimes is a critical maintenance task that, when done carefully, can improve security, performance, and reliability. This guide has walked through the essential steps: assessing your environment, planning a safe configuration path, performing the upgrade with a pilot approach, verifying the new runtime, and recovering from failures. By following the operations checklist and using the practical commands provided, you can reduce risk and ensure a smooth transition.
Remember that every cluster is unique, so adapt these steps to your specific environment and constraints. Always test in a non-production environment first if possible, and keep backups. Assign clear accountability for each step and review progress regularly. With a methodical approach, runtime upgrades become a routine part of your Kubernetes operations rather than a feared event.
For further learning, consult the official Kubernetes documentation and the documentation of your chosen runtime. Stay informed about new releases and security advisories to plan timely upgrades.