使用Kubespray在虚拟机上部署Kubernetes

Kubespray 是 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.1gcr.io/google_containers/hyperkube:v1.8.3lachlanevenson/k8s-helm:2.7.0gcr.io/google_containers/k8s-dns-sidecar-amd64:1.14.7gcr.io/google_containers/k8s-dns-kube-dns-amd64:1.14.7gcr.io/google_containers/k8s-dns-dnsmasq-nanny-amd64:1.14.7andyshinn/dnsmasq:2.78quay.io/calico/ctl:v1.5.0quay.io/calico/node:v2.5.0quay.io/calico/kube-policy-controller:v0.7.0xueshanf/install-socat:latestquay.io/calico/cni:v1.10.0quay.io/calico/routereflector:v0.4.0quay.io/coreos/etcd:v3.2.4gcr.io/google_containers/cluster-proportional-autoscaler-amd64:1.1.1gcr.io/google_containers/fluentd-elasticsearch:1.22gcr.io/google_containers/elasticsearch:v2.4.1gcr.io/google_containers/kibana:v4.6.1nginx:1.11.4-alpinegcr.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=rootnode2 ansible_host=192.168.1.122 ip=192.168.1.122 ansible_user=rootnode3 ansible_host=192.168.1.123 ip=192.168.1.123 ansible_user=rootnode4 ansible_host=192.168.1.124 ip=192.168.1.124 ansible_user=rootnode5 ansible_host=192.168.1.125 ip=192.168.1.125 ansible_user=rootnode6 ansible_host=192.168.1.126 ip=192.168.1.126 ansible_user=root[kube-master]node1[kube-node]node2node3[etcd]node1node2node3[k8s-cluster:children]kube-nodekube-master
6、修改sshkkeys.exp文件IP地址,这是expect脚步,用来复制ssh秘钥
#!/usr/bin/expect -fset timeout -1set user rootset passwd "password"for { set i 121 } { $i < 124 } { incr i } { spawn ssh-copy-id u s e r @ 192.168.1. [email protected]. user@192.168.1.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、完成2017-12-23 17-23-56 的屏幕截图.png
2017-12-23 17-29-37 的屏幕截图.png

2017-12-23 17-54-47 的屏幕截图.png

三、集群扩展
1、修改inventory文件,把新主机加入Master或者Node组
[all]node1 ansible_host=192.168.1.121 ip=192.168.1.121 ansible_user=rootnode2 ansible_host=192.168.1.122 ip=192.168.1.122 ansible_user=rootnode3 ansible_host=192.168.1.123 ip=192.168.1.123 ansible_user=rootnode4 ansible_host=192.168.1.124 ip=192.168.1.124 ansible_user=rootnode5 ansible_host=192.168.1.125 ip=192.168.1.125 ansible_user=rootnode6 ansible_host=192.168.1.126 ip=192.168.1.126 ansible_user=root[kube-master]node1node5[kube-node]node2node3node4…
2、安装
ansible-playbook -i inventory/inventory.cfg cluster.yml --limit node4,node5
3、完成
2017-12-23 22-38-47 的屏幕截图.png

2017-12-23 22-38-34 的屏幕截图.png

你可能感兴趣的:(使用Kubespray在虚拟机上部署Kubernetes)