Please indicate the source of reprint:
http://blog.csdn.net/forezp/article/details/82730382
<http://blog.csdn.net/forezp/article/details/82730382>
This article comes from Fang Zhipeng's blog <http://blog.csdn.net/forezp>

Kubespray yesGoogle An open source deployment production levelKubernetes Open source project of server cluster, It integrated.Ansible As a deployment tool. Project address:
https://github.com/kubernetes-incubator/kubespray
<https://github.com/kubernetes-incubator/kubespray>

<> Deployment history


So far, aboutKubernetes Cluster deployment, I'm just talking about being a doorman. It involves a lot of operation and maintenance knowledge. For a development, It's really hard. It's hard at the beginning, The road to happiness is strewn with setbacks, After more than a week of trial and error, It's finally set up. Compare the deployment methods on the market, There are three main ways. First, fully manual deployment, Very complicated, Easy deployment. The two is to adoptkubeAdmin Open source project deployment, This is also an official open source project of Google.. Three is, UsekubeSpray Deployment. My idea is to have good tools, of course, to use them well. So manual deployment is not possible. Completely exclude, thereforeKubeadmin andKubeSpray. And I am right.Ansibe This operation and maintenance component is of great interest. So I finally choseKubeSpray Deployed.


The deployment project is very difficult, When I decided toKubernetes At that time, It's not hard to learn. It's boring and lonely. I formed a group, Find some friends to study and communicate with, The way is to learn together. Document together, Communicate together, In addition, there are outgoing hosts. therefore, At the beginning of the host is a few friends' own host, Not in a LAN, Computer operating system is not the same, It's a big hole for later deployment.. In addition, due to the domestic blocking of Google's network, Cause Google's related image can't be downloaded, This is also a pit.


Pit point1, Can't deploy without a LANKubernetes? I called Alibaba cloud specifically, The customer said no, Is it really not possible, I'm not sure. In addition, different models of clusters and different operating systems also lead to failure..

Pit point2, Great wall blocks Google's image, So I started to search Alibaba cloud image warehouse based on Google image. causeKubernetes Incompatible versions of components, Something's wrong.

Now I'm going to explain my deployment process in detail in this article. For others' reference, If someone else wants to join usKubernetes Interest group, Make me your WeChat friendmiles02 Contact me.

<> Host related

The host needs to be in the same LAN? So we rented three machines again. Operation has been carried out. Now list the information about the host as follows:

Host System version To configure ip
Ansible CentOS 7.2 1 nucleus1G 172.31.84.154
Mater,Node CentOS 7.2 2 nucleus2G 172.31.84.155
Node CentOS 7.2 2 nucleus2G 172.31.84.156

Ansible That host is in useKubeSpray Deployment, This machine doesn't workKubernetes Deployment of related clusters. in addition2 Taiwan machine, One as wellMaster, Also asNode, The other one is aNode.

This deployment, UsedKubeSpray Version isv2.1.2.

<>Master,Node Operation of nodes

Because of this useKubeSpray Operational deployment, So all hosts need to shut down the firewall and other related operations..

All hosts need to be shut downselinux, The command executed is as follows:
setenforce 0 sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g'
/etc/sysconfig/selinux
Firewall and network settings, All hosts execute the following commands:
systemctl stop firewalld modprobe br_netfilter echo '1' >
/proc/sys/net/bridge/bridge-nf-call-iptables sysctl -w net.ipv4.ip_forward=1
So andKubernetes Cluster related cluster settings are finished.

<>Ansibe Host operation

Ansibe The host also needs to be shut downselinux And turn off firewalls and network settings, Same as above.

<> stayAnsible Set password free operation on other hosts

First generationssh Public key and private key.
ssh-keygen
Press enter three times.

establishssh passageway, Distribute secret keymaster Host.
ssh-copy-id [email protected] ssh-copy-id [email protected]
<> installAnsible

installansible andjinja2, The installation command is as follows.
sudo yum install epel-release sudo yum install ansible easy_install pip pip2
install jinja2 --upgrade
If executed pip2 install jinja2–upgrade Prompt upgrade, Upgrade, Execute the command again.

<> installpython36
sudo yum install python36 -y
<> stayAnsible Install on ClusterKubeSpray

stayansible Download on machineKubeSpray Code, Decompression, Execute the following command:
wget https://github.com/kubernetes-incubator/kubespray/archive/v2.1.2.tar.gz
tar -zxvf v2.1.2.tar.gz mv kubespray-2.1.2 kuberspray
<> installKubeSpray Required package

Execute the following command:
cd kubespray pip install -r requirements.txt
<> Defining clusters

Execute the following command.
IP=(172.31.84.155 172.31.84.156)
CONFIG_FILE=./kubespray/inventory/inventory.cfg python36
./kubespray/contrib/inventory_builder/inventory.py ${IP[*]}
vim ~./kubespray/inventory/inventory.cfg
[all] node1 ansible_host=172.31.84.156 ip=172.31.84.156 node2
ansible_host=172.31.84.155 ip=172.31.84.155 [kube-master] node1 [kube-node]
node1 node2 [etcd] node1 [k8s-cluster:children] kube-node kube-master
[calico-rr] [vault] node1
<> Replace mirroring

staykuberspay Source code search contains gcr.io/google_containers <http://gcr.io/google_containers>
andquay.io <http://quay.io> Mirrored files, And replace it with the one we uploaded to Alibaba cloud before. The replacement steps are as follows:
grc_image_files=(
./kubespray/extra_playbooks/roles/dnsmasq/templates/dnsmasq-autoscaler.yml
./kubespray/extra_playbooks/roles/download/defaults/main.yml
./kubespray/extra_playbooks/roles/kubernetes-apps/ansible/defaults/main.yml
./kubespray/roles/download/defaults/main.yml
./kubespray/roles/dnsmasq/templates/dnsmasq-autoscaler.yml
./kubespray/roles/kubernetes-apps/ansible/defaults/main.yml )
In execution
for file in ${grc_image_files[@]} ; do sed -i
's/gcr.io\/google_containers/registry.cn-hangzhou.aliyuncs.com\/szss_k8s/g'
$file done
Simultaneous replacementquay_image:
quay_image_files=(
./kubespray/extra_playbooks/roles/download/defaults/main.yml
./kubespray/roles/download/defaults/main.yml )
Re execution:
for file in ${quay_image_files[@]} ; do sed -i
's/quay.io\/coreos\//registry.cn-hangzhou.aliyuncs.com\/szss_quay_io\/coreos-/g'
$file sed -i
's/quay.io\/calico\//registry.cn-hangzhou.aliyuncs.com\/szss_quay_io\/calico-/g'
$file sed -i
's/quay.io\/l23network\//registry.cn-hangzhou.aliyuncs.com\/szss_quay_io\/l23network-/g'
$file done
<> Useansible playbook deployKubernetes colony

All of the above, Perform installation:
cd kubespray ansible-playbook -i inventory/inventory.cfg cluster.yml -b -v
--private-key=~/.ssh/id_rsa
It's over.10 Minute, If it goes well, Cluster will be built successfully.

<> Verify the success of several points

Sign inKubernete ClusteredMater colony, Execute the following command:
kubectl get no
The console printed the correctKubernetes Node information, Installation succeeded.

<> Add node
cd kubespray ansible-playbook -i inventory/inventory.cfg cluster.yml -b -v
--private-key=~/.ssh/id_rsa --limit node3
<> Uninstall encountered problems

ansible Perform uninstall operation:
ansible-playbook -i inventory/mycluster/hosts.ini reset.yml
Installation failure cleanupKubernetes machine
rm -rf /etc/kubernetes/ rm -rf /var/lib/kubelet rm -rf /var/lib/etcd rm -rf
/usr/local/bin/kubectl rm -rf /etc/systemd/system/calico-node.service rm -rf
/etc/systemd/system/kubelet.service systemctl stop etcd.service systemctl
disable etcd.service systemctl stop calico-node.service systemctl disable
calico-node.service docker stop $(docker ps -q) docker rm $(docker ps -a -q)
service docker restart
<> More reading

The simplest in history SpringCloud Tutorial summary <https://blog.csdn.net/forezp/article/details/70148833>

SpringBoot Tutorial summary <https://blog.csdn.net/forezp/article/details/70341818>

Java Interview question series summary <https://blog.csdn.net/forezp/article/details/85163411>

<> Reference material

Refer to the following article:

https://github.com/kubernetes-incubator/kubespray
<https://github.com/kubernetes-incubator/kubespray>

https://mp.weixin.qq.com/s/-SXuXhY7KIFl1zYvVT93ZA
<https://mp.weixin.qq.com/s/-SXuXhY7KIFl1zYvVT93ZA>

https://blog.csdn.net/zhuchuangang/article/details/77712614
<https://blog.csdn.net/zhuchuangang/article/details/77712614>

* Follow my public account, Wonderful content can't be missed!