add kubespray to the XTesting as it provides newer version of kubenetes and can be...
[it/test.git] / XTesting / kubespray / docs / upgrades / migrate_docker2containerd.md
1 # Migrating from Docker to Containerd
2
3 ❗MAKE SURE YOU READ BEFORE PROCEEDING❗
4
5 **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.
6
7 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.
8
9 Input and feedback are always appreciated.
10
11 ## Tested environment
12
13 Nodes: Ubuntu 18.04 LTS\
14 Cloud Provider: None (baremetal or VMs)\
15 Kubernetes version: 1.21.5\
16 Kubespray version: 2.18.0
17
18 ## Important considerations
19
20 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.
21
22 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.
23
24 Everything done here requires full root access to every node.
25
26 ## Migration steps
27
28 Before you begin, adjust your inventory:
29
30 ```yaml
31 # Filename: k8s_cluster/k8s-cluster.yml
32 resolvconf_mode: host_resolvconf
33 container_manager: containerd
34
35 # Filename: etcd.yml
36 etcd_deployment_type: host
37 ```
38
39 ### 1) Pick one or more nodes for processing
40
41 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.
42
43 ### 2) Cordon and drain the node
44
45 ... because, downtime.
46
47 ### 3) Stop docker and kubelet daemons
48
49 ```commandline
50 service kubelet stop
51 service docker stop
52 ```
53
54 ### 4) Uninstall docker + dependencies
55
56 ```commandline
57 apt-get remove -y --allow-change-held-packages containerd.io docker-ce docker-ce-cli docker-ce-rootless-extras
58 ```
59
60 In some cases, there might a `pigz` missing dependency. Some image layers need this to be extracted.
61
62 ```shell
63 apt-get install pigz
64 ```
65
66 ### 5) Run `cluster.yml` playbook with `--limit`
67
68 ```commandline
69 ansible-playbook cluster.yml -i inventory/sample/hosts.ini cluster.yml --limit=NODENAME
70 ```
71
72 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.
73
74 Optionally, if you feel confident, you can remove `/var/lib/docker` anytime after this step.
75
76 ```commandline
77 rm -fr /var/lib/docker
78 ```
79
80 You can watch new containers using `crictl`.
81
82 ```commandline
83 crictl ps -a
84 ```
85
86 ### 6) Replace the cri-socket node annotation
87
88 Node annotations need to be adjusted. Kubespray will not do this, but a simple kubectl is enough.
89
90 ```commandline
91 kubectl annotate node NODENAME --overwrite kubeadm.alpha.kubernetes.io/cri-socket=/var/run/containerd/containerd.sock
92 ```
93
94 The annotation is required by kubeadm to follow through future cluster upgrades.
95
96 ### 7) Reboot the node
97
98 Reboot, just to make sure everything restarts fresh before the node is uncordoned.
99
100 ## After thoughts
101
102 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:
103
104 ```text
105 2020-01-10T18:10:40.01576219Z stdout F application log message...
106 ```