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

Kubespray yes Google Open source a deployment production level Kubernetes Open source project of server cluster , It integrates Ansible As a deployment tool . Project address :

<> Deployment history

So far , about Kubernetes Cluster deployment , I'm only talking about a beginner , It involves a lot of operation and maintenance knowledge , For a development , It's really hard . Everything is difficult at the beginning , the road to happiness is strewn with setbacks , After more than a week of repeated attempts , It's finally set up . Compare the deployment methods on the market , The mainstream has three ways . One is full manual deployment , It's very complicated , Easy to deploy . The second is the adoption of kubeAdmin Open source project deployment , This is also an official open source project of Google . Third, it is , use kubeSpray Deploy . My idea is to have good tools, of course, to use them , So manual deployment is not possible , Total exclusion , therefore Kubeadmin and KubeSpray. And I'm right Ansibe This operation and maintenance component is very interesting , So I finally chose KubeSpray Deployed .

The deployment of the project is very difficult , I decided to do it Kubernetes Time of day , In order to learn is not difficult? Boring and lonely , I set up a group , I found some friends to study and communicate with each other , The way is to learn together , Write the document together , Communicate together , In addition, there are hosts out of the host . therefore , At the beginning of the host is a few friends own host , Not in a LAN , The computer operating system is also different , This has brought a big hole for the later deployment . In addition, due to the domestic block of Google's network , As a result, Google's relevant image cannot be downloaded , This is also a pit .

Pit point 1, Cannot deploy without a LAN Kubernetes? I called Alibaba cloud , The customer said no , Is it really not possible , I'm not sure . In addition, different cluster models and operating systems can also lead to failure .

Pit point 2, The great wall blocks Google's image , So at the beginning, I searched Alibaba cloud image warehouse according to Google's image , cause Kubernetes Incompatible components of different versions , Something went wrong .

Now I'll explain my deployment process in detail , For others' reference , If anyone else wants to join us Kubernetes Interest groups , make me your WeChat friend miles02 Contact me .

<> Host related

The host needs to be in the same LAN ? So we re rented three machines , The operation was carried out . Now list the host related information as follows :

host System version to configure ip
Ansible CentOS 7.2 1 nucleus 1G
Mater,Node CentOS 7.2 2 nucleus 2G
Node CentOS 7.2 2 nucleus 2G

Ansible Which host uses KubeSpray Deploy , This machine doesn't do it Kubernetes Deployment of related clusters . in addition 2 Machines , One is as good as the other Master, As well as Node, The other one is one Node.

This deployment , Used KubeSpray Version is v2.1.2.

<>Master,Node Operation of nodes

Because of this use KubeSpray Operational deployment , So all hosts need to close the firewall and other related operations .

All hosts need to be shut down selinux, The order to execute is as follows :
setenforce 0 sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g'
Firewall and network settings , All hosts execute the following command :
systemctl stop firewalld modprobe br_netfilter echo '1' >
/proc/sys/net/bridge/bridge-nf-call-iptables sysctl -w net.ipv4.ip_forward=1
In this way, with Kubernetes Cluster related cluster settings are completed .

<>Ansibe Host operation

Ansibe The host also needs to be shut down selinux And turn off the firewall and network settings , Same as above .

<> stay Ansible Set password free operation on the host computer

First generate ssh Public and private keys .
Press enter three times .

establish ssh passageway , Distribute the key to master host .
ssh-copy-id [email protected] ssh-copy-id [email protected]
<> install Ansible

install ansible and jinja2, The installation command is as follows .
sudo yum install epel-release sudo yum install ansible easy_install pip pip2
install jinja2 --upgrade
If implemented pip2 install jinja2–upgrade Prompt for upgrade , Then upgrade , One more command .

<> install python36
sudo yum install python36 -y
<> stay Ansible Install on Cluster KubeSpray

stay ansible Download on machine KubeSpray code , And unzip it , Execute the following command :
tar -zxvf v2.1.2.tar.gz mv kubespray-2.1.2 kuberspray
<> install KubeSpray Packages required

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 image

stay kuberspay Source code search contains <>
and <> Mirrored files , And replace it with the one we have previously uploaded to alicloud , 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
Replacement by the same principle quay_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
<> use ansible playbook deploy Kubernetes colony

All of the above are completed , Perform the installation operation :
cd kubespray ansible-playbook -i inventory/inventory.cfg cluster.yml -b -v
About 10 minute , If it goes well , The cluster will be built successfully .

<> Verify the success of several points

Sign in Kubernete Clustered Mater colony , Execute the following command :
kubectl get no
The console printed the correct Kubernetes Node information , The installation is successful .

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

ansible Perform the unload operation :
ansible-playbook -i inventory/mycluster/hosts.ini reset.yml
Installation failure cleanup Kubernetes 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

I refer to the article :

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