1、环境准备

基于CentOS-7-x86_64-Minimal-2009.iso,使用VMware构建3个linux环境
master: 10.1.14.11
node1:  10.1.14.15
node2:  10.1.14.16

在这里插入图片描述
三台机器前期工作准备
关闭防火墙服务:

systemctl stop firewalld
systemctl disable firewalld

关闭selinux:

vi /etc/selinux/config
SELINUX=disabled #修改

Kubernetes集群组件说明:

– etcd 一个高可用的K/V键值对存储和服务发现系统  #master
– kube-apiserver 提供kubernetes集群的API调用  #master
– kube-controller-manager 确保集群服务  #master
– kube-scheduler 调度容器,分配到Node  #master
– kubelet 在Node节点上按照配置文件中定义的容器规格启动容器  #node
– kube-proxy 提供网络代理服务,将service与pod打通  #node
– flannel 实现夸主机的容器网络的通信  #node

2、master安装部署
yum安装etcd、kubernetes-master:

yum install etcd kubernetes-master  -y

配置etcd文件

vi /etc/etcd/etcd.conf
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_NAME="default"
ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"

配置apiserver文件

vi /etc/kubernetes/apiserver
KUBE_API_ADDRESS="--insecure-bind-address=0.0.0.0"
KUBE_API_PORT="--port=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,ResourceQuota"
KUBE_API_ARGS=""

启动etcd、kube-apiserver、kube-controller-manager、kube-scheduler等服务,并设置开机启动

for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do 
	systemctl start $SERVICES;
	systemctl enable $SERVICES;
	systemctl status $SERVICES; 
done

在etcd中定义flannel网络

etcdctl mk /atomic.io/network/config '{"Network":"172.40.0.0/16"}'

#可以删除这个网段
etcdctl rm /atomic.io/network/config
PrevNode.Value: {"Network":"172.40.0.0/16"}

3、node节点安装部署
这里以node1为演示,其中node2是配置方式是一样的,修改一下ip即可
yum安装flannel、kubernetes-node

yum  install flannel kubernetes-node  -y

为flannel网络指定etcd服务

vi /etc/sysconfig/flanneld
FLANNEL_ETCD_ENDPOINTS="http://10.1.14.11:2379"
FLANNEL_ETCD_PREFIX="/atomic.io/network" #和master配置的etcd要一致

配置kubernetes

vi /etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
KUBE_LOG_LEVEL="--v=0"
KUBE_ALLOW_PRIV="--allow-privileged=false"
KUBE_MASTER="--master=http://10.1.14.11:8080"

配置kubelet

vi /etc/kubernetes/kubelet
KUBELET_ADDRESS="--address=0.0.0.0"
KUBELET_PORT="--port=10250"
KUBELET_HOSTNAME="--hostname-override=10.1.14.15"
KUBELET_API_SERVER="--api-servers=http://10.1.14.11:8080"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
KUBELET_ARGS=""

所有Node节点上启动flanneld、docker、kube-proxy、kubelet服务,并设置开机启动

for SERVICES in flanneld docker kube-proxy kubelet; do 
	systemctl start $SERVICES;
	systemctl enable $SERVICES;
	systemctl status $SERVICES; 
done

这里强调一下,一定要注意etcd—->flannel—–>docker的先后启动顺序,否则会导致pod里边的ip会和其他node节点的pod不在一个网段,通信就有问题

4、验证集群状态
验证集群是否安装成功
master执行如下命令:

kubectl get node
NAME         STATUS    AGE
10.1.14.15   Ready     3m
10.1.14.16   Ready     3m

查看网络情况

etcdctl ls -r | grep subnets
/atomic.io/network/subnets
/atomic.io/network/subnets/172.40.7.0-24
/atomic.io/network/subnets/172.40.3.0-24

etcdctl get /atomic.io/network/subnets/172.40.7.0-24
{"PublicIP":"10.1.14.15"}

etcdctl get /atomic.io/network/subnets/172.40.3.0-24
{"PublicIP":"10.1.14.16"}

在这里插入图片描述

Logo

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

更多推荐