在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版本兼容。