wmz 发表于 2025-2-7 03:32:06

openEuler搭建k8s(1.28.2版本)

目录

[*]k8s搭建(1.28.2版本)

[*]1. 安装containerd

[*]1.1 下载tar包
[*]1.2 编写服务单元文件

[*]2. 安装runc
[*]3. 安装cni插件

[*]3.1 下载文件
[*]3.2 设置crictl运行端点

[*]4. 配置containerd
[*]5. 主机配置

[*]5.1 编辑hosts文件(可选)
[*]5.2 开启流量转发
[*]5.3 关闭防火墙以及selinux
[*]5.4 关闭swap

[*]6. 搭建k8s

[*]6.1 配置yum源
[*]6.2 安装工具
[*]6.3 初始化

[*]7. 网络插件

[*]7.1 安装calico
[*]7.2 配置镜像加速器地址




k8s搭建(1.28.2版本)

不知道从什么时候开始,openEuler已经开始支持使用containerd的k8s集群了,之前我学习的时候最高都只能支持到1.23,所以这里再来写一篇关于部署运行时为containerd的集群
为什么要单独写关于openEuler的部署方式?
因为使用centos的部署方式在openEuler上部署的时候会有一些差异,而这些差异的地方就会导致无法继续往下进行,所以我单独写一篇博客来避开这些坑点
1. 安装containerd

你可能想问,一个containerd有什么不会安装的,直接使用yum不就可以安装好了吗?是的,你在其他操作系统上确实可以这么干,但是在openEuler上这么干不会报错,因为yum仓库里面确实有containerd的rpm包,你确实可以装上,但是那个containerd版本太低。无法正常的使用。所以需要下载tar包来安装
1.1 下载tar包

# 确保没有使用官方仓库的containerd# yum remove containerd -y# wget https://github.com/containerd/containerd/releases/download/v1.7.16/containerd-1.7.16-linux-amd64.tar.gz# tar -zxvf containerd-1.7.16-linux-amd64.tar.gz # mv bin/* /usr/local/bin/1.2 编写服务单元文件

# vim /usr/lib/systemd/system/containerd.serviceDescription=containerd container runtimeDocumentation=https://containerd.ioAfter=network.target local-fs.targetExecStartPre=-/sbin/modprobe overlayExecStart=/usr/local/bin/containerdType=notifyDelegate=yesKillMode=processRestart=alwaysRestartSec=5# Having non-zero Limit*s causes performance problems due to accounting overhead# in the kernel. We recommend using cgroups to do container-local accounting.LimitNPROC=infinityLimitCORE=infinity# Comment TasksMax if your systemd version does not supports it.# Only systemd 226 and above support this version.TasksMax=infinityOOMScoreAdjust=-999WantedBy=multi-user.target然后给containerd设计开机自启
# systemctl daemon-reload# systemctl enable --now containerd2. 安装runc

这个也是一样的,不能使用yum安装的版本(至少面前不可以--文章写于2024-11-9)
# yum remove runc -y# wget https://github.com/opencontainers/runc/releases/download/v1.1.12/runc.amd64# install -m 755 runc.amd64 /usr/local/sbin/runc3. 安装cni插件

3.1 下载文件

# wget https://github.com/containernetworking/plugins/releases/download/v1.4.1/cni-plugins-linux-amd64-v1.4.1.tgz# mkdir -p /opt/cni/bin# tar Cxzvf /opt/cni/bin cni-plugins-linux-amd64-v1.4.1.tgz3.2 设置crictl运行端点

cat <<EOF > /etc/crictl.yamlruntime-endpoint: unix:///run/containerd/containerd.sockimage-endpoint: unix:///run/containerd/containerd.socktimeout: 5debug: falseEOF4. 配置containerd

# containerd config default > /etc/containerd/config.toml # 将cgroup打开# vim /etc/containerd/config/toml# 找到这一行配置,将false改为trueSystemdCgroup = true# 修改sandbox镜像地址sandbox_image = "registry.aliyuncs.com/google_containers/pause:3.9"重启containerd
# systemctl restart containerd5. 主机配置

5.1 编辑hosts文件(可选)

将IP与主机名写入到/etc/hosts文件内,我这里就不做了。不做没有任何影响
5.2 开启流量转发

# modprobe bridge# modprobe br_netfilter# vim /etc/sysctl.confnet.bridge.bridge-nf-call-ip6tables = 1net.bridge.bridge-nf-call-iptables = 1net.ipv4.ip_forward = 1# sysctl -p5.3 关闭防火墙以及selinux

# sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config# systemctl disable --now firewalld5.4 关闭swap

如果配置了swap,请关闭他
# swapoff -a然后进入到/etc/fstab里面注释掉swap的那一行内容
6. 搭建k8s

到这里就开始搭建k8s了
6.1 配置yum源

#cat <<EOF > /etc/yum.repos.d/kubernetes.reponame=Kubernetesbaseurl=https://mirrors.huaweicloud.com/kubernetes/yum/repos/kubernetes-el7-$basearchenabled=1gpgcheck=1repo_gpgcheck=0gpgkey=https://mirrors.huaweicloud.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.huaweicloud.com/kubernetes/yum/doc/rpm-package-key.gpgEOF6.2 安装工具

# yum install kubectl kubeadm kubelet -y# systemctl enable kubelet6.3 初始化

#kubeadm init --kubernetes-version=v1.28.2 --pod-network-cidr=10.244.0.0/16 --image-repository=registry.aliyuncs.com/google_containers

[*]这里的kubernetes-version后面的值修改为你自己的kubeadm的版本
Your Kubernetes control-plane has initialized successfully!To start using your cluster, you need to run the following as a regular user:mkdir -p $HOME/.kubesudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo chown $(id -u):$(id -g) $HOME/.kube/configAlternatively, if you are the root user, you can run:export KUBECONFIG=/etc/kubernetes/admin.confYou should now deploy a pod network to the cluster.Run "kubectl apply -f .yaml" with one of the options listed at:https://kubernetes.io/docs/concepts/cluster-administration/addons/Then you can join any number of worker nodes by running the following on each as root:kubeadm join 192.168.200.200:6443 --token alefrt.vuiz4k7424ljhh2i \        --discovery-token-ca-cert-hash sha256:1c0943c98d9aeaba843bd683d60ab66a3b025d65726932fa19995f067d62d436 看到这一段信息就是初始化成功了,然后我们根据提示来创建目录
# mkdir -p $HOME/.kube# sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config# sudo chown $(id -u):$(id -g) $HOME/.kube/config,如果有其他节点需要加入集群那么就执行
# kubeadm join 192.168.200.200:6443 --token alefrt.vuiz4k7424ljhh2i \        --discovery-token-ca-cert-hash sha256:1c0943c98d9aeaba843bd683d60ab66a3b025d65726932fa19995f067d62d436 然后我们可以查看节点状态
# kubectl get nodesNAME   STATUS   ROLES         AGE   VERSIONmaster   NotReady   control-plane   26s   v1.28.2接下来我们安装网络插件calico,让他的状态变为Ready
7. 网络插件

7.1 安装calico

#wget https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml# kubectl create -f tigera-operator.yaml接下来我们来处理第二个文件
# wget https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/custom-resources.yaml# vim custom-resources.yaml # 将里面的cidr改为初始化集群使用的地址段      cidr: 10.244.0.0/167.2 配置镜像加速器地址

如果不配置镜像加速器地址的话。镜像是拉取不到的。
# vim /etc/containerd/config.toml# 需要找到这一行,并添加2行    endpoint = ["镜像加速器地址1","镜像加速器地址2"]可以百度搜一下哪些镜像加速器地址还可以使用,然后替换掉里面的文字
重启containerd
# systemctl restart containerd然后等到他把所有的镜像拉取完之后集群就正常了
最终就是这样的
# kubectl get nodes NAME   STATUS   ROLES         AGE   VERSIONmaster   Ready    control-plane   15m   v1.28.2
页: [1]
查看完整版本: openEuler搭建k8s(1.28.2版本)