1虚拟机配置

hostname

配置

IP

组件

k8s-master

5G内存

10G硬盘

2CPU

private=121.xx.xx.155,

chronyd

etcd

flannel

kube-apiserver

kube-controller-manager kube-scheduler

docker

k8s-node1

private=120.xx.xx.18,

chronyd

flannel

kube-proxy, kubelet

docker

k8s-node2

private=121.xx.xx.130

chronyd

flannel

kube-proxy, kubelet

docker

2、关闭防火墙和selinux

在三个实例中分别执行如下命令:

systemctl stop firewalld.service

systemctl enable firewalld.service

二、搭建

1master节点

1.1配置etcd

yum -y install etcd

vi  /etc/etcd/etcd.conf

注释掉ETCD_LISTEN_CLIENT_URLS=http://localhost:2379

添加ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379

对于ETCD_ADVERTISE_CLIENT_URLS,进行同样的操作

1.2配置etcd网络

systemctl restart etcd

etcdctl mk /coreos.com/network/config '{"Network":"172.17.0.0/16"}'

执行结果为:{"Network":"172.17.0.0/16"}

1.3配置Kubernetes API server

yum -y install kubernetes

vi /etc/kubernetes/apiserver

注释掉KUBE_API_ADDRESS="--insecure-bind-address=127.0.0.1"

添加KUBE_API_ADDRESS="--address=0.0.0.0"

删除KUBE_ADMISSION_CONTROL默认包含的ServiceAccount

1.4配置flannel

flannel这里不做说明,可自行百度

yum -y install flannel

vi /etc/sysconfig/flannel

注释掉FLANNEL_ETCD=http://127.0.0.1:2379

添加FLANNEL_ETCD=http://172.11.1.20:2379

注释掉FLANNEL_ETCD_KEY="/atomic.io/network"

添加FLANNEL_ETCD_KEY="/coreos.com/network"

在最后添加FLANNEL_OPTIONS="--iface=eth0"eth0为当前节点的主网卡)

1.5启动服务

使用systemctl  startsystemctl  enable命令对一下各个服务启动并设置为开机启动

etcd kube-apiserver kube-controller-manager kube-scheduler flanneldocker

说明:master节点并不需要docker服务,此处安装docker是为了在master节点启动一个私有docker镜像库.

2minion节点(120.xx.xx.18为例)


2.1  pause
docker pull docker pull registry.aliyuncs.com/paiding/pause:2.0
docker tag registry.aliyuncs.com/paiding/pause:2.0 gcr.io/google_containers/pause:2.0
 docker tag gcr.io/google_containers/pause:2.0 gcr.io/google_containers/pause

2.2配置flannel

yum -y install flannel

vi /etc/sysconfig/flannel

注释掉FLANNEL_ETCD=http://127.0.0.1:2379

添加FLANNEL_ETCD=http://121.xx.xx.155:2379

注释掉FLANNEL_ETCD_KEY="/atomic.io/network"

添加FLANNEL_ETCD_KEY="/coreos.com/network"

在最后添加FLANNEL_OPTIONS="--iface=eth0"

启动服务systemctl start flannel ;systemctl enable flanneld.service

上传配置在当前目录下新建config.json,添加如下内容

{

"Network": "172.17.0.0/16",

"SubnetLen": 24,

"Backend": {

"Type": "vxlan",

"VNI": 7890

}

}

上传配置到master上的etcd服务器

curl -L http://121.40.104.155:2379/v2/keys/coreos.com/network/config -X PUT --data-urlencode value@config.json

执行结果:

{"action":"set","node":{"key":"/coreos.com/network/config","value":"{\n\"Network\": \"172.17.0.0/16\",\n\"SubnetLen\":

24,\n\"Backend\": {\n \"Type\": \"vxlan\",\n \"VNI\": 7890\n }\n }\n","modifiedIndex":64,"createdIndex":64},"prevNode":

{"key":"/coreos.com/network/config","value":"{\"Network\":\"172.17.0.0/16\"}","modifiedIndex":4,"createdIndex":4}}

 

2.3安装docker

yum install  -y docker

systemctl enable docker

systemctl start docker

说明:实际上。在即将进行的下一步(配置kubenetes)中,执行yum install  kubernetes时会同时安装docker,但是,可能由于当前yum源中的docker版本与kubernetes冲突,因此,这样安装的docker启动一直失败,为了绕过这一点,在此处先安装并启动了docker服务。

2.4配置kubernetes

yum -y install kubernetes

vi /etc/kubernetes/config

注释掉KUBE_MASTER="--master=http://127.0.0.1:8080"

添加KUBE_MASTER="--master=http://121.40.104.155:8080"

vi /etc/kubernetes/kubelet

删除所有内容,然后添加如下内容】

KUBELET_ADDRESS="--address=0.0.0.0"

KUBELET_PORT="--port=10250"

# change the hostname to minion IP address

KUBELET_HOSTNAME="--hostname-override=172.16.1.24"

KUBELET_API_SERVER="--api-servers=http://121.40.104.155:8080"

KUBELET_ARGS=""

2.5启动服务

使用systemctl  enablesystemctl  start命令启动kube-proxy kubelet服务,并设置为开机启动

2.6查看集群状态

master节点执行如下命令

kubectl  get nodes

查看node节点的状态为ready即可


Logo

K8S/Kubernetes社区为您提供最前沿的新闻资讯和知识内容

更多推荐