1.1部署规划图
禁用防火墙
systemctl stop firewalld
systemctl disable firewalld
关闭 swap
swapoff -a
sed -i 's/.*swap.*/#&/' /etc/fstab
安装 docker
#安装必要的一些系统工具
apt-get update && apt-get -y install apt-transport-https ca-certifi
cates curl software-properties-common
#安装gpg证书
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg
| sudo apt-key add -
apt-get -y update && apt-get -y install docker-ce
systemctl start docker && systemctl enable docker
配置 docker 加速器
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["你的加速地址"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
配置阿里云仓库地址
配置阿里云镜像的 kubernetes 源(用于安装 kubelet kubeadm kubectl 命令)
apt-get update && apt-get install -y apt-transport-https
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg
| apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial
main
EOF #手动输入 EOF
安装相 kubeadm 命令
apt-get update
apt-get install -y kubelet kubeadm kubectl
systemctl enable kubelet
#安装指定版本 kubeadm
apt-cache madison kubeadm #查看版本信息
apt-get install kubeadm=1.13.5-00 kubelet=1.13.5-00 kubectl=1.13.5-00
下载安装k8s所需镜像
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-apiserver:v1.13.5
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-controller�manager:v1.13.5
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-scheduler:v1.13.5
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.13.5
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/pause:3.1
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/etcd:3.2.24
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/coredns:1.2.6
初始化 master
kubeadm init --apiserver-advertise-address=192.168.7.101 --apiserver-bind-port=6443 --kubernetes-version=v1.15 --pod-network-cidr=10.10.0.0/16 --service-cidr=10.20.0.0/16 --service-dns-domain=linux36.local --image-repository=registry.cn-hangzhou.aliyuncs.com/google_containers
master 配置 kube 证书
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
部署 flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
node节点加入k8s
kubeadm join 192.168.7.101:6443 --token dzh911.z4sa1rk48xznlu31 --discovery-token-ca-cert-hash sha256:0faae813959a0f45d41be2ae5c4658300a2e4771101cfd2010c745e6bed149dc