k8s使用containerd作为容器运行时
Posted 键客李大白
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了k8s使用containerd作为容器运行时相关的知识,希望对你有一定的参考价值。
主机初始化
安装containerd容器运行时
- 获取阿里云镜像源
$ wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- yum安装containerd
$ yum install -y containerd
- 启动containerd服务
$ systemctl start containerd && systemctl enable containerd
- 创建containerd配置文件
$ mkdir -p /etc/containerd
$ containerd config default > /etc/containerd/config.toml #替换配置文件
$ vim /etc/containerd/config.toml #修改配置
sandbox_image = "k8s.gcr.io/pause:3.2" #镜像拉取地址
endpoint = ["https://registry-1.docker.io"] #???
[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.runc.options] #???
- 修改配置文件
$ sed -i "s#k8s.gcr.io#registry.cn-hangzhou.aliyuncs.com/google_containers#g" /etc/containerd/config.toml
$ sed -i /containerd.runtimes.runc.options/a\\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\ \\
SystemdCgroup = true /etc/containerd/config.toml
$ sed -i "s#https://registry-1.docker.io#https://registry.cn-hangzhou.aliyuncs.com#g" /etc/containerd/config.toml
- 重启containerd服务
$ systemctl restart containerd
kubeadm初始化k8s集群
设置容器运行时
$ crictl config runtime-endpoint /run/containerd/containerd.sock #master节点操作
$ crictl config runtime-endpoint /run/containerd/containerd.sock #node节点操作
初始化集群配置文件
$ kubeadm config print init-defaults > kubeadm.yaml
$ vim kubeadm.yaml
apiVersion: kubeadm.k8s.io/v1beta3
bootstrapTokens:
- groups:
- system:bootstrappers:kubeadm:default-node-token
token: abcdef.0123456789abcdef
ttl: 24h0m0s
usages:
- signing
- authentication
kind: InitConfiguration
localAPIEndpoint:
advertiseAddress: 192.168.2.60 #控制节点的 ip
bindPort: 6443
nodeRegistration:
criSocket: /run/containerd/containerd.sock #用 containerd 作为容器运行时
imagePullPolicy: IfNotPresent
name: master1 #控制节点主机名
taints: null
---
apiServer:
timeoutForControlPlane: 4m0s
apiVersion: kubeadm.k8s.io/v1beta3
certificatesDir: /etc/kubernetes/pki
clusterName: kubernetes
controllerManager:
dns:
etcd:
local:
dataDir: /var/lib/etcd
imageRepository: registry.cn-hangzhou.aliyuncs.com/google_containers #指定镜像仓库地址
kind: ClusterConfiguration
kubernetesVersion: 1.23.3 #k8s 版本
networking:
dnsDomain: cluster.local
podSubnet: 10.244.0.0/16 #指定 pod 网段
serviceSubnet: 10.96.0.0/16 #指定 Service 网段
scheduler:
---
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: ipvs
---
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
以上是关于k8s使用containerd作为容器运行时的主要内容,如果未能解决你的问题,请参考以下文章