CentOS 7 安裝k8s叢集
1、建立3臺虛擬機器,並繫結可以連線外網的EIP
2、配置主機名、新增hosts
hostnamectl set-hostname k8s-master1
hostnamectl set-hostname k8s-node1
hostnamectl set-hostname k8s-node2
cat >> /etc/hosts << EOF
192.168.56.11 k8s-master1
192.168.56.12 k8s-node1
192.168.56.13 k8s-node2
EOF
3、關閉防火牆、SELINUX和swap分割槽
systemctl stop firewalld && systemctl disable firewalld
setenforce 0 && sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
swapoff -a && sed -ri 's/.*swap.*/#&/' /etc/fstab
4、配置阿里雲yum源
cd /etc/yum.repos.d/ && mkdir bak && mv *.repo bak
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
curl -o/etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
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=0
repo_gpgcheck=0
EOF
yum clean all && yum makecache
5、將橋接的IPV4流量傳遞到iptables 的鏈
cat > /etc/sysctl.d/k8s.conf << EOF
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
EOF
sysctl --system
7、安裝k8s
yum install -y kubelet kubeadm kubectl
systemctl enable kubelet
8、統一docker執行方式
vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/dockerd 後面新增 --exec-opt native.cgroupdriver=systemd
9、在master節點初始化
kubeadm init \
--apiserver-advertise-address=192.168.56.11 \
--image-repository registry.aliyuncs.com/google_containers \
--kubernetes-version v1.23.5 \
--service-cidr=10.1.0.0/16 \
--pod-network-cidr=10.244.0.0/16
按照上圖提示先完成叢集啟動配置檔案的配置
10、此時叢集狀態為notReady,需要先建立網路,如果無法獲取檔案,需要先想辦法獲取到對應的yaml檔案
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
11、在node節點執行節點加入叢集操作,使用第9步初始化的時候打印出來的命令
12、使能node節點可以使用kubectl命令
mkdir ~/.kube && scp k8s-master1:/root/.kube/config ~/.kube/
13、使能kube命令補全
yum -y install bash-completion
source /usr/share/bash-completion/bash_completion
source <(kubectl completion bash)
echo "source <(kubectl completion bash)" >> ~/.bashrc