Bye, docker! 5 minutes to transform containerd!

Time:2021-9-19

Docker, as a very popular container technology, has been abandoned by k8s and replaced by another container technology containerd! In fact, containerd is only a bottom container separated from docker. When it is used, it is no different from docker. This article mainly introduces the use of containerd, hoping to help you!

Springboot e-commerce project Mall (40K + star) address:https://github.com/macrozheng/mall

Introduction to containerd

Containerd is an industrial standard container runtime, which emphasizes simplicity, robustness and portability. Containerd can manage the complete container life cycle in the host, including container image transmission and storage, container execution and management, storage and network, etc.

Docker vs containerd

Containerd is a project separated from docker and can be used as an underlying container runtime. Now it has become a better choice for kubernete container runtime.

Not only docker, but also many cloud platforms also support containerd as the underlying container runtime. Please refer to the following figure for details.

Bye, docker! 5 minutes to transform containerd!

K8S CRI

K8s releases CRI (container runtime interface), which unifies the container runtime interface. Any container runtime that supports CRI can be used as the underlying container runtime of k8s.

Why should k8s give up using docker as the container runtime and use containerd instead?

If you use docker as the k8s container runtime, kubelet needs to pass thedockershimCall docker, and then call containerd through docker.

Bye, docker! 5 minutes to transform containerd!

If you use containerd as the k8s container runtime, because containerd has built-inCRIPlug in, kubelet can directly call containerd.

Bye, docker! 5 minutes to transform containerd!

Using containerd not only improves the performance (the call chain becomes shorter), but also reduces the resource consumption (docker is not a pure container runtime, but has a lot of other functions).

Containerd use

If you have used docker before, you can learn containerd in 5 minutes. Next, let’s learn how to use containerd.

crictl ps
CONTAINER           IMAGE               CREATED                  STATE               NAME                ATTEMPT             POD ID
4ca73ded41bb6       3b0b04aa3473f       Less than a second ago   Running             helm                20                  21103f0058872
3bb5767a81954       296a6d5035e2d       About a minute ago       Running             coredns             1                   af887263bd869
a5e34c24be371       0346349a1a640       About a minute ago       Running             nginx               1                   89defc6008501
  • View all images;
crictl images
IMAGE                                      TAG                 IMAGE ID            SIZE
docker.io/library/nginx                    1.10                0346349a1a640       71.4MB
docker.io/rancher/coredns-coredns          1.8.0               296a6d5035e2d       12.9MB
docker.io/rancher/klipper-helm             v0.4.3              3b0b04aa3473f       50.7MB
docker.io/rancher/local-path-provisioner   v0.0.14             e422121c9c5f9       13.4MB
docker.io/rancher/metrics-server           v0.3.6              9dd718864ce61       10.5MB
docker.io/rancher/pause                    3.1                 da86e6ba6ca19       327kB
  • Enter the container and execute the bash command. Note that only the container ID can be used, and the container name is not supported;
crictl exec -it a5e34c24be371 /bin/bash
  • Viewing the usage of application resources in the container, you can find that the usage is very low.
crictl stats
CONTAINER           CPU %               MEM                 DISK                INODES
3bb5767a81954       0.54                14.27MB             254B                14
a5e34c24be371       0.00                2.441MB             339B                16

summary

The transformation from docker to containerd is very simple, and there is basically no threshold. Just put the previous docker commanddockerChange tocrictlIt’s basically OK. Sure enough, it’s produced by the same company. The usage is the same. Therefore, whether k8s abandons docker or not, it basically has no impact on our developers!

This article GitHubhttps://github.com/macrozheng/mall-learningAlready included, welcome to star!