Installing master node using kubeadm
1. Basic configuration preparation
# swapoff - Close swap
swapoff -a
sed -ri "/swap/s@(.*)@#/&@g" /etc/fstab
# Firewall limit - Open default iptables rules
echo -e "net.bridge.bridge-nf-call-ip6tables = 1\nnet.bridge.bridge-nf-call-iptables = 1\nnet.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p
#disabled selinux-close SELinux
echo "SELINUX=disabled" > /etc/selinux/config
2. Install dokcer
#install-docker
apt update && apt-get -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common && curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && apt-get update && apt update && apt-get -y install docker-ce=17.06.0~ce-0~debian
3. Install the kube tool
#install kubectl kubelet kubeadm version 1.12.2
apt-get update && apt-get install -y apt-transport-https curl && curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg |apt-key add - && echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" >>/etc/apt/sources.list.d/kubernetes.list && apt update && apt-get install -y kubelet=1.12.2-00 kubeadm kubectl=1.12.2-00
4. Download the required image
# image pull&tag
images=(
kube-apiserver:v1.12.2
kube-controller-manager:v1.12.2
kube-scheduler:v1.12.2
kube-proxy:v1.12.2
pause:3.1
etcd:3.2.24
coredns:1.2.2
pause-amd64:3.1
kubernetes-dashboard-amd64:v1.10.0
heapster-amd64:v1.5.4
heapster-grafana-amd64:v5.0.4
heapster-influxdb-amd64:v1.5.2
)
for imageName in ${images[@]} ; do
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName k8s.gcr.io/$imageName
done
5. Configure kebelet's cgroups and image-repo-mirror
# set image-repo-mirror&cgroups
docker info | grep -i cgroup
echo 'KUBELET_EXTRA_ARGS="--cgroup-driver=cgroupfs --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"' >/etc/default/kubelet
6. Initialize kubeadm init
kubeadm init --kubernetes-version=v1.12.2 --apiserver-advertise-address=10.17.40.80 --pod-network-cidr=192.168.0.0/16
7. Give current users permission to use kubectl
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/rbac-kdd.yaml
kubectl apply -f https://docs.projectcalico.org/v3.3/getting-started/kubernetes/installation/hosted/kubernetes-datastore/calico-networking/1.7/calico.yaml
Join Node Nodes into the Cluster
1. Basic configuration preparation
#forward
echo -e "net.bridge.bridge-nf-call-ip6tables = 1\nnet.bridge.bridge-nf-call-iptables = 1\nnet.ipv4.ip_forward = 1" >> /etc/sysctl.conf
sysctl -p
# disabled swap
swapoff -a
sed -ri "/swap/s@(.*)@#/&@g" /etc/fstab
#disabled selinux
echo "SELINUX=disabled" > /etc/selinux/config
2. Install docker
#install docker
apt update && apt-get -y install apt-transport-https ca-certificates curl gnupg2 software-properties-common && curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable" && apt-get update && apt-cache madison docker-ce && apt update && apt-get -y install docker-ce=17.06.0~ce-0~debian
3. Install kebelet, kubeadm, kubectl
# install kubectl kubelet kubeadm version 1.12.2
apt-get update && apt-get install -y apt-transport-https curl
curl https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg |apt-key add -
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main" >>/etc/apt/sources.list.d/kubernetes.list
apt update
apt-get install -y kubelet=1.12.2-00 kubeadm kubectl=1.12.2-00
4. Download kube-proxy image locally and tag it again
docker pull registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.12.2
docker tag registry.cn-hangzhou.aliyuncs.com/google_containers/kube-proxy:v1.12.2 k8s.gcr.io/kube-proxy:v1.12.2
5. Configure kebelet's cgroups and image-repo-mirror
# set image-repo-mirror&cgroups
docker info | grep -i cgroup
echo 'KUBELET_EXTRA_ARGS="--cgroup-driver=cgroupfs --pod-infra-container-image=registry.cn-hangzhou.aliyuncs.com/google-containers/pause-amd64:3.0"' >/etc/default/kubelet
6. Add node nodes to the cluster
kubeadm join 10.17.40.80:6443 --token qirpum.xiuhtnvipabkqx0q --discovery-token-ca-cert-hash sha256:e2d82dfe71516cbcd64764737e3f20ecf149d2bece14d2befd84b3b16f61bd27
Last note
1. Be careful to close selinux and open forward forwarding
2. If you want to build a cluster of kube-master s
When the first master initializes, you specify all master-etcd-endpoint
And install the master cluster using reverse proxy load; when joining node, the specified master-IP is reverse proxy IP
3. To use the kubectl command, you need to do the following for this user
mkdir -p $HOME/.kube
sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown $(id -u):$(id -g) $HOME/.kube/config