在CentOS上安裝Kubernetes(K8s)時,有幾個關鍵的注意事項需要特別注意:
關閉或臨時禁用SELinux:
setenforce 0
/etc/selinux/config
文件,將 SELINUX=enforcing
改為 SELINUX=disabled
,然后重啟系統。關閉防火墻:
systemctl stop firewalld
systemctl disable firewalld
關閉交換分區(swap):
swapoff -a
/etc/fstab
文件中注釋掉swap分區。配置網絡參數:
cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.ipv4.ip_forward = 1
EOF
sysctl -p /etc/sysctl.d/k8s.conf
設置主機名和hosts文件:
/etc/hosts
文件以便于域名解析:hostnamectl set-hostname localhost.localdomain
echo "127.0.0.1 localhost localhost.localdomain" >> /etc/hosts
配置Docker:
/etc/docker/daemon.json
文件:cat <<EOF > /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"exec-opts": ["native.cgroupdriver=systemd"]
}
EOF
systemctl daemon-reload
systemctl restart docker
安裝Kubernetes組件:
cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-\$basearch
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
EOF
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet && systemctl start kubelet
初始化Kubernetes集群:
kubeadm init --apiserver-advertise-address <master-ip> --image-repository registry.aliyuncs.com/google_containers --kubernetes-version 1.23.5
通過遵循這些注意事項,可以確保在CentOS上安裝Kubernetes的過程更加順利和安全。