使用Kubespray在虛擬機上部署Kubernetes
阿新 • • 發佈:2017-12-24
kubernetesKubespray 是 Kubernetes incubator 中的項目,目標是提供 Production Ready Kubernetes 部署方案,該項目基礎是通過 Ansible Playbook 來定義系統與 Kubernetes 集群部署的任務,具有以下幾個特點:
可以部署在 AWS, GCE, Azure, OpenStack以及裸機上.
部署 High Available Kubernetes 集群.
可組合性(Composable),可自行選擇 Network Plugin (flannel, calico, canal, weave) 來部署.
支持多種 Linux distributions(CoreOS, Debian Jessie, Ubuntu 16.04, CentOS/RHEL7)
一、環境介紹
宿主機Ubuntu17.10,也是ansible主機
kubernetes v1.8.3
etcd v3.2.4
calico v2.5.0
docker 17.03
Centos 7.4
二、安裝前準備
1、ansible安裝最新ansible,我這是 Ubuntu 其他系統
$ sudo apt-get update
$ sudo apt-get install software-properties-common
$ sudo apt-add-repository ppa:ansible/ansible
$ sudo apt-get update
$ sudo apt-get install ansible python-netaddr python-pbr
2、下載kubespary,這是我修改過的 官方的
git clone https://github.com/bravem/ansible-k8s.git
3、虛擬機安裝docker
yum install docker-engine-17.03.1.ce-1.el7.centos -y
4、下載鏡像
kubespray/roles/download/defaults/main.yml 這個文件定義了鏡像版本,按照這文件提前下載所需鏡像
下載後直接上傳至虛擬機
gcr.io/google_containers/kubernetes-dashboard-amd64:v1.8.1
gcr.io/google_containers/hyperkube:v1.8.3
lachlanevenson/k8s-helm:2.7.0
gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.7
gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.7
gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.7
andyshinn/dnsmasq:2.78
quay.io/calico/ctl:v1.5.0
quay.io/calico/node:v2.5.0
quay.io/calico/kube-policy-controller:v0.7.0
xueshanf/install-socat:latest
quay.io/calico/cni:v1.10.0
quay.io/calico/routereflector:v0.4.0
quay.io/coreos/etcd:v3.2.4
gcr.io/google_containers/cluster-proportional-autoscaler-amd64:1.1.1
gcr.io/google_containers/fluentd-elasticsearch:1.22
gcr.io/google_containers/elasticsearch:v2.4.1
gcr.io/google_containers/kibana:v4.6.1
nginx:1.11.4-alpine
gcr.io/google_containers/pause-amd64:3.0
5、修改inventory文件IP地址
[all]
node1 ansible_host=192.168.1.121 ip=192.168.1.121 ansible_user=root
node2 ansible_host=192.168.1.122 ip=192.168.1.122 ansible_user=root
node3 ansible_host=192.168.1.123 ip=192.168.1.123 ansible_user=root
node4 ansible_host=192.168.1.124 ip=192.168.1.124 ansible_user=root
node5 ansible_host=192.168.1.125 ip=192.168.1.125 ansible_user=root
node6 ansible_host=192.168.1.126 ip=192.168.1.126 ansible_user=root
[kube-master]
node1
[kube-node]
node2
node3
[etcd]
node1
node2
node3
[k8s-cluster:children]
kube-node
kube-master
6、修改sshkkeys.exp文件IP地址,這是expect腳步,用來復制ssh秘鑰
#!/usr/bin/expect -f
set timeout -1
set user root
set passwd "password"
for { set i 121 } { $i < 124 } { incr i } {
spawn ssh-copy-id [email protected].$i
expect {
"yes/no" { send "yes\r";exp_continue }
"id_rsa" { send "yes\r";exp_continue }
"*assword" { send "$passwd\r" }
}
}
expect eof
三、安裝
1、復制ssh秘鑰,需安裝expect,或者手動添加
expect sshkeys.exp
2、安裝
ansible-playbook -i inventory/inventory.cfg cluster.yml
3、完成
三、集群擴展
1、修改inventory文件,把新主機加入Master或者Node組
[all]
node1 ansible_host=192.168.1.121 ip=192.168.1.121 ansible_user=root
node2 ansible_host=192.168.1.122 ip=192.168.1.122 ansible_user=root
node3 ansible_host=192.168.1.123 ip=192.168.1.123 ansible_user=root
node4 ansible_host=192.168.1.124 ip=192.168.1.124 ansible_user=root
node5 ansible_host=192.168.1.125 ip=192.168.1.125 ansible_user=root
node6 ansible_host=192.168.1.126 ip=192.168.1.126 ansible_user=root
[kube-master]
node1
node5
[kube-node]
node2
node3
node4
.....
2、安裝
ansible-playbook -i inventory/inventory.cfg cluster.yml --limit node4,node5
3、完成
使用Kubespray在虛擬機上部署Kubernetes