The background of this article is that inside the walls...Copy the code
Install Docker
1. Install using an official script
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
2. View doker
docker --version
3. Configure the mirror accelerator
The configuration here is ali cloud, the address cr.console.aliyun.com/cn-hangzhou… , modify it according to the operation document
Install kubeadm
1. Download and add the public key
The curl -s packages.cloud.google.com/apt/doc/apt… | apt-key add –
Note: if you can't download on the server public key, which can in advance in the official website to download to the server, the address https://packages.cloud.google.com/apt/doc/apt-key.gpg add public key apt - key add apt - key. GPGCopy the code
2. Add the Kubernetes source
cat <<EOF >/etc/apt/sources.list.d/kubernetes.list
deb https://apt.kubernetes.io/ kubernetes-xenial main
EOF
Copy the code
3. Install kubeadm
Kubelet, kubectl, kubernetes-cni will be installed automatically when kubeadm is installed
apt-get update
apt-get install -y kubeadm
Copy the code
Note: Docker can be installed with kubeadm here, not tried...Copy the code
3. Deploy the Master node of the K8s cluster
1. View the image used for kubeadm initialization
kubeadm config images list
2. Download the image
Here with the help of the mirror service provided by Ali Cloud, obtain the mirror on GCR. IO, you can search the ready-made mirror directly used, can also build their own.
Note: the address of the https://cr.console.aliyun.com/cn-hangzhou/instances/images search image (self-built warehouse building total failure, so I found as input url, search is not search...)Copy the code
To pull ali cloud image on the server, you need to log in Ali cloud first
You can write a script, including pull, label, delete the original image, execute the script to pull the image. Coredns :v1.8.0 image was not found in the repository, the subsequent direct pull.
Images =(kube-apiserver:v1.21.0 kube-Controller-manager :v1.21.0 kuBE-scheduler :v1.21.0 kuBE-proxy :v1.21.0 pause:3.4.1 Etcd :3.4.13-0) 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 docker rmi registry.cn-hangzhou.aliyuncs.com/google_containers/$imageName doneCopy the code
Pull coredns
$docker pull coredns/coredns: 1.8.0 comes with $docker tag coredns/coredns: 1.8.0 comes with k8s. GCR. IO/coredns/coredns: v1.8.0Copy the code
Initialize kubeadm
$ kubeadm init
Copy the code
$kubeadm init --ignore-preflight-errors=NumCPU $kubeadm init --ignore-preflight-errors=NumCPUCopy the code
The following prompt is displayed after initialization
The kubectl command needs to be executed using kubernetes-admin, so execute it as a normal user as prompted
$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config
Copy the code
Alternatively, run the command as user root
$ echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile
$ source ~/.bash_profile
Copy the code
The last token, used to add a Work node
4. Check the node status of the cluster
Kube-system is the workspace of system Pod reserved by Kubernetes project
Because the network of the Master node is not ready, coreDNS is in Pending state
5. Deploy the network plug-in
Refer to the website of network extension (kubernetes. IO/docs/concep…). Calico is used here
$ wget https://docs.projectcalico.org/manifests/calico.yaml
$ kubectl apply -f calico.yaml
Copy the code
Then check the cluster status
The Master node is now installed
4. Deploy the Work node in the K8s cluster
- Install Docker and Kubeadm on the Work node
- Execute the kubeadm join command generated when the Master node is deployed
$ kubeadm join 172.16.0.7:6443 --token 9mr1az.wx1uau4w4cro4opa --discovery-token-ca-cert-hash sha256:7697ebc577d456d1505e47024dfa403bd9743edb228bdca0d0f55476e83fdc6d
Copy the code
There are no extra servers, so the deployment of the Work node was not attemptedCopy the code
At this point, Kubernetes cluster deployment is complete