k8s master init and add node
目录
k8s tutorial series main reference
一. add google apt-key
1.vim /etc/apt/source.list (use k8s repository (中科大源))
deb http://us.archive.ubuntu.com/ubuntu/ xenial main restricted
deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
deb http://us.archive.ubuntu.com/ubuntu/ xenial universe
deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates universe
deb http://us.archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
deb http://us.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu xenial-security main restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse
deb http://ppa.launchpad.net/tbfr/zabbix/ubuntu precise main
deb-src http://ppa.launchpad.net/tbfr/zabbix/ubuntu precise main
deb [arch=amd64] https://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main
deb [arch=amd64] https://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main
2.add apt-key
reference add google apt-key
apt-get update && apt-get install -y apt-transport-https
下载apt_key
cat kube_apt_key.gpg | sudo apt-key add -
echo "deb [arch=amd64] https://mirrors.ustc.edu.cn/kubernetes/apt kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list
apt-get update
apt-get install -y kubelet kubeadm kubectl //如果报错去掉-y试试
二. k8s master init
reference kubeadm 搭建 kubernetes 集群
1.change hostname
echo "192-168-43-134.master" > /etc/hostname
echo "127.0.0.1 192-168-43-134.master" >> /etc/hosts
sysctl kernel.hostname=192-168-43-134.master
2.pull images
images=(kube-proxy-amd64:v1.11.0 coredns:1.1.3 pause:3.1 kubedns-amd64:1.7 kube-scheduler-amd64:v1.11.0 kube-controller-manager-amd64:v1.11.0 kube-apiserver-amd64:v1.11.0 etcd-amd64:3.2.18 pause-amd64:3.1)
for imageName in ${images[@]} ; do
docker pull vickeywu/$imageName
docker tag vickeywu/$imageName k8s.gcr.io/$imageName
docker rmi vickeywu/$imageName
done
3.shutdown swap and start kubelet
kubeadm reset
sudo swapoff -a
systemctl daemon-reload
systemctl stop kubelet
systemctl enable kubelet
systemctl start kubelet
4.update kube* (just one time)
apt-get update
apt-get install -y kubelet kubeadm kubectl
5.kubeadm init
kubeadm init --kubernetes-version=v1.11.0 --apiserver-advertise-address 192.168.43.131 --pod-network-cidr=10.244.0.0/16 --skip-preflight-checks
6.copy token from init output(use fork8s nodes join master cluster)
kubeadm join 192.168.43.131:6443 --token 5x4hzc.bauzypcyezrjds06 --discovery-token-ca-cert-hash sha256:a03e0fe800e5a6af55a0238eebfb52b732ec6ac037f850871f54dc863f654130
7.pull network image
docker pull vickeywu/flannel:v0.10.0-amd64
docker tag vickeywu/flannel:v0.10.0-amd64 quay.io/coreos/flannel:v0.10.0-amd64
docker rmi vickeywu/flannel:v0.10.0-amd64
8.run the following as a regular user and root
su vickey
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
echo "source <(kubectl completion bash)" >> ~/.bashrc
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
9.apply network solution
su root
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
echo "source <(kubectl completion bash)" >> ~/.bashrc
三. k8s node add to master cluster(use this command when you wanna add node)
1.repeat some steps on 二.
1,2,3,4,7
2.add to master cluster
kubeadm join 192.168.43.131:6443 --token 5x4hzc.bauzypcyezrjds06 --discovery-token-ca-cert-hash sha256:a03e0fe800e5a6af55a0238eebfb52b732ec6ac037f850871f54dc863f654130