There are two versions of k8S cluster deployment process practice notes: one focuses on deployment operations, and the other describes deployment operations. This article is the former. This article describes how to deploy Kubernetes 1.17.0 cluster on two Ubuntu 16.04 64-bit dual-core CPU VMS using Kubeadm. The network plug-in is Flannel and the image source is Ali Cloud. This paper has some practical reference significance.
A, environmental
Two Ubuntu 16.04 64-bit, 2GB ram, dual-core CPU. Environment requirements and Settings: Two hosts: master and Node. Master The host name is Ubuntu. Node The host name is Node. Ensure that the host name of the operating system is different. The project directory is $HOME/k8s. All operations can be performed with root permission.
The K8S version deployed for this article is 1.17.0.
Install docker
apt-get install docker.io
Copy the code
Add /etc/docker/daemon.json file, add:
{
"registry-mirrors": [
"https://a8qh6yqv.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com"
],
"exec-opts": ["native.cgroupdriver=systemd"]
}
Copy the code
Definition: registry-mirrors specifies the address of the mirror accelerator. Native. cgroupDriver =systemd Indicates that the cgroupdriver is systemd (used by K8S). The default cgroupfs driver is cgroupfs. The reason is that the driver mode of k8S failed to be modified in kubeadm.conf.
Restart docker and check cgroup:
# docker info | grep -i cgroup
Cgroup Driver: systemd
Copy the code
If systemd is displayed, the modification is successful.
3. Deploy k8S master host
The K8S can be deployed on a master host and a node. This section describes the master host.
3.1 close the swap
Edit the /etc/fstab file to comment out the lines mounted by the swap partition, as shown in the following example:
# swap was on /dev/sda5 during installation
UUID=aaa38da3-6e60-4e9d-bfc6-7128fd05f1c7 none swapsw 0 0
Copy the code
To perform:
# sudo swapoff -a
Copy the code
3.2 Adding a Domestic K8S source
Select aliyun here:
# cat <<EOF > /etc/apt/sources.list.d/kubernetes.list
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
Copy the code
Add the key:
# cat https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
Copy the code
If you don’t succeed, first through some method to download: packages.cloud.google.com/apt/doc/apt… And put it in the project directory. To perform:
# cat apt-key.gpg | sudo apt-key add -
Copy the code
3.3 update the source
# apt-get update
Copy the code
Install kubeadm, kubectl, kubelet, kubernetes-cni and other tools.
# apt-get install -y kubeadm kubectl kubelet kubernetes-cni
Copy the code
3.4 Obtaining the Image Version Required for Deployment
# kubeadm config images list
Copy the code
The output is as follows:
K8s. GCR. IO/kube - apiserver: v1.17.0 k8s. GCR. IO/kube - controller - manager: v1.17.0 k8s. GCR. IO/kube - the scheduler: v1.17.0 K8s. GCR. IO/kube - proxy: v1.17.0 k8s. GCR. IO/pause: 3.1 k8s. GCR. IO/etcd: rule 3.4.3-0 k8s. GCR. IO/coredns: 1.6.5Copy the code
The preceding warning messages are ignored. This is the version of the image that kubeadm matches. Compatibility problems may occur due to different component versions.
3.5 Pulling an Image File.
In general, the image of k8s.gcr. IO cannot be downloaded directly in China. There are two ways: 1. When initializing K8S, use ali Cloud image address, which can be downloaded smoothly. See initialization below. 2. Download the above image by yourself.
3.6 the network
After practice, this step can not be done.
3.7 Downloading the Flannel Image
Docker pull quay. IO/coreos/flannel: v0.11.0 - amd64Copy the code
Note: If you cannot download, you need to use another method.
3.8 the initialization
Kubeadm init - pod - network - cidr = 10.244.0.0/16 \ - image - repository registry.aliyuncs.com/google_containersCopy the code
The following information is displayed:
Your Kubernetes control-plane has initialized successfully! To start using your cluster, you need to run the following as a regular user: mkdir -p $HOME/.kube sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config sudo chown $(id -u):$(id -g) $HOME/.kube/config You should now deploy a pod network to the cluster. Run "kubectl apply -f [podnetwork].yaml" with one of the options listed at: https://kubernetes.io/docs/concepts/cluster-administration/addons/ Then you can join any number of worker nodes by running the following on each as root: Kubeadm join 192.168.0.102:6443 --token 1rpp8b. axfud1xRSvx4q8nw \ --discovery-token-ca-cert-hash sha256:6bf952d45bbdc121fa90583eac33f11f0a3f4b491f29996a56fc289363843e3cCopy the code
Copy the admin.conf file to the current user directory as prompted. The admin.conf file will be used later (copy it to node).
# 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
The POD status is as follows:
# kubectl get pods -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-9d85f5447-67qtv 0/1 Pending 0 3h26m
coredns-9d85f5447-cg87c 0/1 Pending 0 3h26m
etcd-ubuntu 1/1 Running 0 3h27m
kube-apiserver-ubuntu 1/1 Running 0 3h27m
kube-controller-manager-ubuntu 1/1 Running 0 3h27m
kube-proxy-chqbq 1/1 Running 0 3h26m
kube-scheduler-ubuntu 1/1 Running 0 3h27m
Copy the code
All pods are running except coreDNS whose status is Pending. This is because the network plug-in is not deployed. Flannel is used in this paper.
3.9 the deployment of flannel
Modify coreDNS ConfigMap:
kubectl edit cm coredns -n kube-system
Copy the code
VIM editing is used by default, and the line in the loop field is deleted (using dd). Enter :wq to save the configuration and exit.
Run the following command to deploy flannel:
# kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Copy the code
Definition: Deploy using the kube-flannel.yml file of the Flannel repository. Please refer to this document for details. If not, you can manually download github.com/coreos/flan… Go to the current directory and run kubectl apply -f kube-flannel.yml.
Note: If flannel is deployed first and then ConfigMap is modified, you need to manually delete all the coreDNS problems. Example:
# kubectl delete pod coredns-9d85f5447-c9wn8 coredns-9d85f5447-tvpbg -n kube-system
Copy the code
A moment later, check pod again:
# kubectl get pod -n kube-system
NAME READY STATUS RESTARTS AGE
coredns-9d85f5447-67qtv 1/1 Running 0 10s
coredns-9d85f5447-cg87c 1/1 Running 0 10s
etcd-ubuntu 1/1 Running 0 3h58m
kube-apiserver-ubuntu 1/1 Running 0 3h58m
kube-controller-manager-ubuntu 1/1 Running 0 3h58m
kube-flannel-ds-amd64-pjj5k 1/1 Running 0 14m
kube-proxy-chqbq 1/1 Running 0 3h57m
kube-scheduler-ubuntu 1/1 Running 0 3h58m
Copy the code
All pods are running. The master node is deployed successfully.
4. Node Node
The K8S can be deployed on a master host and a node. This section describes node nodes.
4.1 Prerequisites
The operation is performed on the node node. 1. Install Kubeadm, as described above. Download the Flannel image, as described above. (If you do not download the Flannel image in advance, it will be downloaded automatically when you join the cluster.) 3, the host of the/etc/kubernetes/admin. Conf file copy to the node node/etc/kubernetes/directory. (Note: Use SCP command on master node.)
4.2 Joining a Cluster
Run the following command to join the node:
Kubeadm join 192.168.0.102:6443 --token 1rpp8b. axfud1xRSvx4q8nw \ --discovery-token-ca-cert-hash sha256:6bf952d45bbdc121fa90583eac33f11f0a3f4b491f29996a56fc289363843e3cCopy the code
Five, validation,
Execute on the master node:
# kubectl get nodes NAME STATUS ROLES AGE VERSION node Ready < None > 17m v1.17.0 Ubuntu Ready Master 5h11m v1.17.0Copy the code
You can see that the two machines are in Ready state.
If the verification succeeds, the K8S is successfully deployed.
The resources
During deployment, refer to the following articles and adjust according to the actual situation:
- Juejin. Cn/post / 684490…
- zhuanlan.zhihu.com/p/46341911
- Kubernetes. IO/docs/setup /… (official)
Kubeadm init - pod - network - cidr = 10.244.0.0/16 \ - image - repository registry.aliyuncs.com/google_containers kubectl edit cm coredns -n kube-system kubectl apply -f kube-flannel.yml kubeadm reset rm -rf $HOME/.kube/config rm -rf /var/lib/cni/ rm -rf /var/lib/kubelet/* rm -rf /etc/kubernetes/ rm -rf /etc/cni/ ifconfig cni0 down ifconfig flannel.1 down ip link delete cni0 ip link delete flannel.1Copy the code