感谢支持
我们一直在努力

Docker开发平台的构建

主机信息

操作系统版本

CentOS-7-x86_64-Everything-1511

 

主机A

192.168.6.128

主节点

主机B

192.168.6.129

主节点

主机C

192.168.6.130

从节点

第一步:配置静态IP

1.编辑网卡配置

vi /etc/sysconfig/network-scripts/ifcfg-eno16777736

默认配置:

文件更改后:

2.重启网卡

service network restart

3.网络测试

ping 192.168.6.2

能ping通,表示网络正常。

tips:

关闭网卡:ifdown eth0

启动网卡:ifup eth0

启动网络服务:

  service network start

  /etc/init.d/network start

重启网络服务:

  service network restart

  /etc/init.d/network restart

关闭网络服务:

  service network stop

  /etc/init.d/network stop

修改IP地址:

  即时生效:# ifconfig eth0 192.168.1.100 netmask 255.255.255.0

  重启生效:修改/etc/sysconfig/network-scripts/ifcfg-eth0

修改Default Gateway

  即时生效:# route add default gw 192.168.1.1

  重启生效:修改/etc/sysconfig/network-scripts/ifcfg-eth0

修改DNS:

  即时生效:修改/etc/resolv.conf

  重启生效:修改/etc/resolv.conf

修改hostname:

  即时生效:hostname test

  重启生效:修改/etc/sysconfig/network

更多Docker相关教程见以下内容

Docker安装应用(CentOS 6.5_x64) http://www.linuxidc.com/Linux/2014-07/104595.htm

Ubuntu 14.04安装Docker  http://www.linuxidc.com/linux/2014-08/105656.htm

Ubuntu使用VNC运行基于Docker的桌面系统  http://www.linuxidc.com/Linux/2015-08/121170.htm

阿里云CentOS 6.5 模板上安装 Docker http://www.linuxidc.com/Linux/2014-11/109107.htm

Ubuntu 15.04下安装Docker  http://www.linuxidc.com/Linux/2015-07/120444.htm

在Ubuntu Trusty 14.04 (LTS) (64-bit)安装Docker http://www.linuxidc.com/Linux/2014-10/108184.htm

在 Ubuntu 15.04 上如何安装Docker及基本用法 http://www.linuxidc.com/Linux/2015-09/122885.htm

Ubuntu 16.04上Docker使用手记 http://www.linuxidc.com/Linux/2016-12/138490.htm

第二步:关闭SELinux
1.查看SELinux状态:

sestatus -v

如果 SELinux status 参数为 enabled,即为开启状态。

也可以用 getenforce 命令查看:

2.关闭SELinux

1)临时关闭:

若想即时生效且不重启系统,执行命令 setenforce 0

setenforce 0    #设置 SELinux 为 permissive 模式
setenforce 1    #设置 SELinux 为 enforcing模式。

2)永久关闭:

修改配置文件/etc/selinux/config,需要重启

vi /etc/selinux/config

将 SELINUX=enforcing

改为SELINUX=disabled

修改完成后,重启即可。

3.测试:

临时修改测试:

修改文件配置重启后,测试:

 

第三步:关闭防火墙
1.查看状态:

systemctl status firewalld.service

2.关闭

systemctl stop firewalld.service

查看状态:

3.开机禁用服务

systemctl disable firewalld.service

查看状态:

第四步:更改主机名

echo 192-168-6-128.master > /etc/hostname

第五步:配置hosts

echo "127.0.0.1 192-168-6-128.master" >> /etc/hosts
echo "192.168.6.128 192-168-6-128.master" >> /etc/hosts
echo "192.168.6.129 192-168-6-129.master" >> /etc/hosts
echo "192.168.6.130 192-168-6-130.master" >> /etc/hosts
echo "192.168.6.128 index.liubc.com" >> /etc/hosts # 128作为镜像库

第六步:修改kernel.hostname

sysctl  kernel.hostname=192-168-6-128.master

第七步:重启网络

service network restart

第八步:配置本地yum源
1.上传系统安装包

本文上传到根目录下,目录名称为 CentOS-7。

2.配置yum源

进入 /etc/yum.repos.d 目录,新建 CentOS-Package.repo 文件

# cd /etc/yum.repos.d
# mkdir bak
# mv * bak # vi CentOS-Package.repo

将以下内容写入到 CentOS-Package.repo 文件

name=CentOS-7
baseurl=file:///CentOS-7
enable=1
gpgcheck=0
gpgkey=file:///CentOS-7/RPM-GPG-KEY-CentOS-7

3.测试

查看是否配置成功:

yum repolist

显示有9007个软件包,源配置成功。

 

tips: 配置 ftp 方式的局域网 yum 源

配置本地 yum 源,可以选择上述方式,但是该种方式需要每台主机都上传软件包,造成时间和空间上的浪费。

因此,可以选择一台主机上传软件包,作为局域网 yum 源,其他主机通过 ftp 方式获取 yum 源。

1.所需软件

vsftpd  —-  用户提供局域网的 FTP 服务

1)软件包:

  vsftpd-3.0.2-10.el7.x86_64.rpm

  vsftpd-sysvinit-3.0.2-10.el7.x86_64.rpm    

2)安装:

  rpm -ivh vsftpd*

3)启动:

  service vsftpd start

4)设置 vsftpd 开机启动

执行以下命令:

chkconfig vsftpd on

2.上传系统安装包

上传到一台主机上,本文上传到 192.168.6.128 的 /CentOS-7 目录下

3.更改 vsftpd 配置文件

在 192.168.6.128 主机上的文件 /etc/vsftpd/vsftpd.conf 最下面追加以下内容:

no_anon_password=NO
anon_root=/CentOS-7/

4.重启 vsftpd 服务

在 192.168.6.128 上执行以下命令:

service vsftpd restart

5.其他两台主机做如下配置操作:

1)进入 /etc/yum.repos.d 目录,新建 CentOS-Package.repo 文件

# cd /etc/yum.repos.d
# mkdir bak
# mv * bak
# vi CentOS-Package.repo

2)将以下内容写入到 CentOS-Package.repo 文件

[base]
name=CentOS-7
baseurl=ftp://192.168.6.128
enable=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

3)清除缓存

执行以下命令:

yum clean all

4)测试

查看是否配置成功:

yum repolist

显示有9007个软件包,源配置成功。

第九步:其他两台主机做以上相同配置操作

配置操作完成后,验证网络连通性、主机名解析正确性后,准备工作即为成功完成!

更多详情见请继续阅读下一页的精彩内容: http://www.linuxidc.com/Linux/2017-03/141592p2.htm

第一步:上传安装包和 docker 镜像
1.安装包:

  docker-engine-1.12.1-1.el7.CentOS.x86_64.rpm

  docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm

2.docker 镜像

  共28个文件:

  

第二步:安装 docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm

使用 yum 安装会同时安装相关依赖

yum install docker-engine-selinux-1.12.1-1.el7.centos.noarch.rpm

第三步:安装 docker-engine-1.12.1-1.el7.centos.x86_64.rpm

通过 rpm 命令安装:

rpm -ivh docker-engine-1.12.1-1.el7.centos.x86_64.rpm

第四步:启动 Docker

执行以下命令启动:

systemctl start docker

第五步:设置 docker 服务开机启动

执行以下命令:

chkconfig docker on

第六步:测试
1.查看 docker 进程

2.查看 docker 版本

1)docker -v

2)docker version

第七步:导入 docker 镜像文件
1.分别执行一下命令导入

 1 docker load -i busyboxgoogle.tar
 2 docker load -i busybox.tar
 3 docker load -i calicocni.tar
 4 docker load -i calicoctl.tar
 5 docker load -i calico-kube-policy-controller.tar
 6 docker load -i caliconode.tar
 7 docker load -i dnsmasq-metrics.tar
 8 docker load -i dnssidecar.tar
 9 docker load -i etcd-amd64.tar
10 docker load -i exechealthz-amd64111.tar
11 docker load -i exechealthz-amd64.tar
12 docker load -i kube-apiserver-amd64.tar
13 docker load -i kube-apiserver.tar
14 docker load -i kube-controller-manager-amd64.tar
15 docker load -i kube-controller-manager.tar
16 docker load -i kube-discovery.tar
17 docker load -i kubedns-amd64.tar
18 docker load -i kube-dnsmasq-amd6414.tar
19 docker load -i kube-dnsmasq-amdd.tar
20 docker load -i kubedns.tar
21 docker load -i kube-proxy140.tar
22 docker load -i kube-proxy-amd64.tar
23 docker load -i kube-proxy.tar
24 docker load -i kubernetes-dashboard-amd64.tar
25 docker load -i kube-scheduler.tar
26 docker load -i nginx111.tar
27 docker load -i nginx.tar
28 docker load -i pause-amd645.tar

2.测试

验证镜像文件是否导入完整,共计28个文件,执行以下命令查看:

docker images

第八步:其他两台主机做以上相同配置操作

操作完成后,docker 安装工作即为成功完成!

第一步:准备
1. 安装包:

kubeadm-1.6.0-0.alpha.0.2074.a092d8e0f95f52.x86_64.rpm

kubernetes-cni-0.3.0.1-0.07a8a2.x86_64.rpm

kubelet-1.5.1-0.x86_64.rpm

kubectl-1.5.1-0.x86_64.rpm

etcd-v2.2.1-linux-amd64.tar.gz

2. 上传

在三台主机分别上传以上安装包。

第二步:安装 k8s

# yum localinstall *.rpm -y

返回信息:

第三步:安装 tmux

# yum install tmux

返回信息:

第四步:安装配置 etcd
1. 删除默认的 k8s 配置文件

# rm -rf /etc/kubernetes/

2. 解压 etcd 压缩包

# tar zxvf etcd-v2.2.1-linux-amd64.tar.gz
# mv etcd-v2.2.1-linux-amd64 etcd
# cd etcd

3.  执行 tmux 进入后台,执行 etcd 配置脚本

1)在 192.168.6.128 执行

./etcd --name infra0 --initial-advertise-peer-urls http://192.168.6.128:2380 \
      --listen-peer-urls http://192.168.6.128:2380 \
      --listen-client-urls http://192.168.6.128:2379,http://127.0.0.1:2379 \
      --advertise-client-urls http://192.168.6.128:2379 \
      --initial-cluster-token etcd-cluster-1       --initial-cluster infra0=http://192.168.6.128:2380,infra1=http://192.168.6.129:2380,infra2=http://192.168.6.130:2380 \
      --initial-cluster-state new

返回信息:

2017-03-07 21:40:34.058276 I | etcdmain: etcd Version: 2.2.1
2017-03-07 21:40:34.058350 I | etcdmain: Git SHA: 75f8282
2017-03-07 21:40:34.058358 I | etcdmain: Go Version: go1.5.1
2017-03-07 21:40:34.058364 I | etcdmain: Go OS/Arch: linux/amd64
2017-03-07 21:40:34.058373 I | etcdmain: setting maximum number of CPUs to 1, total number of available CPUs is 1
2017-03-07 21:40:34.058385 W | etcdmain: no data-dir provided, using default data-dir ./infra0.etcd
2017-03-07 21:40:34.058499 I | etcdmain: listening for peers on http://192.168.6.128:2380
2017-03-07 21:40:34.058545 I | etcdmain: listening for client requests on http://127.0.0.1:2379
2017-03-07 21:40:34.058575 I | etcdmain: listening for client requests on http://192.168.6.128:2379
2017-03-07 21:40:34.060783 I | etcdserver: name = infra0
2017-03-07 21:40:34.060805 I | etcdserver: data dir = infra0.etcd
2017-03-07 21:40:34.060813 I | etcdserver: member dir = infra0.etcd/member
2017-03-07 21:40:34.060820 I | etcdserver: heartbeat = 100ms
2017-03-07 21:40:34.060826 I | etcdserver: election = 1000ms
2017-03-07 21:40:34.060832 I | etcdserver: snapshot count = 10000
2017-03-07 21:40:34.060851 I | etcdserver: advertise client URLs = http://192.168.6.128:2379
2017-03-07 21:40:34.060862 I | etcdserver: initial advertise peer URLs = http://192.168.6.128:2380
2017-03-07 21:40:34.060882 I | etcdserver: initial cluster = infra0=http://192.168.6.128:2380,infra1=http://192.168.6.129:2380,infra2=http://192.168.6.130:2380
2017-03-07 21:40:34.102470 I | etcdserver: starting member 205e265f32ab88c4 in cluster 24d40765d97551b1
2017-03-07 21:40:34.102699 I | raft: 205e265f32ab88c4 became follower at term 0
2017-03-07 21:40:34.102756 I | raft: newRaft 205e265f32ab88c4 [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2017-03-07 21:40:34.102773 I | raft: 205e265f32ab88c4 became follower at term 1
2017-03-07 21:40:34.159745 I | etcdserver: starting server... [version: 2.2.1, cluster version: to_be_decided]
2017-03-07 21:40:34.162442 E | etcdmain: failed to notify systemd for readiness: No socket
2017-03-07 21:40:34.162485 E | etcdmain: forgot to set Type=notify in systemd service file?
2017-03-07 21:40:34.168847 N | etcdserver: added local member 205e265f32ab88c4 [http://192.168.6.128:2380] to cluster 24d40765d97551b1
2017-03-07 21:40:34.169066 N | etcdserver: added member 277ba44edc63d7cd [http://192.168.6.130:2380] to cluster 24d40765d97551b1
2017-03-07 21:40:34.169745 N | etcdserver: added member c1d267ff57ac5bcc [http://192.168.6.129:2380] to cluster 24d40765d97551b1
2017-03-07 21:40:34.170048 E | rafthttp: failed to dial 277ba44edc63d7cd on stream Message (dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:34.170125 E | rafthttp: failed to dial 277ba44edc63d7cd on stream MsgApp v2 (dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:34.170191 E | rafthttp: failed to dial c1d267ff57ac5bcc on stream Message (dial tcp 192.168.6.129:2380: getsockopt: connection refused)
2017-03-07 21:40:34.170251 E | rafthttp: failed to dial c1d267ff57ac5bcc on stream MsgApp v2 (dial tcp 192.168.6.129:2380: getsockopt: connection refused)
2017-03-07 21:40:34.703774 I | raft: 205e265f32ab88c4 is starting a new election at term 1
2017-03-07 21:40:34.704446 I | raft: 205e265f32ab88c4 became candidate at term 2
2017-03-07 21:40:34.704478 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 2
2017-03-07 21:40:34.704510 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 2
2017-03-07 21:40:34.704535 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 2
2017-03-07 21:40:34.709296 E | rafthttp: failed to write c1d267ff57ac5bcc on pipeline (dial tcp 192.168.6.129:2380: getsockopt: connection refused)
2017-03-07 21:40:34.709712 E | rafthttp: failed to write 277ba44edc63d7cd on pipeline (dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:36.003331 I | raft: 205e265f32ab88c4 is starting a new election at term 2
2017-03-07 21:40:36.042379 I | raft: 205e265f32ab88c4 became candidate at term 3
2017-03-07 21:40:36.042511 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 3
2017-03-07 21:40:36.042551 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 3
2017-03-07 21:40:36.042576 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 3
2017-03-07 21:40:37.203729 I | raft: 205e265f32ab88c4 is starting a new election at term 3
2017-03-07 21:40:37.204106 I | raft: 205e265f32ab88c4 became candidate at term 4
2017-03-07 21:40:37.204161 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 4
2017-03-07 21:40:37.204205 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 4
2017-03-07 21:40:37.204247 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 4
2017-03-07 21:40:38.604756 I | raft: 205e265f32ab88c4 is starting a new election at term 4
2017-03-07 21:40:38.605007 I | raft: 205e265f32ab88c4 became candidate at term 5
2017-03-07 21:40:38.605038 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 5
2017-03-07 21:40:38.605382 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 5
2017-03-07 21:40:38.605432 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 5
2017-03-07 21:40:39.804275 I | raft: 205e265f32ab88c4 is starting a new election at term 5
2017-03-07 21:40:39.804662 I | raft: 205e265f32ab88c4 became candidate at term 6
2017-03-07 21:40:39.804684 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 6
2017-03-07 21:40:39.804697 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 6
2017-03-07 21:40:39.804709 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 6
2017-03-07 21:40:41.168876 E | etcdserver: publish error: etcdserver: request timed out
2017-03-07 21:40:41.204051 I | raft: 205e265f32ab88c4 is starting a new election at term 6
2017-03-07 21:40:41.204460 I | raft: 205e265f32ab88c4 became candidate at term 7
2017-03-07 21:40:41.204494 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 7
2017-03-07 21:40:41.204515 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 7
2017-03-07 21:40:41.204532 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 7
2017-03-07 21:40:42.803859 I | raft: 205e265f32ab88c4 is starting a new election at term 7
2017-03-07 21:40:42.803939 I | raft: 205e265f32ab88c4 became candidate at term 8
2017-03-07 21:40:42.803949 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 8
2017-03-07 21:40:42.803962 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 8
2017-03-07 21:40:42.803973 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 8
2017-03-07 21:40:44.207322 I | raft: 205e265f32ab88c4 is starting a new election at term 8
2017-03-07 21:40:44.207549 I | raft: 205e265f32ab88c4 became candidate at term 9
2017-03-07 21:40:44.207581 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 9
2017-03-07 21:40:44.207608 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 9
2017-03-07 21:40:44.207632 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 9
2017-03-07 21:40:45.404016 I | raft: 205e265f32ab88c4 is starting a new election at term 9
2017-03-07 21:40:45.404575 I | raft: 205e265f32ab88c4 became candidate at term 10
2017-03-07 21:40:45.404616 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 10
2017-03-07 21:40:45.404644 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 10
2017-03-07 21:40:45.404669 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 10
2017-03-07 21:40:46.605584 I | raft: 205e265f32ab88c4 is starting a new election at term 10
2017-03-07 21:40:46.605724 I | raft: 205e265f32ab88c4 became candidate at term 11
2017-03-07 21:40:46.605747 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 11
2017-03-07 21:40:46.605772 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 11
2017-03-07 21:40:46.605795 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 11
2017-03-07 21:40:47.855884 I | rafthttp: the connection with c1d267ff57ac5bcc became active
2017-03-07 21:40:48.038296 I | raft: 205e265f32ab88c4 [term: 11] ignored a MsgVote message with lower term from c1d267ff57ac5bcc [term: 2]
2017-03-07 21:40:48.105541 I | raft: 205e265f32ab88c4 is starting a new election at term 11
2017-03-07 21:40:48.105669 I | raft: 205e265f32ab88c4 became candidate at term 12
2017-03-07 21:40:48.105691 I | raft: 205e265f32ab88c4 received vote from 205e265f32ab88c4 at term 12
2017-03-07 21:40:48.105716 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 12
2017-03-07 21:40:48.105740 I | raft: 205e265f32ab88c4 [logterm: 1, index: 3] sent vote request to c1d267ff57ac5bcc at term 12
2017-03-07 21:40:48.151355 I | raft: 205e265f32ab88c4 received vote from c1d267ff57ac5bcc at term 12
2017-03-07 21:40:48.151714 I | raft: 205e265f32ab88c4 [q:2] has received 2 votes and 0 vote rejections
2017-03-07 21:40:48.151962 I | raft: 205e265f32ab88c4 became leader at term 12
2017-03-07 21:40:48.152021 I | raft: raft.node: 205e265f32ab88c4 elected leader 205e265f32ab88c4 at term 12
2017-03-07 21:40:48.164621 W | etcdserver: failed to reach the peerURL(http://192.168.6.130:2380) of member 277ba44edc63d7cd (Get http://192.168.6.130:2380/version: dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:48.164660 W | etcdserver: cannot get the version of member 277ba44edc63d7cd (Get http://192.168.6.130:2380/version: dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:48.167418 I | etcdserver: setting up the initial cluster version to 2.1
2017-03-07 21:40:48.169673 E | etcdserver: publish error: etcdserver: request timed out, possibly due to connection lost
2017-03-07 21:40:48.173202 N | etcdserver: set the initial cluster version to 2.1
2017-03-07 21:40:48.176115 I | etcdserver: published {Name:infra0 ClientURLs:[http://192.168.6.128:2379]} to cluster 24d40765d97551b1
2017-03-07 21:40:53.169422 W | etcdserver: failed to reach the peerURL(http://192.168.6.130:2380) of member 277ba44edc63d7cd (Get http://192.168.6.130:2380/version: dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:53.169475 W | etcdserver: cannot get the version of member 277ba44edc63d7cd (Get http://192.168.6.130:2380/version: dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:58.177751 W | etcdserver: failed to reach the peerURL(http://192.168.6.130:2380) of member 277ba44edc63d7cd (Get http://192.168.6.130:2380/version: dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:58.177823 W | etcdserver: cannot get the version of member 277ba44edc63d7cd (Get http://192.168.6.130:2380/version: dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:41:01.438424 I | rafthttp: the connection with 277ba44edc63d7cd became active
2017-03-07 21:41:03.191553 I | etcdserver: updating the cluster version from 2.1 to 2.2
2017-03-07 21:41:03.197963 N | etcdserver: updated the cluster version from 2.1 to 2.2

2)在 192.168.6.129 上执行:

./etcd --name infra1 --initial-advertise-peer-urls http://192.168.6.129:2380 \
      --listen-peer-urls http://192.168.6.129:2380 \
      --listen-client-urls http://192.168.6.129:2379,http://127.0.0.1:2379 \
      --advertise-client-urls http://192.168.6.129:2379 \
      --initial-cluster-token etcd-cluster-1       --initial-cluster infra0=http://192.168.6.128:2380,infra1=http://192.168.6.129:2380,infra2=http://192.168.6.130:2380 \
      --initial-cluster-state new

返回信息:

2017-03-07 21:40:47.824138 I | etcdmain: etcd Version: 2.2.1
2017-03-07 21:40:47.824299 I | etcdmain: Git SHA: 75f8282
2017-03-07 21:40:47.824318 I | etcdmain: Go Version: go1.5.1
2017-03-07 21:40:47.824332 I | etcdmain: Go OS/Arch: linux/amd64
2017-03-07 21:40:47.824351 I | etcdmain: setting maximum number of CPUs to 1, total number of available CPUs is 1
2017-03-07 21:40:47.824376 W | etcdmain: no data-dir provided, using default data-dir ./infra1.etcd
2017-03-07 21:40:47.824605 I | etcdmain: listening for peers on http://192.168.6.129:2380
2017-03-07 21:40:47.824832 I | etcdmain: listening for client requests on http://127.0.0.1:2379
2017-03-07 21:40:47.824919 I | etcdmain: listening for client requests on http://192.168.6.129:2379
2017-03-07 21:40:47.830245 I | etcdserver: name = infra1
2017-03-07 21:40:47.830298 I | etcdserver: data dir = infra1.etcd
2017-03-07 21:40:47.830316 I | etcdserver: member dir = infra1.etcd/member
2017-03-07 21:40:47.830368 I | etcdserver: heartbeat = 100ms
2017-03-07 21:40:47.830388 I | etcdserver: election = 1000ms
2017-03-07 21:40:47.830401 I | etcdserver: snapshot count = 10000
2017-03-07 21:40:47.830435 I | etcdserver: advertise client URLs = http://192.168.6.129:2379
2017-03-07 21:40:47.830477 I | etcdserver: initial advertise peer URLs = http://192.168.6.129:2380
2017-03-07 21:40:47.830530 I | etcdserver: initial cluster = infra0=http://192.168.6.128:2380,infra1=http://192.168.6.129:2380,infra2=http://192.168.6.130:2380
2017-03-07 21:40:47.836392 I | etcdserver: starting member c1d267ff57ac5bcc in cluster 24d40765d97551b1
2017-03-07 21:40:47.836576 I | raft: c1d267ff57ac5bcc became follower at term 0
2017-03-07 21:40:47.836628 I | raft: newRaft c1d267ff57ac5bcc [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2017-03-07 21:40:47.836646 I | raft: c1d267ff57ac5bcc became follower at term 1
2017-03-07 21:40:47.858347 I | etcdserver: starting server... [version: 2.2.1, cluster version: to_be_decided]
2017-03-07 21:40:47.858946 E | etcdmain: failed to notify systemd for readiness: No socket
2017-03-07 21:40:47.858966 E | etcdmain: forgot to set Type=notify in systemd service file?
2017-03-07 21:40:47.862192 I | rafthttp: the connection with 205e265f32ab88c4 became active
2017-03-07 21:40:47.862912 N | etcdserver: added member 205e265f32ab88c4 [http://192.168.6.128:2380] to cluster 24d40765d97551b1
2017-03-07 21:40:47.863026 N | etcdserver: added member 277ba44edc63d7cd [http://192.168.6.130:2380] to cluster 24d40765d97551b1
2017-03-07 21:40:47.863120 N | etcdserver: added local member c1d267ff57ac5bcc [http://192.168.6.129:2380] to cluster 24d40765d97551b1
2017-03-07 21:40:47.863461 E | rafthttp: failed to dial 277ba44edc63d7cd on stream Message (dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:47.863503 E | rafthttp: failed to dial 277ba44edc63d7cd on stream MsgApp v2 (dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:48.039642 I | raft: c1d267ff57ac5bcc is starting a new election at term 1
2017-03-07 21:40:48.039865 I | raft: c1d267ff57ac5bcc became candidate at term 2
2017-03-07 21:40:48.039891 I | raft: c1d267ff57ac5bcc received vote from c1d267ff57ac5bcc at term 2
2017-03-07 21:40:48.039921 I | raft: c1d267ff57ac5bcc [logterm: 1, index: 3] sent vote request to 277ba44edc63d7cd at term 2
2017-03-07 21:40:48.039946 I | raft: c1d267ff57ac5bcc [logterm: 1, index: 3] sent vote request to 205e265f32ab88c4 at term 2
2017-03-07 21:40:48.046572 E | rafthttp: failed to write 277ba44edc63d7cd on pipeline (dial tcp 192.168.6.130:2380: getsockopt: connection refused)
2017-03-07 21:40:48.153424 I | raft: c1d267ff57ac5bcc [term: 2] received a MsgVote message with higher term from 205e265f32ab88c4 [term: 12]
2017-03-07 21:40:48.153530 I | raft: c1d267ff57ac5bcc became follower at term 12
2017-03-07 21:40:48.153577 I | raft: c1d267ff57ac5bcc [logterm: 1, index: 3, vote: 0] voted for 205e265f32ab88c4 [logterm: 1, index: 3] at term 12
2017-03-07 21:40:48.163099 I | raft: raft.node: c1d267ff57ac5bcc elected leader 205e265f32ab88c4 at term 12
2017-03-07 21:40:48.181204 I | etcdserver: published {Name:infra1 ClientURLs:[http://192.168.6.129:2379]} to cluster 24d40765d97551b1
2017-03-07 21:40:48.184526 N | etcdserver: set the initial cluster version to 2.1
2017-03-07 21:41:01.448599 I | rafthttp: the connection with 277ba44edc63d7cd became active
2017-03-07 21:41:03.207866 N | etcdserver: updated the cluster version from 2.1 to 2.2

3)在 192.168.6.130 上执行:

./etcd --name infra2 --initial-advertise-peer-urls http://192.168.6.130:2380 \
      --listen-peer-urls http://192.168.6.130:2380 \
      --listen-client-urls http://192.168.6.130:2379,http://127.0.0.1:2379 \
      --advertise-client-urls http://192.168.6.130:2379 \
      --initial-cluster-token etcd-cluster-1       --initial-cluster infra0=http://192.168.6.128:2380,infra1=http://192.168.6.129:2380,infra2=http://192.168.6.130:2380 \
      --initial-cluster-state new

返回信息:

2017-03-07 21:41:01.402423 I | etcdmain: etcd Version: 2.2.1
2017-03-07 21:41:01.402651 I | etcdmain: Git SHA: 75f8282
2017-03-07 21:41:01.402677 I | etcdmain: Go Version: go1.5.1
2017-03-07 21:41:01.402691 I | etcdmain: Go OS/Arch: linux/amd64
2017-03-07 21:41:01.402711 I | etcdmain: setting maximum number of CPUs to 1, total number of available CPUs is 1
2017-03-07 21:41:01.402736 W | etcdmain: no data-dir provided, using default data-dir ./infra2.etcd
2017-03-07 21:41:01.402972 I | etcdmain: listening for peers on http://192.168.6.130:2380
2017-03-07 21:41:01.403070 I | etcdmain: listening for client requests on http://127.0.0.1:2379
2017-03-07 21:41:01.403145 I | etcdmain: listening for client requests on http://192.168.6.130:2379
2017-03-07 21:41:01.408318 I | etcdserver: name = infra2
2017-03-07 21:41:01.408354 I | etcdserver: data dir = infra2.etcd
2017-03-07 21:41:01.408364 I | etcdserver: member dir = infra2.etcd/member
2017-03-07 21:41:01.408372 I | etcdserver: heartbeat = 100ms
2017-03-07 21:41:01.408379 I | etcdserver: election = 1000ms
2017-03-07 21:41:01.408386 I | etcdserver: snapshot count = 10000
2017-03-07 21:41:01.408422 I | etcdserver: advertise client URLs = http://192.168.6.130:2379
2017-03-07 21:41:01.408440 I | etcdserver: initial advertise peer URLs = http://192.168.6.130:2380
2017-03-07 21:41:01.408479 I | etcdserver: initial cluster = infra0=http://192.168.6.128:2380,infra1=http://192.168.6.129:2380,infra2=http://192.168.6.130:2380
2017-03-07 21:41:01.421508 I | etcdserver: starting member 277ba44edc63d7cd in cluster 24d40765d97551b1
2017-03-07 21:41:01.421628 I | raft: 277ba44edc63d7cd became follower at term 0
2017-03-07 21:41:01.421658 I | raft: newRaft 277ba44edc63d7cd [peers: [], term: 0, commit: 0, applied: 0, lastindex: 0, lastterm: 0]
2017-03-07 21:41:01.421667 I | raft: 277ba44edc63d7cd became follower at term 1
2017-03-07 21:41:01.448333 I | etcdserver: starting server... [version: 2.2.1, cluster version: to_be_decided]
2017-03-07 21:41:01.448691 E | etcdmain: failed to notify systemd for readiness: No socket
2017-03-07 21:41:01.448707 E | etcdmain: forgot to set Type=notify in systemd service file?
2017-03-07 21:41:01.451690 I | rafthttp: the connection with 205e265f32ab88c4 became active
2017-03-07 21:41:01.454571 N | etcdserver: added member 205e265f32ab88c4 [http://192.168.6.128:2380] to cluster 24d40765d97551b1
2017-03-07 21:41:01.454801 N | etcdserver: added local member 277ba44edc63d7cd [http://192.168.6.130:2380] to cluster 24d40765d97551b1
2017-03-07 21:41:01.454895 N | etcdserver: added member c1d267ff57ac5bcc [http://192.168.6.129:2380] to cluster 24d40765d97551b1
2017-03-07 21:41:01.456262 I | rafthttp: the connection with c1d267ff57ac5bcc became active
2017-03-07 21:41:01.459542 I | raft: 277ba44edc63d7cd [term: 1] received a MsgHeartbeat message with higher term from 205e265f32ab88c4 [term: 12]
2017-03-07 21:41:01.460567 I | raft: 277ba44edc63d7cd became follower at term 12
2017-03-07 21:41:01.460593 I | raft: raft.node: 277ba44edc63d7cd elected leader 205e265f32ab88c4 at term 12
2017-03-07 21:41:01.502371 N | etcdserver: set the initial cluster version to 2.1
2017-03-07 21:41:01.506410 I | etcdserver: published {Name:infra2 ClientURLs:[http://192.168.6.130:2379]} to cluster 24d40765d97551b1
2017-03-07 21:41:03.214718 N | etcdserver: updated the cluster version from 2.1 to 2.2

4. 退出 tmux 后台模式

Ctrl + b 再按 d 键

附:tmux 帮助

1)查看存在的 session

# tmux ls

返回信息:

2)删除某个 session

# tmux kill-session -t $session_name

3)进入某个 session

# tmux attach -t $session_name

第五步:在初始化 k8s
1. 为 192.168.6.128 网卡增加 IP

# ip addr add 192.168.6.132 dev eno16777736

查看网卡:

2. 初始化

1)执行初始化命令

# kubeadm init --api-advertise-addresses=192.168.6.131 --external-etcd-endpoints=http://192.168.6.128:2379,http://192.168.6.129:2379,http://192.168.6.130:2379 --use-kubernetes-version v1.5.1

返回信息:

Flag –external-etcd-endpoints has been deprecated, this flag will be removed when componentconfig exists
[kubeadm] WARNING: kubeadm
is in alpha, please do not use it for production clusters.
[preflight] Running pre
flight checks
[preflight] WARNING: kubelet service
is not enabled, please run systemctl enable kubelet.service [preflight] Starting the kubelet service [init] Using Kubernetes version: v1.5.1
[tokens] Generated token:
e2e92d.d96382dcac25aa22
[certificates] Generated Certificate Authority key and certificate.
[certificates] Generated API Server key and certificate
[certificates] Generated Service Account signing keys
[certificates] Created keys and certificates
in /etc/kubernetes/pki
[kubeconfig] Wrote KubeConfig file to disk:
/etc/kubernetes/kubelet.conf
[kubeconfig] Wrote KubeConfig file to disk:
/etc/kubernetes/admin.conf
[apiclient] Created API client, waiting
for the control plane to become ready
[apiclient] All control plane components are healthy after
22.501928 seconds
[apiclient] Waiting
for at least one node to register and become ready
[apiclient] First node
is ready after 0.509735 seconds
[apiclient] Creating a test deployment
[apiclient] Test deployment succeeded
[token
-discovery] Created the kube-discovery deployment, waiting for it to become ready
[token
-discovery] kube-discovery is ready after 3.503953 seconds
[addons] Created essential addon: kube
proxy
[addons] Created essential addon: kube
dns

Your Kubernetes master has initialized successfully!

You should now deploy a pod network to the cluster.
Runkubectl apply -f [podnetwork].yaml with one of the options listed at:
    http:
//kubernetes.io/docs/admin/addons/

You can now join any number of machines by running the following on each node:

kubeadm join–token=e2e92d.d96382dcac25aa22 192.168.6.131

其中,切记:kubeadm join –token=e2e92d.d96382dcac25aa22 192.168.6.131

2)添加 kubelet 服务

# systemctl enable kubelet.service

返回信息:

3)查看 nodes

# kubectl get nodes

返回信息:

4)查看 pods 

# kubectl get pods --all-namespaces

 返回信息:

3. 配置 192.168.6.129 的 k8s

1)停止 k8s 服务

# systemctl stop kubelet

2)将 192.168.6.128 上的 /etc/kubernetes 目录复制到 192.168.6.129 上

3)重启 k8s 服务

# systemctl start kubelet

3)查看 nodes

# kubectl get nodes

返回信息:

 

4)查看 pods

# kubectl get pods --all-namespaces

返回信息:

4. 在 192.168.6.130 上启动 k8s 服务,并加入集群

1)执行上述切记的脚本:

# kubeadm join --token=e2e92d.d96382dcac25aa22 192.168.6.131

返回信息:

2)查看 nodes

# kubectl get nodes

返回信息:

第六步:添加 calico
1. 修改 calico.yaml

找到 etcd_endpoints 字段,修改成应的 IP:

etcd_endpoints: "http://192.168.6.128:2379,http://192.168.6.129:2379,http://192.168.6.130:2379"

2. 在主节点(192.168.6.128)添加 calico.yaml

# kubectl apply -f calico.yaml

返回信息:

3. 在主节点(192.168.6.128)添加 busybox.yaml

# kubectl create -f busybox.yaml

返回信息:

4. 查看 pods

# kubectl get pods --all-namespaces

返回信息:

第七步:kubuctl 其他配置
1. 目前 deploy/kube-dns 只有主节点上有,需进行扩容 kube-dns

1)执行命令

# kubectl scale deploy/kube-dns  --replicas=2 -n kube-system

返回信息:

2)查看 pods

# kubectl get pods --all-namespaces

返回信息:

2. 目前 deploy/kube-discovery 只有主节点上有,需进行扩容 kube-discovery

1)执行命令

# kubectl scale deploy/kube-discovery --replicas=2 -n kube-system

返回信息:

2)查看 pods

# kubectl get pods --all-namespaces

返回信息:

3. 给另一个主节点打主节点标签

1)在 192.168.6.129 执行

# kubectl label node 192-168-6-129.master kubeadm.alpha.kubernetes.io/role=master

返回信息:

2)重启 192.168.6.129 上的 docker 服务

# systemctl restart docker

3)查看 nodes

# kubectl get nodes

返回信息:

4. 设置主节点可调节度

即设置应用也能在主节点上运行。

# kubectl taint nodes --all dedicated-

返回信息:

此时,kubernetes 组件已成功添加完成!第一步:创建服务
1. 配置 nginx 的 yaml 文件

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-nginx
spec:
  replicas: 2
  template:
    metadata:
      labels:
        run: my-nginx
    spec:
      containers:
      - name: my-nginx
        imagePullPolicy: IfNotPresent #默认拉取方式,先查本地是否存在
        image: nginx:v1.1.1
        ports:
        - containerPort: 80

2. 创建 nginx 服务

1)创建

# kubectl create -f run-my-nginx.yaml

返回信息:

2)查看 pods

# kubectl get pods --all-namespaces

返回信息:

附:删除 nginx 服务

# kubectl delete -f run-my-nginx.yaml

返回信息:

第二步:扩缩容
1. 扩容

1)由两个 nginx pod 扩到五个 pod

# kubectl scale --replicas=5 -f run-my-nginx.yaml

返回信息:

2)查看 pods

# kubectl get pods --all-namespaces

返回信息:

2. 缩容

1)由五个 nginx pod 缩到两个 pod

# kubectl scale --replicas=2 -f run-my-nginx.yaml

返回信息:

2)查看 pods

# kubectl get pods --all-namespaces

返回信息:

第三步:暴露端口
1. 暴露端口

# kubectl expose deployment my-nginx --target-port=80 --port=8081 --protocol=TCP --type=NodePort

返回信息:

2. 查看端口

1)查看容器的 IP

# kubectl get ep my-nginx

返回信息:

2)查看容器详细信息

# kubectl describe svc my-nginx

返回信息:

得知暴露在外面的端口为31838。

3. 测试

访问地址:http://192.168.6.132:31838/

返回页面:

Docker 的详细介绍:请点这里
Docker 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-03/141592.htm

赞(0) 打赏
转载请注明出处:服务器评测 » Docker开发平台的构建
分享到: 更多 (0)

听说打赏我的人,都进福布斯排行榜啦!

支付宝扫一扫打赏

微信扫一扫打赏