kubernetes分布式集群的搭建

网络结构

kubernetes分布式集群的搭建_第1张图片

操作环境

操作系统

[root@group20511 ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 

docker

[root@group20511 ~]# docker version
Client:
 Version:         1.13.1
 API version:     1.26
 Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      8633870/1.13.1
 Built:           Fri Sep 28 19:45:08 2018
 OS/Arch:         linux/amd64

Server:
 Version:         1.13.1
 API version:     1.26 (minimum version 1.12)
 Package version: docker-1.13.1-75.git8633870.el7.centos.x86_64
 Go version:      go1.9.4
 Git commit:      8633870/1.13.1
 Built:           Fri Sep 28 19:45:08 2018
 OS/Arch:         linux/amd64
 Experimental:    false

etcd

[root@group20511 ~]# etcd --version
etcd Version: 3.2.22
Git SHA: 1674e68
Go Version: go1.9.4
Go OS/Arch: linux/amd64

kubernetes

[root@group20511 ~]# kubectl version
Client Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"5", GitVersion:"v1.5.2", GitCommit:"269f928217957e7126dc87e6adfa82242bfe5b1e", GitTreeState:"clean", BuildDate:"2017-07-03T15:31:10Z", GoVersion:"go1.7.4", Compiler:"gc", Platform:"linux/amd64"}

搭配yum源

我选用的是yum源安装
也可以使用二进制安装,也可以从github上面找资源

[root@group20511 ~]# vim /etc/yum.repos.d/k8s.repo 
[kubernetes]
name=Kubernetes
baseurl=http://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=0
repo_gpgcheck=0
gpgkey=http://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
       http://mirrors.aliyun.com/kubernetes/yum/doc/rpm-package-key.gpg

这里使用的是阿里云的yum源,也可以自己在网上找适合的源。

安装前的操作

master和node都要配置
先把master端和node端的时间全部对齐

[root@group4510 ~]# ntpdate ntp1.aliyun.com
 2 Dec 17:40:15 ntpdate[13022]: adjust time server 120.25.115.20 offset -0.007960 sec

关闭防火墙和selinux

[root@group20511 ~]# systemctl stop firewalld && systemctl disable firewalld
[root@group20511 ~]# setenforce 0
[root@group20511 ~]# vim /etc/selinux/config 
SELINUX=disabled

安装部署master

安装etcd和kubernetes

[root@group20511 ~]# yum -y install kubernetes-master etcd

修改配置文件


vim /etc/etcd/etcd.conf
保持下列的配置是 开启并且正确的

ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_PEER_URLS="http://172.24.205.11:2380,http://127.0.0.1:2380"
ETCD_LISTEN_CLIENT_URLS="http://172.24.205.11:2379,http://127.0.0.1:2379"
ETCD_NAME="default"
ETCD_ADVERTISE_CLIENT_URLS="http://127.0.0.1:2379"
ETCD_INITIAL_CLUSTER="default=http://172.24.205.11:2380"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster"
ETCD_INITIAL_CLUSTER_STATE="new"

vim /etc/kubernetes/apiserver

KUBE_API_ADDRESS="--address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBE_MASTER="--master=http://172.24.205.11:8080"
KUBELET_PORT="--kubelet-port=10250"
KUBE_ETCD_SERVERS="--etcd-servers=http://127.0.0.1:2379"
KUBE_SERVICE_ADDRESSES="--service-cluster-ip-range=10.254.0.0/16"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ServiceAccount,ResourceQuota"
KUBE_API_ARGS=""

/etc/kubernetes/scheduler
/etc/kubernetes/controller-manager
这两个服务的配置文件暂时不需要配置

开启服务

[root@group20511 ~]# systemctl start etcd
[root@group20511 ~]# systemctl start kube-scheduler
[root@group20511 ~]# systemctl start kube-apiserver
[root@group20511 ~]# systemctl start kube-controller-manager

配置etcd网络

[root@group20511 ~]# etcdctl mkdir /k8s/network


[root@group20511 ~]# etcdctl set /k8s/network/config \
'{"Network":"10.2.0.0/16"}'

检测nodes

[root@group20511 ~]# kubectl get nodes

这个时候会什么都没有,因为我们还没有搭建node节点。
到这里我们的master已经全部配置完成,接下来是node节点

安装部署node节点

安装kubernetes和flanneld

[root@group20512 ~]# yum install flannel kubernetes

编辑配置文件

vim /etc/kubernetes/kubelet

KUBELET_ADDRESS="--address=172.24.205.12"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname-override=172.24.205.12"
KUBELET_API_SERVER="--api-servers=http://172.24.205.11:8080"
KUBELET_POD_INFRA_CONTAINER=""
KUBELET_ARGS=""

vim /etc/kubernetes/config

KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://172.24.205.11:8080"
KUBE_ETCD_SERVERS='--etc_servers=http://172.24.205.11:2379'

vim /etc/sysconfig/flanneld

FLANNEL_ETCD_ENDPOINTS="http://172.24.205.11:2379"
FLANNEL_ETCD_PREFIX="/k8s/network"

/etc/kubernetes/proxy 暂时可以不用配置

开启各种服务

[root@group20512 ~]# systemctl start kube-proxy
[root@group20512 ~]# systemctl start kubelet
[root@group20512 ~]# systemctl start flanneld

到这里node节点也搭配完毕了,另外一个node节点也一样的搭配。
然后可以回到master再次使用获得节点的命令

[root@group20511 ~]# kubectl get nodes
NAME            STATUS     AGE
127.0.0.1       NotReady   4d
172.24.205.12   Ready      3d
172.24.205.13   NotReady   3d

node ip和pod ip互通需要
在这里插入图片描述cluster ip互通需要
在这里插入图片描述

你可能感兴趣的:(docker)