在CentOS上安裝Kubernetes(k8s)集群的步驟如下:
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
sed -i 's/SELINUXenforcing/SELINUXdisabled/g' /etc/selinux/config
swapoff -a
sed -i '/swap/s///#/g' /etc/fstab
hostnamectl set-hostname k8s-master
yum install -y ntpdate
ntpdate ntp.aliyun.com
yum install -y yum-utils device-mapper-persistent-data lvm2
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
systemctl start docker
systemctl enable docker
docker --version
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=1
repo_gpgcheck=1
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 kubeadm kubectl
/etc/kubernetes/kubelet.conf
文件,設置 --cgroup-driver
為 systemd
(如果使用Docker作為容器運行時)。kubeadm init --apiserver-advertise-address master-ip --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr 10.244.0.0/16
初始化完成后,Master節點會輸出一個join命令,用于將Node節點加入到集群中。kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
kubectl get nodes
如果一切正常,你應該能看到所有節點都已加入集群。以上步驟是基于CentOS 7和較新版本的Kubernetes進行安裝的。如果使用的是CentOS 8或其他版本,可能需要根據具體情況進行調整。同時,建議在安裝前查閱最新的官方文檔,以確保安裝步驟和配置與最新的Kubernetes版本兼容。