1.master
#!/bin/sh
# please run this script in root mode
apt-get update && apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
systemctl daemon-reload
systemctl restart kubelet
# init cluster with kubeadm and set cidr for flannel
kubeadm init --kubernetes-version=1.15.1 --pod-network-cidr=10.244.0.0/16
sysctl net.bridge.bridge-nf-call-iptables=1
# copy kubeconfig to HOME
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
# install flannel
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ece4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
# remember to save the token for worker node to join like:
#kubeadm join 10.176.2.227:6443 --token a87y01.t7perarnbj3r8mgh --discovery-token-ca-cert-hash sha256:2fa4ebad5542451648009bbfc2adc9c19d69d89812591c835e030fc59c79b5d9
2.slave
#!/bin/sh
apt-get update&&apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg|apt-key add -
cat<<EOF>/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
apt-get update
apt-get install -y kubelet kubeadm kubectl
apt-mark hold kubelet kubeadm kubectl
systemctl daemon-reload
systemctl restart kubelet
注意:
1.kubeadm init --kubernetes-version=1.15.1 --pod-network-cidr=10.244.0.0/16 --apiserver-advertise-address=Ip
2.apt-get install -y kubelet=1..15.1-00 kubeadm=1.15.1-00 kubectl=1.15.1-00