Skip to content

Commit b03dfa8

Browse files
authored
Docs to change Container runtime (#30141)
* Docs to change Container runtime * Updated header * Updated header * Few changes made according to the reviews * Updated few headings * Updated few markdown changes * Reverted a unwanted changes * Removed the double extension in the filename * Updated * Updated according to review * Final Updates * Added instructions to remove docker engine * Minor changes * Minor updates on heading * Minor updates on lists * Minor updates on line 106 * Minor updates on line 106
1 parent 89e2fa2 commit b03dfa8

File tree

1 file changed

+154
-0
lines changed

1 file changed

+154
-0
lines changed
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
title: "Changing the Container Runtime on a Node from Docker Engine to containerd"
3+
weight: 8
4+
content_type: task
5+
---
6+
7+
This task outlines the steps needed to update your container runtime to containerd from Docker. It is applicable for cluster operators running Kubernetes 1.23 or earlier. Also this covers an example scenario for migrating from dockershim to containerd and alternative container runtimes can be picked from this [page](https://kubernetes.io/docs/setup/production-environment/container-runtimes/).
8+
9+
## {{% heading "prerequisites" %}}
10+
11+
{{% thirdparty-content %}}
12+
13+
Install containerd. For more information see, [containerd's installation documentation](https://containerd.io/docs/getting-started/) and for specific prerequisite follow [this](/docs/setup/production-environment/container-runtimes/#containerd).
14+
15+
## Drain the node
16+
17+
```
18+
# replace <node-to-drain> with the name of your node you are draining
19+
kubectl drain <node-to-drain> --ignore-daemonsets
20+
```
21+
## Stop the Docker daemon
22+
23+
```shell
24+
systemctl stop kubelet
25+
systemctl disable docker.service --now
26+
```
27+
28+
## Install Containerd
29+
30+
This [page](/docs/setup/production-environment/container-runtimes/#containerd) contains detailed steps to install containerd.
31+
32+
{{< tabs name="tab-cri-containerd-installation" >}}
33+
{{% tab name="Linux" %}}
34+
35+
1. Install the `containerd.io` package from the official Docker repositories.
36+
Instructions for setting up the Docker repository for your respective Linux distribution and installing the `containerd.io` package can be found at
37+
[Install Docker Engine](https://docs.docker.com/engine/install/#server).
38+
39+
2. Configure containerd:
40+
41+
```shell
42+
sudo mkdir -p /etc/containerd
43+
containerd config default | sudo tee /etc/containerd/config.toml
44+
```
45+
46+
3. Restart containerd:
47+
48+
```shell
49+
sudo systemctl restart containerd
50+
```
51+
52+
{{% /tab %}}
53+
{{% tab name="Windows (PowerShell)" %}}
54+
55+
Start a Powershell session, set `$Version` to the desired version (ex: `$Version="1.4.3"`), and then run the following commands:
56+
57+
1. Download containerd:
58+
59+
```powershell
60+
curl.exe -L https://github.com/containerd/containerd/releases/download/v$Version/containerd-$Version-windows-amd64.tar.gz -o containerd-windows-amd64.tar.gz
61+
tar.exe xvf .\containerd-windows-amd64.tar.gz
62+
```
63+
64+
2. Extract and configure:
65+
66+
```powershell
67+
Copy-Item -Path ".\bin\" -Destination "$Env:ProgramFiles\containerd" -Recurse -Force
68+
cd $Env:ProgramFiles\containerd\
69+
.\containerd.exe config default | Out-File config.toml -Encoding ascii
70+
71+
# Review the configuration. Depending on setup you may want to adjust:
72+
# - the sandbox_image (Kubernetes pause image)
73+
# - cni bin_dir and conf_dir locations
74+
Get-Content config.toml
75+
76+
# (Optional - but highly recommended) Exclude containerd from Windows Defender Scans
77+
Add-MpPreference -ExclusionProcess "$Env:ProgramFiles\containerd\containerd.exe"
78+
```
79+
80+
3. Start containerd:
81+
82+
```powershell
83+
.\containerd.exe --register-service
84+
Start-Service containerd
85+
```
86+
87+
{{% /tab %}}
88+
{{< /tabs >}}
89+
90+
## Configure the kubelet to use containerd as its container runtime
91+
92+
Edit the file `/var/lib/kubelet/kubeadm-flags.env` and add the containerd runtime to the flags. `--container-runtime=remote` and `--container-runtime-endpoint=unix:///run/containerd/containerd.sock"`
93+
94+
For users using kubeadm should consider the following:
95+
96+
The `kubeadm` tool stores the CRI socket for each host as an annotation in the Node object for that host.
97+
98+
To change it you must do the following:
99+
100+
Execute `kubectl edit no <NODE-NAME>` on a machine that has the kubeadm `/etc/kubernetes/admin.conf` file.
101+
102+
This will start a text editor where you can edit the Node object.
103+
104+
To choose a text editor you can set the `KUBE_EDITOR` environment variable.
105+
106+
- Change the value of `kubeadm.alpha.kubernetes.io/cri-socket` from `/var/run/dockershim.sock`
107+
to the CRI socket path of your choice (for example `unix:///run/containerd/containerd.sock`).
108+
109+
Note that new CRI socket paths must be prefixed with `unix://` ideally.
110+
111+
- Save the changes in the text editor, which will update the Node object.
112+
113+
## Restart the kubelet
114+
115+
```shell
116+
systemctl start kubelet
117+
```
118+
119+
## Verify that the node is healthy
120+
121+
Run `kubectl get nodes -o wide` and containerd appears as the runtime for the node we just changed.
122+
123+
## Remove Docker Engine
124+
125+
{{% thirdparty-content %}}
126+
127+
Finally if everything goes well remove docker
128+
129+
{{< tabs name="tab-remove-docker-enigine" >}}
130+
{{% tab name="CentOS" %}}
131+
132+
```shell
133+
sudo yum remove docker-ce docker-ce-cli
134+
```
135+
{{% /tab %}}
136+
{{% tab name="Debian" %}}
137+
138+
```shell
139+
sudo apt-get purge docker-ce docker-ce-cli
140+
```
141+
{{% /tab %}}
142+
{{% tab name="Fedora" %}}
143+
144+
```shell
145+
sudo dnf remove docker-ce docker-ce-cli
146+
```
147+
{{% /tab %}}
148+
{{% tab name="Ubuntu" %}}
149+
150+
```shell
151+
sudo apt-get purge docker-ce docker-ce-cli
152+
```
153+
{{% /tab %}}
154+
{{< /tabs >}}

0 commit comments

Comments
 (0)