You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
4.0 KiB

  1. # Migrating from Docker to Containerd
  2. ❗MAKE SURE YOU READ BEFORE PROCEEDING❗
  3. **Migrating container engines is not officially supported by Kubespray**. The following procedure covers one particular scenario and involves manual steps, along with multiple runs of `cluster.yml`. It provides no guarantees that it will actually work or that any further action is needed. Please, consider these instructions as experimental guidelines. While they can be used to migrate your cluster, they will likely evolve over time. At the moment, they are intended as an additional resource to provide insight into how these steps can be officially integrated into the Kubespray playbooks.
  4. As of Kubespray 2.18.0, containerd is already the default container engine. If you have the chance, it is still advisable and safer to reset and redeploy the entire cluster with a new container engine.
  5. Input and feedback are always appreciated.
  6. ## Tested environment
  7. Nodes: Ubuntu 18.04 LTS\
  8. Cloud Provider: None (baremetal or VMs)\
  9. Kubernetes version: 1.21.5\
  10. Kubespray version: 2.18.0
  11. ## Important considerations
  12. If you require minimum downtime, nodes need to be cordoned and drained before being processed, one by one. If you wish to run `cluster.yml` only once and get it all done in one swoop, downtime will be significantly higher. Docker will need to be manually removed from all nodes before the playbook runs (see [#8431](https://github.com/kubernetes-sigs/kubespray/issues/8431)). For minimum downtime, the following steps will be executed multiple times, once for each node.
  13. Processing nodes one by one also means you will not be able to update any other cluster configuration using Kubespray before this procedure is finished and the cluster is fully migrated.
  14. Everything done here requires full root access to every node.
  15. ## Migration steps
  16. Before you begin, adjust your inventory:
  17. ```yaml
  18. # Filename: k8s_cluster/k8s-cluster.yml
  19. resolvconf_mode: host_resolvconf
  20. container_manager: containerd
  21. # Filename: etcd.yml
  22. etcd_deployment_type: host
  23. ```
  24. ### 1) Pick one or more nodes for processing
  25. It is still unclear how the order might affect this procedure. So, to be sure, it might be best to start with the control plane and etcd nodes all together, followed by each worker node individually.
  26. ### 2) Cordon and drain the node
  27. ... because, downtime.
  28. ### 3) Stop docker and kubelet daemons
  29. ```commandline
  30. service kubelet stop
  31. service docker stop
  32. ```
  33. ### 4) Uninstall docker + dependencies
  34. ```commandline
  35. apt-get remove -y --allow-change-held-packages containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras
  36. ```
  37. In some cases, there might a `pigz` missing dependency. Some image layers need this to be extracted.
  38. ```shell
  39. apt-get install pigz
  40. ```
  41. ### 5) Run `cluster.yml` playbook with `--limit`
  42. ```commandline
  43. ansible-playbook -i inventory/sample/hosts.ini cluster.yml --limit=NODENAME
  44. ```
  45. This effectively reinstalls containerd and seems to place all config files in the right place. When this completes, kubelet will immediately pick up the new container engine and start spinning up DaemonSets and kube-system Pods.
  46. Optionally, if you feel confident, you can remove `/var/lib/docker` anytime after this step.
  47. ```commandline
  48. rm -fr /var/lib/docker
  49. ```
  50. You can watch new containers using `crictl`.
  51. ```commandline
  52. crictl ps -a
  53. ```
  54. ### 6) Replace the cri-socket node annotation
  55. Node annotations need to be adjusted. Kubespray will not do this, but a simple kubectl is enough.
  56. ```commandline
  57. kubectl annotate node NODENAME --overwrite kubeadm.alpha.kubernetes.io/cri-socket=/var/run/containerd/containerd.sock
  58. ```
  59. The annotation is required by kubeadm to follow through future cluster upgrades.
  60. ### 7) Reboot the node
  61. Reboot, just to make sure everything restarts fresh before the node is uncordoned.
  62. ## After thoughts
  63. If your cluster runs a log aggregator, like fluentd+Graylog, you will likely need to adjust collection filters and parsers. While docker generates Json logs, containerd has its own space delimited format. Example:
  64. ```text
  65. 2020-01-10T18:10:40.01576219Z stdout F application log message...
  66. ```