《Kubernetes runtime从docker迁移到containerd探索.docx》由会员分享,可在线阅读,更多相关《Kubernetes runtime从docker迁移到containerd探索.docx(19页珍藏版)》请在第一文库网上搜索。
1、Kubernetesruntime从docker迁移至Ucontainerd探索O1前言Kubernetes(以下简称k8s)宣布在120版本之后将弃用docker作为容器运行时,在2023年末发布的1.23版本中将彻底移除01心”11加组件。Dockershim是kube1et内置的一个组件,功能是使k8s能够通过CRI(ContainerRuntimeInterface)操作docker。一旦docker有任何的功能特性变更,dockershim代码必须加以改动来保证能够继续和docker通信。另外,docker的底层运行时是Containerd,而Containerd自身是可以支持CR1
2、的,也就是说k8s可以绕过docker通过CR1直接与COntainerd通信,这也是k8s社区希望弃用dockershim的原因。Containerd在1.0版本中虽然考虑了CRI,但是它将CR1-COntainerd作为一个独立组件存在的,即:k8s需要先通过CR1接口调用CR1-COntainerd,再由这个组件去调用Containerdo在COntaiIIerd11版本之后对该特性做了重新的设计,它将CRI-PIUgin内嵌在Containerd中,以此来达到与Containerd通信的目的,调用链路更短了。COntainerd1I支持k8s1.10及以上版本作为容器运行时,并且支持k
3、8s的全部特性。下图说明了docker和COntainerd作为容器运行时的工作原理。由此可以看出,如果之前使用docker作为容器运行时,那么迁移到Containerd是一个相对容易的选择,而且Containerd具有更好的性能和更低的成本。接下来,主要介绍如何将k8s的运行时从docker迁移到COntainerd,并且迁移之后使用上的一些变化。02K8s运行时从docker迁移到Containerd(1)环境准备操作系统:SUSE12SP5Kerne1版本:4.12.14-120K8s版本:v1.14.0DoCker版本:docker-ee-18.09.9Containerd版本:1.4
4、.4(2)查看当前节点运行时信息kubect1getnode-owide=-1可以看到,当前所有节点使用的运行时都是docker,通过Systemct1statusContainerd可以看到COntainerCI服务默认也是启动的O使用如下命令列出Containerd的命名空间。ctrnamespaces1ist可以看到有一个moby命名空间,这也是docker服务默认使用的命名空间。ctr-namespacemobycontainer1ist使用如上命令列出Inoby命名空间下运行的所有容器,结果如下图,可以看到跟dockerPS输出的容器个数相同。-一一11(3)驱逐节点并停止节点上的d
5、ocker和kube1et服务kubect1drainspk8mgr03-ignore-daemonsets-de1ete-1oca1-data-forcesystemct1stopkube1etsystemct1stopdocker卸载docker(该步躲是可选的,为了排除测试过程中docker的干扰,这里选择卸载)zypperrm-ydocker-eedocker-ee-c1icontainerd.io(4)安装配置Containerd下载containerd并解压安装Wgethttps:/-containerd-cni-1.4.4-1inux-amd64.tar.gztar-C/-zvf
6、cri-containerd-cni-1.4.4-1inu-amd64.tar.gz解压后的文件包括如下内容:/etc/etcsystemdetcsystemdsystem/etcsystemdsystemcontainerd.serviceetccrict1.yam1etccnietccninet.d/etccninet.d10-containerd-net.conf1istusrusr1oca1usr1oca1binusr1oca1bincontainerdusr1oca1bincontainerd-shimusr1oca1bincrict1usr1oca1bincontainerd-sh
7、im-runc-v2usr1oca1bincritestusr1oca1bincontainerd-shim-runc-v1usr1oca1binctrusr1oca1sbinusr1oca1sbinruncopt/opt/containerd/optcontainerdc1uster/optcontainerdc1uster/gceoptcontainerdc1ustergceenvoptcontainerdc1ustergcecni.temp1ate/opt/containerd/c1uster/gceconfigure,sh/opt/containerdc1ustergcec1oud-i
8、nitoptcontainerdc1ustergcec1oud-initnode,yam1optcontainerdc1ustergcec1oud-initmaster.yam1optcontainerdc1usterversionoptcnioptcnibinoptcnibinbandwidthoptcnibinhost-device/opt/cnibinf1anne1optcnibinstaticoptcnibin1oopbackoptcnibindhcpoptcnibinptpoptcnibinipv1anoptcnibinv1anoptcnibinhost-1oca1optcnibin
9、firewa11optcnibintuning/opt/cnibinsbr/opt/cni/bin/bridgeoptcnibinportmapoptcni/bin/macv1an启动并配置containerdsystemct1startcontainerdsystemct1enab1econtainerdmkdir-petccontainerdcontainerdconfigdefau1tetccontainerdconfig.tom1config,tom1文件内容如下,注意修改sandbox_image参数version=2root=wvar1ibcontainerd,state=nrun
10、containerd,11HHp1ugn-r-disab1ed_p1ugins=口required_p1ugins=oom_score=Ogrpcaddress=,7run/containerd/containerd.socktcp_address=wwtcp_t1s_cert=tcp_t1s_key=wuid=0gid=0max_recv_message_size=16777216max_send_message_size=16777216ttrpcaddress=uid-0gid=0debugaddress=uid=Ogid二O1eve1=metricsaddress=grpc_histo
11、gram=fa1secgrouppath=timeoutsio.containerd.timeout,shim,c1eanupw=,5s,io.containerd.timeout,shim.Ioadw=5s”,io.containerd.timeout,shim,shutdown0=3s”io.containerd.timeout,task,state,=2sp1uginsp1ugins,tio.containerd.gc.v1.schedu1erpause_thresho1d=O.02de1etion_thresho1d二Omutation_thresho1d=IOOschedu1e_de
12、1ay=Osstartup_de1ay=,100msr,p1ugins,io.containerd.grpc.v1.criwdisab1e_tcp_service=truestream_server_address=127.0.0.1stream_server_port=f,0wstream_id1e_timeout=4h0m0senab1e_seIinux=fa1sese11nux_category_range=1024sandbox_image=,k8s.gc.io/pause:3.1stats_co11ect_period=10systemd_cgroup=fa1seenab1e_t1s
13、_streaming=fa1semax_container_1og_1ine_size=16384disab1e_cgroup=fa1sedisab1e_apparmor=fa1serestrict_oom_score_adj=fa1semax_concurrent_down1oads=3disab1e_proc_mount=fa1seunset_seccomp_profiIe=to1erate_missing_huget1b_contro11er=truedisab1e_huget1b_contro11er=trueignore_image_defined_vo1umes=fa1sep1ug
14、ins,io.containerd.grpc.v1.crir,.containerdsnapshotter=nover1ayfsdefau1t_runtime_name=runeno_pivot=fa1sedisab1e_snapshot_annotations=truediscard_unpacked_1ayers=fa1sep1ugins.nio.containerd.grpc.v1.cri,.containerd.defau1t_runtimeruntime_type=runtime_engine二runtime_root二privi1eged_without_host_devices=fa1sebase_runtime_specp1ugins,nio.containerd.grpc.v1.crih.containerd.untrusted_work1oad_runtimeruntime_type=runtime_engine二runtime_root=privi1eged_without_host_devices