Today we came to the most interesting part, which is to deploy our K8S cluster service. In a typical cluster environment, there are no clusters, so we usually need 3 servers for a minimum unit, as shown in the figure below.

K8s-master is the master node. K8s-node1 and K8S-node2 are nodes or slave nodes.

Centos is the most commonly used system in China. In order to facilitate the use of Ubuntu, yes, because apt software library is really powerful.

We installed can refer to https://kubernetes.io/docs/setup/independent/install-kubeadm

Note that all components of K8S and Docker images are placed on Google’s own website, which was also dropped by the wall, but fortunately Ali is the best service platform supporters in China, but also the contributor of domestic software, because he made Ali cloud service third in the world, these sources are also provided. We need to modify it ourselves

General enterprises will not build their own K8S, are to buy Ali Cloud or Rander, here it would be good to know about it

Install Dokcer All nodes need to install Docker

apt-get update && apt-get install docker.io
Copy the code

Install kubelet, kubeadm and kubectl

All nodes must be installed

  1. Kubelet runs on all nodes of the cluster, responsible for starting pods and containers
  2. Kubeadm: used to initialize a cluster
  3. Kubectl (command line console) CRUD resources and containers
$auth = $auth = $auth = $auth = $auth = $auth = $auth = $auth = $auth = $auth = $auth = $auth = $auth = $auth = $auth https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | apt-key add - cat <<EOF >/etc/apt/sources.list.d/kubernetes.list deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main EOF apt-get update apt-get install -y kubelet kubeadm kubectlCopy the code

Initialize the Master

Kubeadm init-apiserver-advertise-address 192.168.65.120 --pod-netword-cidr=10.244.0.0/16Copy the code

-apiserver-advertise-address Indicates that the interface of the Master is used to communicate with other nodes in the Cluster.

— POd-netword-cidR is the pod network scope

Copy the mkidr part of the operation. And see that join thing? That one is operated on the node host.

K8s does something during initialization

  1. K8s Check before execution
  2. Generate tokens and certificates
  3. Generate the KubeConfig file that Kubelet needs to communicate with the Master
  4. Installing the Master component will download the Docker image from Registry in Google
  5. Install kube-proxy and kube-DNS
  6. K8s initial completed
  7. Prompts you to configure Kubectl
  8. Tips on how to install Pod network

9. How do I register other nodes to a Cluster

Configuration Kubectl

# # it is actually just after the success of the things the su - ubuntu mkdir -p $HOME /. Kube sudo cp - I/etc/kubernetes/admin. Config $HOME /. Kube/config sudo shown $(id -u):$(id -g) $HOME/.kube/configCopy the code

Installing a Pod Network

The flannel has to be installed for the cluster to work, otherwise the Pod will not be able to communicate. There are a number of networking solutions

kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
Copy the code

We can then add nodes for node1 and node2, copying the commands just init

Kubeadm join --token d38a01.1361dsfdfg980 192.168.65.120:6443Copy the code

We can view the nodes by kubectl get nodes