k8s-1.28.2单控制节点集群安装(基于containerd)基于阿里anolis



环境说明 k8s 1.28.2 containerd 1.7.8 runc.amd64 1.1.9 anolis 8.8 环境准备 修改主机名 hostnamectl set-hostname 修改host vim /etc/hosts 192.168.2.124 master124 192.168.2.125 master125 192.168.2.126 master126 systemctl disable firewalld systemctl stop firewalld setenforce 0 sed -i ’s/SELINUX=permissive/SELINUX=disabled/’ /etc/sysconfig/selinux sed -i “s/SELINUX=enforcing/SELINUX=disabled/g” /etc/selinux/config swapoff -a sed -i ’s/.swap./#&/’ /etc/fstab cat «EOF > /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_forward = 1 EOF sysctl –system

chronyc -a makestep 和之前不一样的地方 modprobe br_netfilter echo 1 > /proc/sys/net/ipv4/ip_forward sysctl -p /etc/sysctl.d/k8s.conf 安装containerd tar xf containerd-1.6.6-linux-amd64.tar.gz cp -r bin/* /usr/local/bin vim /etc/systemd//system/containerd.service

Copyright The containerd Authors.

Licensed under the Apache License, Version 2.0 (the “License”);

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an “AS IS” BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

[Unit] Description=containerd container runtime

Documentation=https://containerd.io After=network.target local-fs.target [Service] ExecStartPre=-/sbin/modprobe overlay ExecStart=/usr/local/bin/containerd Type=notify Delegate=yes KillMode=process Restart=always RestartSec=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=infinity LimitCORE=infinity LimitNOFILE=infinity

Comment TasksMax if your systemd version does not supports it.

Only systemd 226 and above support this version.

TasksMax=infinity OOMScoreAdjust=-999 [Install] WantedBy=multi-user.target systemctl daemon-reload mkdir /etc/containerd containerd config default > /etc/containerd/config.toml vim config.toml vim下搜索/mirrors,添加镜像加速,使用docker镜像源即可,上下级配置,缩进两个空格。 [plugins.“io.containerd.grpc.v1.cri”.registry.mirrors] [plugins.“io.containerd.grpc.v1.cri”.registry.mirrors.“docker.io”] endpoint = [“https://docker.mirrors.ustc.edu.cn”] 搜索 sandbox_image 将 registry.k8s.io/pause:3.8 替换为 registry.aliyuncs.com/google_containers/pause:3.8 sandbox_image = “registry.aliyuncs.com/google_containers/pause:3.8”

把配置文件中的 SystemdCgroup 修改为 true SystemdCgroup = true systemctl enable containerd –now systemctl restart containerd 安装runc chmod +x runc.amd64 cp runc.amd64 /usr/local/bin/runc 只安装containerd与runc就行,可以不用nerdctl命令行工具与 cni网络插件 安装k8s cat «EOF > /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg EOF yum install -y kubelet-1.28.2 kubeadm-1.28.2 kubectl-1.28.2 systemctl enable kubelet systemctl start kubelet kubelet –version crictl config runtime-endpoint unix:///run/containerd/containerd.sock crictl config image-endpoint unix:///run/containerd/containerd.sock

查看所需的镜像列表

kubeadm config images list –kubernetes-version=v1.28.2 # –image-repository registry.aliyuncs.com/google_containers

1. 使用默认容器镜像仓库

sudo kubeadm config images pull –kubernetes-version=v1.28.2

2. 使用指定容器镜像仓库

sudo kubeadm config images pull –kubernetes-version=v1.28.2 –image-repository registry.aliyuncs.com/google_containers 初始化k8s kubeadm init
–image-repository registry.aliyuncs.com/google_containers
–kubernetes-version=v1.28.2
–pod-network-cidr=10.244.0.0/16
–service-cidr=10.96.0.0/12
–apiserver-advertise-address=192.168.2.124
–node-name=k8s-master
–cri-socket unix:///var/run/containerd/containerd.sock 安装calico网络插件 #目前测试3.23版本的可用 3.24-3.27都报错 curl https://docs.projectcalico.org/v3.23/manifests/calico.yaml -O kubectl apply -f calico.yaml calico 开头的以及 coredns 都跑起来就算完成。 如果网络插件起不来请查看网卡配置 因为有节点是多网卡,所以需要在资源清单文件中指定内网网卡 vim calico.yaml …… spec: containers:

  • env:

Cluster type to identify the deployment type

  • name: CLUSTER_TYPE value: “k8s,bgp”

value 就是指定你的网卡名字,我这里网卡是 eth0,然后直接配置的通配符 eth.*

  • name: IP_AUTODETECTION_METHOD value: “interface=eth.*”

Auto-detect the BGP IP address.

  • name: IP value: “autodetect”

Enable IPIP

  • name: CALICO_IPV4POOL_IPIP value: “Always”

Enable or Disable VXLAN on the default IP pool.

  • name: CALICO_IPV4POOL_VXLAN value: “Never”

Enable or Disable VXLAN on the default IPv6 IP pool.

  • name: CALICO_IPV6POOL_VXLAN value: “Never” …… 加入集群 kubeadm join 192.168.2.126:6443 –token 8xf6yk.rapdmv3tre7isnsy
    –discovery-token-ca-cert-hash sha256:a849756b018b5eba1bd1d5d5599b670c26972e84ec48f304e2312b56bb009658 1.28.2版本的k8s安装kuboard没有成功