擴展CentOS上的Kubernetes(k8s)部署規模涉及多個步驟,以下是一個基本的指南:
在每個節點上進行以下操作:
yum install -y ntpdate ntp wget lsof telnet yum-utils
yum update
hostnamectl set-hostname k8s-master
hostnamectl set-hostname k8s-worker1
hostnamectl set-hostname k8s-worker2
/etc/hosts
文件,將主機名和IP地址映射添加進去。cat >> /etc/hosts << EOF
192.168.192.131 k8s-master
192.168.192.132 k8s-worker1
192.168.192.133 k8s-worker2
EOF
ntpdate -u ntp.aliyun.com
swapoff -ased -ri 's/.*swap.*/#&/' /etc/fstab
setenforce 0
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
systemctl disable firewalld
systemctl status firewalld
/etc/sysctl.conf
文件,加載必要的流量控制內核模塊:vm.swappiness=0
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.ipv4.ip_forward = 1
使配置立即生效:sysctl --system
在每個節點上進行以下操作:
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum makecache fast
yum install -y docker-ce docker-ce-cli containerd.io
/etc/docker/daemon.json
文件:mkdir -p /etc/docker
tee /etc/docker/daemon.json <<-'EOF'
{"registry-mirrors": ["https://*********.mirror.aliyuncs.com"]}
EOF
重載并重啟Docker服務:systemctl daemon-reload
systemctl restart docker
從Kubernetes v1.24發行版起,dockershim
組件被移除,需要安裝cri-dockerd
:
cri-dockerd
:wget https://github.com/Mirantis/cri-dockerd/releases/download/v0.3.4/cri-dockerd-0.3.4-3.el7.x86_64.rpm
rpm -ivh cri-dockerd-0.3.4-3.el7.x86_64.rpm
kubeadm join <master-ip>:<master-port> --token <token> --discovery-token-ca-cert-hash sha256:<hash>
etcdctl --name <node-name> --endpoints=<etcd-endpoints> --initial-cluster-token <token> --initial-cluster <cluster-name>/<node-name>,<node-ip>:<node-port> --initial-cluster-state=new
使用以下命令驗證集群狀態:
kubectl get nodes
通過以上步驟,你可以擴展CentOS上的Kubernetes集群規模。根據實際需求,可能還需要進行更多的配置和優化。