Please indicate the source of reprint:
This article comes from Fang Zhipeng's blog <>

Kubespray yesGoogle An open source deployment production levelKubernetes Open source project of server cluster, It integrated.Ansible As a deployment tool. Project address:

<> 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
Mater,Node CentOS 7.2 2 nucleus2G
Node CentOS 7.2 2 nucleus2G

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'
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.
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:
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.
CONFIG_FILE=./kubespray/inventory/inventory.cfg python36
./kubespray/contrib/inventory_builder/ ${IP[*]}
vim ~./kubespray/inventory/inventory.cfg
[all] node1 ansible_host= ip= node2
ansible_host= ip= [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 <> <> Mirrored files, And replace it with the one we uploaded to Alibaba cloud before, The replacement steps are as follows:
./kubespray/roles/kubernetes-apps/ansible/defaults/main.yml )
In execution
for file in ${grc_image_files[@]} ; do sed -i
$file done
Simultaneous replacementquay_image:
./kubespray/roles/download/defaults/main.yml )
Re execution:
for file in ${quay_image_files[@]} ; do sed -i
$file sed -i
$file sed -i
$file done
<> Useansible playbook deployKubernetes colony

All of the above, Perform installation:
cd kubespray ansible-playbook -i inventory/inventory.cfg cluster.yml -b -v
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 <>

SpringBoot Tutorial summary <>

Java Interview question series summary <>

<> Reference material

Refer to the following article:

* Pay attention to my official account. Wonderful content can't be missed!