高速镜像源:清华源、华为源、阿里源
0. centos
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-7-anon.repo
1. docker-ce
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.huaweicloud.com/docker-ce/linux/centos/docker-ce.repo
软件仓库地址替换为:
sed -i 's+download.docker.com+mirrors.huaweicloud.com/docker-ce+' /etc/yum.repos.d/docker-ce.repo
更新索引文件并安装
yum makecache fast
yum install docker-ce && systemctl enable docker
配置加速源 /etc/docker/daemon.json
{
"registry-mirrors": [
"https://b9pmyelo.mirror.aliyuncs.com",
"https://1nj0zren.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"http://f1361db2.m.daocloud.io",
"https://registry.docker-cn.com"
]
}
2. k8s
修改/etc/yum.repos.d/kubernetes.repo文件:
cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=https://mirrors.huaweicloud.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/kubernetes/yum/doc/yum-key.gpg https://mirrors.huaweicloud.com/kubernetes/yum/doc/rpm-package-key.gpg
EOF
SELinux运行模式切换为宽容模式
setenforce 0
更新索引文件
yum install -y kubelet-1.18.2 kubeadm-1.18.2 kubectl-1.18.2 --disableexcludes=kubernetes && systemctl enable --now kubelet
安装ipvsadm
yum install -y ipvsadm
echo > /etc/sysconfig/modules/ipvs.modules <<EOF
#!/bin/bash
ipvs_modules="ip_vs ip_vs_lc ip_vs_wlc ip_vs_rr ip_vs_wrr ip_vs_lblc ip_vs_lblcr ip_vs_dh ip_vs_sh ip_vs_fo ip_vs_nq ip_vs_sed ip_vs_ftp nf_conntrack"
for kernel_module in \${ipvs_modules}; do /sbin/modinfo -Ffilename \${kernel_module} > /dev/null 2>&1
if [ $? -eq 0 ];then
/sbin/modprobe\${kernel_module}
fi
done
EOF
初始化集群
kubeadm init --apiserver-advertise-address=172.18.3.168 --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.18.2 --service-cidr=10.96.0.0/24 --pod-network-cidr=10.244.0.0/16 --ignore-preflight-errors=all --v=5
加入集群
kubeadm join 172.18.3.168:6443 --token 41ttux.9miaem2gdc4zzjfr \
--discovery-token-ca-cert-hash sha256:85c348866e543c3483ee3b7d11dddc89c0686306796f64132034441e59f331a2
calico网络组件
wget https://docs.projectcalico.org/manifests/calico.yaml
kubectl apply -f calico.yaml
检查集群
kubectl get nodes