Deploy k8s Cluster (part 1)-play Docker container technology for 5 minutes every day (118)-Alibaba Cloud Developer Community

We will deploy the Kubernetes Cluster of the three nodes.

k8s-master is a Master, and k8s-node1 and k8s-node2 are nodes.

The operating system of all nodes is Ubuntu 16.04. Of course, other Linux nodes are also available.

For more information, see https://kubernetes.io/docs/setup/independent/install-kubeadm/

note: Kubernetes, almost all installation components and Docker images are stored on goolge's own website, which may be a big obstacle for domestic employees. The suggestion is: we must find ways to overcome the network obstacles, otherwise we can't even enter the door of the Kubernetes.

Install Docker

Docker must be installed on all nodes.

apt-get update && apt-get install docker.io

Mounting kubelet, kubeadm and kubectl

install kubelet, kubeadm, and kubectl on all nodes.

kubelet runs on all nodes of the Cluster and starts pods and containers.

kubeadm is used to initialize Cluster.

kubectl is Kubernetes command line tool. kubectl allows you to deploy and manage applications, view various resources, and create, delete, and update various components.

apt-get update && apt-get install -y apt-transport-httpscurl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add -cat <<EOF >/etc/apt/sources.list.d/kubernetes.listdeb http://apt.kubernetes.io/ kubernetes-xenial mainEOFapt-get updateapt-get install -y kubelet kubeadm kubectl

For kubeadm create Cluster

for more information, see https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/

initialize Master

run the following command on the Master:

kubeadm init --apiserver-advertise-address 192.168.56.105 --pod-network-cidr=10.244.0.0/16

--apiserver-advertise-addressindicates which interface of the Master is used to communicate with other nodes of the Cluster. If the Master with multiple interface, recommendations explicitly specified, if you do not specify, kubeadm automatically selector with of the default gateway interface.

--pod-network-cidrThe range of the Pod network. Kubernetes supports multiple network solutions. --pod-network-cidrHave your own requirements, set here 10.244.0.0/16this is because we will use the flannel network solution, which must be set to this CIDR block. In the following practice, we will switch to other network solutions, such as Canal.

The initialization process is as follows:

① kubeadm performs the pre-initialization check.

(2) generate tokens and certificates.

③ generate KubeConfig file. kubelet needs this file to communicate with the Master.

(4) when installing the Master component, the Docker image of the component is downloaded from the Registry of goolge. This step may take some time, mainly depending on the network quality.

⑤ install kube-proxy and kube-dns.

⑥ the Kubernetes Master is initialized.

⑦Prompt how to configure kubectl, which will be practiced later.

⑧ you are prompted how to install the Pod network, which will be practiced later.

**This topic describes how to register other nodes to Cluster.

Configuration kubectl

kubectl is a command line tool for managing Kubernetes Cluster. We have installed kubectl on all nodes. After the Master is initialized, some configuration work needs to be done before kubectl can be used.

In accordance kubeadm initin step ⑦ of the output, we recommend that you run kubectl for Linux users (root may have some problems).

Configure kubectl for ubuntu users:

su - ubuntumkdir -p $HOME/.kubesudo 
cp -i /etc/kubernetes/admin.conf $HOME/.kube/configsudo 
chown $(id -u):$(id -g) $HOME/.kube/config

to make it easier to use, enable the automatic completion feature of the kubectl command.

echo "source <(kubectl completion bash)" >> ~/.bashrc

In this way, ubuntu users can use kubectl.

In the next section, we will install the Pod network and add k8s-node1 and k8s-node2 to complete the cluster deployment.

Books:

1. Play Docker container technology in 5 minutes every day https://item.jd.com/16936307278.html 2. Play OpenStack in 5 minutes every day https://item.jd.com/12086376.html

Selected, One-Stop Store for Enterprise Applications
Support various scenarios to meet companies' needs at different stages of development

Start Building Today with a Free Trial to 50+ Products

Learn and experience the power of Alibaba Cloud.

Sign Up Now