Quickly build Kubernetes combat (a) -Kubernetes cluster

From the beginning two years ago, has been concerned about the technological development of Kubernetes ashamed to say, until two years later was to write this column, container development today is already very mature technology, major companies competing to use Kubernetes do container management, the future will be more focus to the study of container-related technologies, such as Kubernetes, Istio, Prometheus, Knative and so on, slowly toward the operation and maintenance to develop their own direction.

I have always believed that divide together for a long, long period of division truth, the world is so, the service is also true micro, micro-services are never limited to a certain framework, I believe to be eliminated in the near future SpringCloud, Dubbo and other micro-services framework will Instead of mature container distributed solutions, that is, I firmly believe that the future of the mind: a container that is service.

A, Kubernetes Profile

What Kubernetes that?

First, it is a new program leading distributed architecture based container technology. Google is an open source version of the Borg (large-scale cluster management system).

Second, if the system design follows the design philosophy Kubernetes, then the traditional system architecture and business is not the underlying code or function module how much the relationship (such as load balancing, service self-care framework, service monitoring, troubleshooting, etc.), can disappear. Use Kubernetes, not only can save at least 30% of the development costs, but also focus on business, and because Kubernetes provides a powerful automated mechanism, so the difficulty of operation and maintenance and operation and maintenance costs later system significantly reduced.

However, Kubernetes is an open platform. And J2EE different, it is not limited in any language, is not limited to any programming interface, regardless of use JAVA, Go, C ++ is written in Python and services, can without difficulty be mapped to Kubernetes of service, and by the standard TCP interact.

In addition, because Kubernetes platform without any invasive to existing programming languages, programming frameworks, middleware, so the existing system is easy upgrading and migrating to Kubernetes platform.

Finally, Kubernetes is a fully distributed system support platform. There is a complete cluster management capabilities, including multi-level security and access mechanism, multi-tenant application support capabilities, transparent service registration and discovery mechanism, built-in intelligent load balancing, a powerful fault detection and self-healing capabilities, service rolling upgrades and online expansion capabilities, scalable mechanism for automatic scheduling of resources, and resource quota management capabilities and more granularity. Meanwhile, Kubernetes provides a complete management tools covered include the development, deployment, testing all aspects, including the operation and maintenance monitoring.

Therefore, Kubernetes is a new distributed architecture based container technology solutions, and a distributed system is a complete development platform and one-stop support.

Second, prepare for work

This column is based on the foundation Centos7 built environment, and the need to install and configure the environment docker Ali cloud image source, related articles I have written, Portal:

Docker and actual combat operation and maintenance (a) -Docker Past and Present

Then we need to close Swap

# 临时关闭swap分区
$ swapoff -a

# 要永久禁掉swap分区,打开如下文件注释掉swap那一行
$ vim /etc/fstab

Close SELinux

# 临时关闭
$ getenforce
$ setenforce 0

# 永久关闭
$ vim /etc/selinux/config  
# 改:7SELINUX=enforcing     #前面的7,表示文档中第7行。方便你查找
# 为:7SELINUX=disabled
$ reboot

Forwarding configuration parameters

# 配置转发相关参数,否则可能会出错
$ cat <<EOF > /etc/sysctl.d/k8s.conf
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
vm.swappiness=0
EOF
$ sysctl --system

Three, Kubernetes Cluster Setup

3.1, install kubeadm and related tools

First configure the source yum, yum official source address is https://packages.cloud.google.com/yumrepos/kubernetes-el7-x86_64 . If you can not access the official website address yum source, you can use a domestic source yum, address http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/ , yum source configuration file / etc /yum.repos.d/kubernetes.repo reads as follows:

[kubernetes]
name=Kubernetes Repository
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0

Then run the yum install command to install kubeadm and related tools:

    $ yum install -y kubeadm-1.14.0 kubectl-1.14.0 kubelet-1.14.0 --disableexcludes=kubernetes

Run the following command to start Docker service (if Docker already installed, you do not start up again) and kubelet service, and is set to boot automatically start:

$ systemctl enable docker && systemctl start docker
$ systemctl enable kubelet && systemctl start kubelet

3.2、kubeadm config

kubeadm GA has entered the stage, the control plane initialization step and join nodes supported by a large number of customizable content, so kubeadm also provides profiles feature for complex customization. Meanwhile, kubeadm save the configuration file in the form of ConfigMap into clusters, to facilitate follow-up queries and upgrades. kubeadm config subcommand provides support for this group of functions (as detailed in "Kubernetes The Definitive Guide, Fourth Edition," 58), for example, to perform kubeadm config print init-defaults, you can get weary of initialization parameter file:

    $ kubeadm config print init-defaults > init.default.yaml

To edit the generated files can be generated on demand appropriate configuration. For example, if the warehouse need to customize the image address, and the address range of the Pod, may be used as follows:

apiVersion: kubeadm.k8s.io/v1beta1
kind: ClusterConfiguration
imageRepository: docker.io/dustise
kubernetesVersion: v1.14.0
networking:
  podSubnet: "192.168.0.0/16"

The stored contents of the above init-config.yaml standby.

3.3, download Kubernetes related image

In order to obtain a mirror acceleration support from the country's image hosting site, proposed changes Docker profile parameter increases Registry Mirror, mirror configuration will write the configuration parameters, such as echo '{ "registry-mirrors": [ "https: // registry .docker-cn.com "]} '> /etc/docker/daemon.json, then restart Docker service.

Use config images pull command to download the desired sub-image, for example:

    $ kubeadm config images pull --config=init-config.yaml

After the image has been downloaded, you can install it.

3.4, run kubeadm init command to install the Master

So far, the preparatory work is ready to execute kubeadm init command to install a key Master of Kubernetes.

Before you begin Note: kubeadm installation process does not involve initialize the network plug-in (CNI), so kubeadm initial installation is complete cluster does not have network functions, including any Pod comes CoreDNS do not work properly. The plug-in installation network tend to have certain requirements on the parameters kubeadm init command. For example, specify --pod-network-cidr = 192.168.0.0 / 16 Calico plug installation details refer https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm / #-POD Network .

Then use kubeadm init command, using the configuration file you created earlier to initialize cluster control surface:

    $ kubeadm init --config=init-config.yaml

After a while, Kubernetes of Master installation is successful, the following message appears:

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.3.206:6443 --token lh8hfg.0alfi6stfzkx2ogw \
    --discovery-token-ca-cert-hash sha256:7a6a6c4a444eb14ad2d93befe8c06ffc87f419f53e5c741c5e9addeff34020d8 

Follow the prompts to execute the following command to copy the configuration file to the average user's home directory:

$ mkdir -p $HOME/.kube
$ sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
$ sudo chown $(id -u):$(id -g) $HOME/.kube/config

This is installed on the Master Kubernetes, but things are not available in the Node cluster, and the lack of network configuration container. It should be noted that after the last few lines kubeadm init command complete message, containing instructions which the joining node (kubeadm join) and the desired Token.

3.5, install Node, join the cluster

For adding a new node, the system is ready and configuration process Kubernetes yum source is the same, do not repeat them here, to join the cluster is in order to break out above command, need only be performed on Node node click on it

kubeadm join 192.168.3.206:6443 --token lh8hfg.0alfi6stfzkx2ogw \
    --discovery-token-ca-cert-hash sha256:7a6a6c4a444eb14ad2d93befe8c06ffc87f419f53e5c741c5e9addeff34020d8 

3.6, install the network plug-in

Kubectl get nodes execute the command, you will find Kubernetes prompt Master is NotReady state, because the CNI network plug-in has not been installed, following the prompts to install the plug-kubeadm of CNI network. For CNI network plug-in, you can have many options, please refer https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/create-cluster-kubeadm/#pod-network explained.

For example, select plug-weave, the following command can be a key to complete the installation:

    $ kubectl apply -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')"

3.7, verify that the cluster installation is complete Kubernetes

Whether to execute the following command to verify Kubernetes cluster of related Pod are properly created and run:

    $ kubectl get pods --all-namespaces

If any error status Pod, may be performed kubectl --namespace = kube-system describe pod <pod_name> to view the cause of the error is the common cause of the error image is not complete download.

By kubeadm tools to achieve a rapid build Kubernetes cluster. If the installation fails, you can perform kubeadm reset command to restore the host, re-execute kubeadm init command to install again.

This Kubernetes Cluster Setup is complete.

Published 352 original articles · won praise 390 · views 370 000 +

Guess you like

Origin blog.csdn.net/qq_19734597/article/details/94890830