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

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

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 | apt-key add -cat <<EOF >/etc/apt/sources.list.d/kubernetes.listdeb kubernetes-xenial mainEOFapt-get updateapt-get install -y kubelet kubeadm kubectl

For kubeadm create Cluster

for more information, see

initialize Master

run the following command on the Master:

kubeadm init --apiserver-advertise-address --pod-network-cidr=

--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 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.


1. Play Docker container technology in 5 minutes every day 2. Play OpenStack in 5 minutes every day

Please read this disclaimer carefully before you start to use the service. By using the service, you acknowledge that you have agreed to and accepted the content of this disclaimer in full. You may choose not to use the service if you do not agree to this disclaimer. This document is automatically generated based on public content on the Internet captured by Machine Learning Platform for AI. The copyright of the information in this document, such as web pages, images, and data, belongs to their respective author and publisher. Such automatically generated content does not reflect the views or opinions of Alibaba Cloud. It is your responsibility to determine the legality, accuracy, authenticity, practicality, and completeness of the content. We recommend that you consult a professional if you have any doubt in this regard. Alibaba Cloud accepts no responsibility for any consequences on account of your use of the content without verification. If you have feedback or you find that this document uses some content in which you have rights and interests, please contact us through this link: We will handle the matter according to relevant regulations.
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