主机信息:

master节点:  节点功能Master、etcd、Registry; 主机名: master ; IP地址:192.168.80.161

node节点: 节点功能Node1; 主机名:node1; IP地址:192.168.80.162

 

1: 设置机器的主机名

master主机上执行:

hostnamectl --static set-hostname master

node主机上执行:

hostnamectl --static set-hostname node1

2: 关闭对应机器上的防火墙

systemctl disable firewalld.service

systemctl stop firewalld.service

 

3:master 节点

1)部署etcd

k8s运行依赖etcd,需要先部署etcd;

yum install etcd -y

yum 安装的etcd默认配置文件在/etc/etcd/etcd.conf

vim /etc/etcd/etcd.conf(修改部分)

ETCD_NAME="master"

ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379,http://0.0.0.0:4001"

ETCD_ADVERTISE_CLIENT_URLS="http://etcd:2379,http://etcd:4001"

启动并验证状态

[root@localhost ~]# systemctl start etcd
[root@localhost ~]#  etcdctl set testdir/testkey0 0
0
[root@localhost ~]#  etcdctl get testdir/testkey0 
0
[root@localhost ~]# etcdctl -C http://etcd:4001 cluster-health
cluster is healthy
[root@localhost ~]# etcdctl -C http://etcd:2379 cluster-health
cluster is healthy

2)部署Docker

yum install docker

配置Docker配置文件,使其允许从registry中拉取镜像

vim /etc/sysconfig/docker(增加部分)

OPTIONS='--insecure-registry registry:5000'

启动开机自启并开启服务:

chkconfig docker on

service docker start

3)安装kubernetes

yum install kubernetes

配置并启动Kubernetes

    Kubernetes API Server

    Kubernetes Controller Manager

    Kubernetes Scheduler

修改如下配置部分:

一: vim /etc/kubernetes/apiserver

KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_API_PORT="--port=8080"
KUBE_ETCD_SERVERS="--etcd-servers=http://etcd:2379"
KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"

二: vim /etc/kubernetes/config

KUBE_MASTER="--master=http://master:8080"

启动服务并设置开机自启动

systemctl enable kube-apiserver.service
systemctl start kube-apiserver.service
systemctl enable kube-controller-manager.service
systemctl start kube-controller-manager.service
systemctl enable kube-scheduler.service
systemctl start kube-scheduler.service

检查安装情况: netstat -ntlp 查看端口是否启用

 

4: node节点部署

1) docker 安装

yum install docker

配置Docker配置文件,使其允许从registry中拉取镜像

vim /etc/sysconfig/docker(增加部分)

OPTIONS='--insecure-registry registry:5000'

启动开机自启并开启服务:

chkconfig docker on

service docker start

 

2)安装kubernetes

yum install kubernetes

配置并启动Kubernetes

    kubelet

    kubernetes proxy

修改配置如下:

vim /etc/kubernetes/config

KUBE_MASTER="--master=http://master:8080"

vim /etc/kubernetes/kubelet

KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_HOSTNAME="--hostname-override=node-1"
KUBELET_API_SERVER="--api-servers=http://master:8080"

启动并设置开机自启动
systemctl enable kubelet.service
systemctl start kubelet.service
systemctl enable kube-proxy.service
systemctl start kube-proxy.service

检查安装情况: netstat -ntlp 查看端口是否启用

5: 创建覆盖网络Flannel

master和node节点上共同执行:

yum install flannel

配置Flannel

vim /etc/sysconfig/flanneld

FLANNEL_ETCD_ENDPOINTS="http://etcd:2379"

配置etcd中关于flannel的key

  Flannel使用Etcd进行配置,来保证多个Flannel实例之间的配置一致性,所以需要在etcd上进行如下配置:(‘/atomic.io/network/config’这个key与上文/etc/sysconfig/flannel中的配置项FLANNEL_ETCD_PREFIX是相对应的,错误的话启动就会出错)

 master节点执行:etcdctl mk /atomic.io/network/config '{ "Network": "10.0.0.0/16" }'

启动Flannel 之后,需要再次重启docker和kubernete:

master上执行:

systemctl enable flanneld.service 
systemctl start flanneld.service 
service docker restart
systemctl restart kube-apiserver.service
systemctl restart kube-controller-manager.service
systemctl restart kube-scheduler.service
 

node上执行:

ystemctl enable flanneld.service 
systemctl start flanneld.service 
service docker restart
systemctl restart kubelet.service
systemctl restart kube-proxy.service
 

之后执行 kubectl get nodes查看部署情况

 

 

Logo

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

更多推荐