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

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 :
https://github.com/kubernetes-incubator/kubespray
<https://github.com/kubernetes-incubator/kubespray>

<> 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 172.31.84.154
Mater,Node CentOS 7.2 2 nucleus 2G 172.31.84.155
Node CentOS 7.2 2 nucleus 2G 172.31.84.156

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'
/etc/sysconfig/selinux
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 .
ssh-keygen
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 :
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
<> install KubeSpray Packages required

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 image

stay kuberspay Source code search contains gcr.io/google_containers <http://gcr.io/google_containers>
and quay.io <http://quay.io> Mirrored files , And replace it with the one we have previously uploaded to alicloud , 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
Replacement by the same principle quay_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
<> 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
--private-key=~/.ssh/id_rsa
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 <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

I refer to the 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>

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