# (2). 安装kubelet、kubeadm、kubectl cat <<EOF | sudo tee /etc/yum.repos.d/kubernetes.repo [kubernetes] name=Kubernetes baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64 enabled=1 gpgcheck=0 repo_gpgcheck=0 gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg exclude=kubelet kubeadm kubectl EOF sudo yum install -y kubelet-1.20.9 kubeadm-1.20.9 kubectl-1.20.9 --disableexcludes=kubernetes sudo systemctl enable --now kubelet
③. kubeadm引导集群
- ①. 下载各个机器需要的镜像(需要在三台机器上都执行如下命令)
# 下载核心镜像 kubeadm config images list:查看需要哪些镜像 # kubeadm config images list sudo tee ./images.sh <<-'EOF' #!/bin/bash images=( kube-apiserver:v1.20.9 kube-proxy:v1.20.9 kube-controller-manager:v1.20.9 kube-scheduler:v1.20.9 coredns:1.7.0 etcd:3.4.13-0 pause:3.2 ) for imageName in ${images[@]} ; do docker pull registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images/$imageName done EOF chmod +x ./images.sh && ./images.sh
②. 初始化主节点
指定一个网络可达范围pod的子网范围+service负载均衡网络的子网范围+本机ip的子网范围不能有重复域
注意:下面这个ip(192.168.68.144)地址需要改成自己的ip地址
#所有机器添加master域名映射,以下需要修改为自己的 echo "192.168.68.144 k8s-master" >> /etc/hosts #主节点初始化 kubeadm init \ --apiserver-advertise-address=192.168.68.144 \ --control-plane-endpoint=k8s-master \ --image-repository registry.cn-hangzhou.aliyuncs.com/lfy_k8s_images \ --kubernetes-version v1.20.9 \ --service-cidr=10.96.0.0/16 \ --pod-network-cidr=11.168.0.0/16 #所有网络范围不重叠