码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2019-01-20 11:48:47      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:prope   masters   release   分享   rem   css   关系   单机   class   

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

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

构成说明

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

NotypeIPOS
1 master 192.168.32.31 CENTOS7.2
2 etcd 192.168.32.31 CENTOS7.2
3 minion 192.168.32.32 CENTOS7.2

Step 1:安装ansible

在192.168.32.31上安装ansible

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

确认安装

[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]#
  • 1
  • 2
  • 3
  • 4
  • 5

Step 2:设定ssh通路和ansible

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

[root@host31 ~]# ssh-keygen
[root@host32 ~]# ssh-keygen
  • 1
  • 2

设定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 ~]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

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

# ssh-copy-id -i host31
# ssh-copy-id -i host32
  • 1
  • 2

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

[root@host31 ansible]# grep host3 /etc/ansible/hosts
host31
host32
[root@host31 ansible]#
  • 1
  • 2
  • 3
  • 4

确认ansible正常动作

[root@host31 ~]# ansible localhost -m ping
localhost | SUCCESS => {
    "changed": false,
    "ping": "pong"
}
[root@host31 ~]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

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]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

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]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

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

[root@host31 ansible]# cat inventory

[masters]
host31

[etcd:children]
host31

[nodes]
host32
[root@host31 ansible]#
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

Step 6:安装所需package

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

Nopackage机器安装命令
1 python-netaddr 192.168.32.31 yum -y install python-netaddr

Step 7:执行安装文件

执行安装文件setup.sh

[root@host31 ansible]# pwd
/local/contrib/ansible
[root@host31 ansible]# ./setup.sh
  • 1
  • 2
  • 3

Step 8:确认kubernetes

确认node

[root@host31 ansible]# kubectl get nodes
NAME      STATUS    AGE
host31    Ready     1m
host32    Ready     1m
[root@host31 ansible]#
  • 1
  • 2
  • 3
  • 4
  • 5

确认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]#
  • 1
  • 2
  • 3
  • 4

确认版本

[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
  • 3
  • 4

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

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

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

标签:prope   masters   release   分享   rem   css   关系   单机   class   

原文地址:https://www.cnblogs.com/firsttry/p/10294035.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!