Kubernetes 1.3 从入门到进阶 安装篇(2)

Kubernetes 1.3 从入门到进阶 安装篇: kubernetes-ansible

上一篇文章我们介绍了使用minikube快速部署kubernetes1.3到单机上. 多台机器构成的集群,本次介绍kubernetes-ansible来进行安装。ansible是自动化部署一大神器,接下来就让我们来看看使用神器的效果吧。

构成说明

master和etcd共用一台机器,只有一个minion的超级mini构成,只是为演示只用。

NotypeIPOS
1master192.168.32.31CENTOS7.2
2etcd192.168.32.31CENTOS7.2
3minion192.168.32.32CENTOS7.2

Step 1:安装ansible

在192.168.32.31上安装ansible

[root@host31 local]# yum -y install epel-release
[root@host31 local]# yum -y install ansible

确认安装

[root@host31 local]# ansible --version
ansible 2.1.0.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = Default w/o overrides
[root@host31 local]#

Step 2:设定ssh通路和ansible

分别在两台机器上生成ssh的key

[root@host31 ~]# ssh-keygen
[root@host32 ~]# ssh-keygen

设定2台机器的/etc/hosts

[root@host31 ~]# grep host3 /etc/hosts
192.168.32.31 host31
192.168.32.32 host32
[root@host31 ~]#
[root@host32 ~]# grep host3 /etc/hosts
192.168.32.31 host31
192.168.32.32 host32
[root@host32 ~]#

在2台机器上都作如下设定,保证ssh通路畅通

# ssh-copy-id -i host31
# ssh-copy-id -i host32

在ansible所安装的机器上,追加机器信息到/etc/ansible/hosts中

[root@host31 ansible]# grep host3 /etc/ansible/hosts
host31
host32
[root@host31 ansible]#

确认ansible正常动作

[root@host31 ~]# ansible localhost -m ping
localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
[root@host31 ~]#

Step 3:下载contrib

contrib里面有kubernets生态中很多有用的组件,但不属于kubernetes的core的部分。首先我们使用git从https://github.com/kubernetes/contrib上clong下来整个contrib,而用来方便安装的kubernetes-ansible,只是其中的一个部分:https://github.com/kubernetes/contrib/tree/master/ansible

[root@host31 local]# cd ..
[root@host31 /]# mkdir -p /local; cd /local
[root@host31 local]# git clone https://github.com/kubernetes/contrib.git
Cloning into 'contrib'...
remote: Counting objects: 27980, done.
remote: Compressing objects: 100% (40/40), done.
remote: Total 27980 (delta 13), reused 0 (delta 0), pack-reused 27940
Receiving objects: 100% (27980/27980), 30.05 MiB | 173.00 KiB/s, done.
Resolving deltas: 100% (13411/13411), done.
[root@host31 local]#

Step 4:生成kubernetes-ansible设定文件

按照构成说明中的2台机器构成,设定inventory文件

[root@host31 ansible]# pwd
/local/contrib/ansible
[root@host31 ansible]# ll
total 28
-rw-r--r--.  1 root root 1630 Jul 29 08:09 deploy-cluster.yml
drwxr-xr-x.  2 root root   20 Jul 29 08:09 group_vars
-rw-r--r--.  1 root root  115 Jul 29 08:09 inventory.example.ha
-rw-r--r--.  1 root root  156 Jul 29 08:09 inventory.example.single_master
drwxr-xr-x.  3 root root   18 Jul 29 08:09 playbooks
-rw-r--r--.  1 root root 2207 Jul 29 08:09 README.md
drwxr-xr-x. 15 root root 4096 Jul 29 08:09 roles
-rwxr-xr-x.  1 root root  711 Jul 29 08:09 setup.sh
drwxr-xr-x.  2 root root 4096 Jul 29 08:09 vagrant
[root@host31 ansible]# cp inventory.example.ha inventory
[root@host31 ansible]#

将inventory文件的内容设定为如下

[root@host31 ansible]# cat inventory

[masters]
host31

[etcd:children]
host31

[nodes]
host32
[root@host31 ansible]#

Step 6:安装所需package

依赖关系整理的真不错,只有一个package在github的说明中虽然没有提到,但是实际是需要提前安装的

Nopackage机器安装命令
1python-netaddr192.168.32.31yum -y install python-netaddr

Step 7:执行安装文件

执行安装文件setup.sh

[root@host31 ansible]# pwd
/local/contrib/ansible
[root@host31 ansible]# ./setup.sh

Step 8:确认kubernetes

确认node

[root@host31 ansible]# kubectl get nodes
NAME      STATUS    AGE
host31    Ready     1m
host32    Ready     1m
[root@host31 ansible]#

确认services

[root@host31 ansible]# kubectl get services
NAME         CLUSTER-IP   EXTERNAL-IP   PORT(S)   AGE
kubernetes   10.254.0.1   <none>        443/TCP   12m
[root@host31 ansible]#

确认版本

[root@host31 ansible]# kubectl version
Client Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.0", GitCommit:"a4463d9a1accc9c61ae90ce5d314e248f16b9f05", GitTreeState:"clean"}
Server Version: version.Info{Major:"1", Minor:"2", GitVersion:"v1.2.0", GitCommit:"a4463d9a1accc9c61ae90ce5d314e248f16b9f05", GitTreeState:"clean"}
[root@host31 ansible]#

吐槽: 居然是1.2,再到github上仔细一看,四个月没有更新了。是要放弃kubernetes-ansible转用minikube的意图么,对我们来说明明非常友好可用的东西,不像minikube有问题了的话只能眼巴巴地看着它那个go语言的二进制文件,眼睁睁的看着它取个版本信息都要联一下google。对1.2和1.3之间区别不是特别在意的朋友,严重推荐此种方式进行安装,甚至生产环境或者测试环境也完全可以在此基础上进行定制和改进安装与部署。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值