請讀者務必保持環境一致node
安裝過程當中須要下載所需系統包,請務必使全部節點連上互聯網。python
實驗環境:VMware的虛擬機linux
IP地址 | 主機名 | CPU | 內存 |
---|---|---|---|
192.168.77.133 | k8s-m1 | 6核 | 6G |
192.168.77.134 | k8s-m2 | 6核 | 6G |
192.168.77.135 | k8s-m3 | 6核 | 6G |
192.168.77.136 | k8s-n1 | 6核 | 6G |
192.168.77.137 | k8s-n2 | 6核 | 6G |
192.168.77.138 | k8s-n3 | 6核 | 6G |
另外由全部 master節點提供一組VIP 192.168.77.140
。nginx
ansible role怎麼用請看下面文章git
以static pod方式安裝kubernetes ha高可用集羣。github
OS: CentOS Linux release 7.4.1708 (Core)
ansible: 2.5.3
docker
# yum -y install ansible # ansible --version ansible 2.5.3 config file = /etc/ansible/ansible.cfg configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /usr/bin/ansible python version = 2.7.5 (default, Aug 4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]
# sed -i 's|#host_key_checking|host_key_checking|g' /etc/ansible/ansible.cfg
# yum -y install git # git clone https://github.com/kuailemy123/Ansible-roles.git /etc/ansible/roles 正克隆到 '/etc/ansible/roles'... remote: Counting objects: 1767, done. remote: Compressing objects: 100% (20/20), done. remote: Total 1767 (delta 5), reused 24 (delta 4), pack-reused 1738 接收對象中: 100% (1767/1767), 427.96 KiB | 277.00 KiB/s, done. 處理 delta 中: 100% (639/639), done.
這是爲了適應國情,導出所需的谷歌docker image,方便你們使用。api
文件下載連接:https://pan.baidu.com/s/1BNMJLEVzCE8pvegtT7xjyQ
密碼:qm4k
bash
# yum -y install unzip # unzip kubernetes-files.zip -d /etc/ansible/roles/kubernetes/files/
# cat /etc/ansible/hosts [k8s-master] 192.168.77.133 192.168.77.134 192.168.77.135 [k8s-node] 192.168.77.136 192.168.77.137 192.168.77.138 [k8s-cluster:children] k8s-master k8s-node [k8s-cluster:vars] ansible_ssh_pass=123456
k8s-master
組爲全部的master節點主機。k8s-node
組爲全部的node節點主機。k8s-cluster
包含k8s-master
和k8s-node
組的全部主機。服務器
請注意, 主機名稱請用小寫字母, 大寫字母會出現找不到主機的問題。
# cat /etc/ansible/k8s.yml --- # 初始化集羣 - hosts: k8s-cluster serial: "100%" any_errors_fatal: true vars: - ipnames: '192.168.77.133': 'k8s-m1' '192.168.77.134': 'k8s-m2' '192.168.77.135': 'k8s-m3' '192.168.77.136': 'k8s-n1' '192.168.77.137': 'k8s-n2' '192.168.77.138': 'k8s-n3' roles: - hostnames - repo-epel - docker # 安裝master節點 - hosts: k8s-master any_errors_fatal: true vars: - kubernetes_master: true - kubernetes_apiserver_vip: 192.168.77.140 roles: - kubernetes # 安裝node節點 - hosts: k8s-node any_errors_fatal: true vars: - kubernetes_node: true - kubernetes_apiserver_vip: 192.168.77.140 roles: - kubernetes # 安裝addons應用 - hosts: k8s-master any_errors_fatal: true vars: - kubernetes_addons: true - kubernetes_ingress_controller: nginx - kubernetes_apiserver_vip: 192.168.77.140 roles: - kubernetes
kubernetes_ingress_controller 還能夠選擇
traefik
# ansible-playbook /etc/ansible/k8s.yml ...... real 26m44.153s user 1m53.698s sys 0m55.509s
# kubectl version Client Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:17:39Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"} Server Version: version.Info{Major:"1", Minor:"10", GitVersion:"v1.10.3", GitCommit:"2bba0127d85d5a46ab4b778548be28623b32d0b0", GitTreeState:"clean", BuildDate:"2018-05-21T09:05:37Z", GoVersion:"go1.9.3", Compiler:"gc", Platform:"linux/amd64"}
kubectl -n kube-system get po -o wide -l k8s-app=kube-proxy
kubectl -n kube-system get po -l k8s-app=kube-dns
kubectl -n kube-system get po -l k8s-app=calico-node -o wide
calicoctl node status
kubectl -n kube-system get po,svc -l k8s-app=kubernetes-dashboard
kubectl -n kube-system get po,svc | grep -E 'monitoring|heapster|influxdb' kubectl -n ingress-nginx get pods kubectl -n kube-system get po -l app=helm kubectl -n kube-system logs -f kube-scheduler-k8s-m2 helm version
這裏就不寫結果了。
在第一臺master服務器上
kubectl cluster-info
Kubernetes master is running at https://192.168.77.140:6443 Elasticsearch is running at https://192.168.77.140:6443/api/v1/namespaces/kube-system/services/elasticsearch-logging/proxy heapster is running at https://192.168.77.140:6443/api/v1/namespaces/kube-system/services/heapster/proxy Kibana is running at https://192.168.77.140:6443/api/v1/namespaces/kube-system/services/kibana-logging/proxy kube-dns is running at https://192.168.77.140:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy monitoring-grafana is running at https://192.168.77.140:6443/api/v1/namespaces/kube-system/services/monitoring-grafana/proxy monitoring-influxdb is running at https://192.168.77.140:6443/api/v1/namespaces/kube-system/services/monitoring-influxdb:http/proxy
# cat ~/k8s_addons_access
集羣部署完成後,建議重啓集羣全部節點。