KubeSpray部署k8s集羣
Kubespray 是 Kubernetes incubator 中的項目,目標是提供 Production Ready Kubernetes 部署方案,該項目基礎是經過 Ansible Playbook 來定義系統與 Kubernetes 集羣部署的任務,具備如下幾個特色:node
- l 能夠部署在 AWS, GCE, Azure, OpenStack 以及裸機上.
- l 部署 High Available Kubernetes 集羣.
- l 可組合性 (Composable),可自行選擇 Network Plugin (flannel, calico, canal, weave) 來部署.
- l 支持多種 Linux distributions(CoreOS, Debian Jessie, Ubuntu 16.04, CentOS/RHEL7).
GitHub地址:https://github.com/kubernetes-sigs/kubespraypython
1、環境準備
1)因此的主機都須要關閉selinux,執行的命令以下:linux
setenforce 0 sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
2)防火牆(可選)和網絡設置,全部的主機都執行如下命令:git
systemctl stop firewalld & systemctl disable firewalld modprobe br_netfilter echo '1' > /proc/sys/net/bridge/bridge-nf-call-iptables sysctl -w net.ipv4.ip_forward=1
3)#設置內核參數github
sudo vim /etc/security/limits.conf * soft nofile 32768 * hard nofile 65535 * soft nproc 32768 * hadr nproc 65535
4)設置k8s內核參數vim
sudo vim /etc/sysctl.d/k8s.conf net.bridge.bridge-nf-call-ip6tables = 1 net.bridge.bridge-nf-call-iptables = 1 net.ipv4.ip_nonlocal_bind = 1 net.ipv4.ip_forward = 1 vm.swappiness=0
5)從新加載生效網絡
sudo sysctl --system sudo sysctl -p
6) 安裝 python 及 epel (在Ansible主機上安裝並配置好與各node的免祕鑰登陸)app
yum install -y epel-release python36 python36-pip git
2、部署k8s集羣
1)#克隆項目ui
wget https://github.com/kubernetes-sigs/kubespray/archive/v2.12.4.tar.gz
2)# Install dependencies from ``requirements.txt``spa
sudo /usr/bin/pip3.6 install -r requirements.txt
3)# Copy ``inventory/sample`` as ``inventory/mycluster``
cp -rfp inventory/sample inventory/mycluster
4)# Update Ansible inventory file with inventory builder
declare -a IPS=(10.10.1.3 10.10.1.4 10.10.1.5) CONFIG_FILE=inventory/mycluster/hosts.yaml /usr/bin/python3.6 contrib/inventory_builder/inventory.py ${IPS[@]}
5)# Review and change parameters under ``inventory/mycluster/group_vars``
cat inventory/mycluster/group_vars/all/all.yml cat inventory/mycluster/group_vars/k8s-cluster/k8s-cluster.yml
6)# Deploy Kubespray with Ansible Playbook - run the playbook as root
# The option `--become` is required, as for example writing SSL keys in /etc/,
# installing packages and interacting with various systemd daemons.
# Without --become the playbook will fail to run!
ansible-playbook -i inventory/mycluster/hosts.yaml --become --become-user=root cluster.yml
注意:
一、默認從國外下載鏡像由於node須要能上外網。
二、安裝須要點時間耐心等待,遇到報錯解決後繼續安裝。