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

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: https://www.alibabacloud.com/campaign/contact-us-feedback. 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