在CentOS上安装Kubernetes(k8s)需要满足一定的硬件和软件要求。以下是详细的安装要求和步骤:
systemctl stop firewalld
,systemctl disable firewalld
。setenforce 0
,永久禁用:sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
。swapoff -a
。sed -i '/swap/s///#/g' /etc/fstab
。配置主机名和hosts文件:
hostnamectl set-hostname k8s-master
。/etc/hosts
文件,指定各节点的IP地址和主机名。时间同步:
ntpdate
并配置时间同步:yum install -y ntpdate ntpdate ntp.aliyun.com
,systemctl enable ntpdate
,systemctl start ntpdate
。安装Docker:
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
。安装Kubernetes组件:
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
EOF
yum install -y kubelet kubeadm kubectl
。/etc/kubernetes/kubelet.conf
文件,设置 --cgroup-driver
为 systemd
(如果使用Docker作为容器运行时)。初始化Master节点:
kubeadm init --apiserver-advertise-address <master-ip> --image-repository registry.aliyuncs.com/google_containers --pod-network-cidr 10.244.0.0/16
。将Node节点加入集群:
安装网络插件(如Flannel):
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
。验证集群状态:
kubectl get nodes
。以上步骤是基于CentOS 7和较新版本的Kubernetes进行安装的。如果使用的是CentOS 8或其他版本,可能需要根据具体情况进行调整。同时,建议在安装前查阅最新的官方文档,以确保安装步骤和配置与最新的Kubernetes版本兼容。