国内部署kubernetes
2021-03-05 本文已影响0人
冥王星的卧底
虚机为ubuntu16.04,准备安装k8s 1.18版本, 一个master节点,一个work节点举例。
升级操作系统
apt-get update
apt-get upgrade -y
安装docker-ce
每个k8s都需要安装,选用docker 5:18版本
# 部署docker
apt-get remove docker docker-engine docker.io containerd runc
apt-get update
apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
apt-get update
# apt-cache madison docker-ce
# apt-cache madison docker-ce-cli
apt-get install docker-ce=5:18.09.9~3-0~ubuntu-xenial docker-ce-cli=5:18.09.9~3-0~ubuntu-xenial containerd.io
dockers代理
tee /etc/docker/daemon.json <<-'EOF'
{
"exec-opts": ["native.cgroupdriver=systemd"],
"registry-mirrors": [
"https://wht4c63r.mirror.aliyuncs.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com",
"https://reg-mirror.qiniu.com"
]
}
EOF
systemctl daemon-reload
systemctl restart docker
安装kubeadm,kubelet,kubectl
设置阿里云 k8s 源
国内无法访问k8s.io,需要使用阿里云kubernetes源
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add -
tee /etc/apt/sources.list.d/kubernetes.list <<-'EOF'
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
apt-get update
apt-cache madison kubeadm
apt install kubeadm=1.18.16-00 kubectl=1.18.16-00 kubelet=1.18.16-00
提前拉镜像
k8s.gcr.io的镜像国内也无法下载,参考https://blog.csdn.net/bbwangj/article/details/85017765,先将需要的镜像列出,kubeadm config images list,然后更换为阿里云的docker源,拉到本地之后,docker tag更改
kubeadm config images list |sed -e 's/^/docker pull /g' -e 's#k8s.gcr.io#docker.io/registry.aliyuncs.com/google_containers#g' |sh -x
docker images |grep registry.aliyuncs.com/google_containers |awk '{print "docker tag ",$1":"$2,$1":"$2}' |sed -e 's#registry.aliyuncs.com/google_containers#k8s.gcr.io#2' |sh -x
master 节点
kubeadm init --pod-network-cidr 10.10.0.0/16 --kubernetes-version 1.18.16
安装flannel,如下载失败,可以使用浏览器下载kube-flannel.yml文件
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
work节点
kubeadm join 192.168.3.15:6443 --token hnhx8f.jfdtdwkhg0v8hmus \
--discovery-token-ca-cert-hash sha256:4a95483da6377ec7ddd57df92a4839802d579cc16e0e3fde84b357313c7be54a
image.png