kubernetes集群搭建
上周领导安排我搭建一下kubernetes的集群环境,经过多日的努力依靠百度完成了该集群的搭建,特此记录
- 安装机器环境准备
- master节点安装
- node节点安装
- 测试
安装机器环境准备
我的集群安装准备了4台虚拟机
- 192.168.51.198 master节点
- 192.168.51.199 node1节点
- 192.168.51.205 node2节点
192.168.51.232 私有docker仓库节点
四台机器都安装了centos7系统,安装过程中选择了最小安装,点选了右侧的基础开发组件
虚拟机选择桥接网络,配置网络环境
vi /etc/sysconfig/network-scripts/ifcfg-enp0s3
service network restart
重启网络vi /etc/hosts
host配置可以通过ping命令测试网络是否设置成功
-网络配置成功之后,修改centos系统的yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum makecache
关闭防火墙
systemctl stop firewalld
systemctl disable firewalld
systemctl status firewalld
关闭selinux
修改/etc/selinux/config 文件
将SELINUX=enforcing改为SELINUX=disabled
reboot重启机器
至此所有机器完成基础环境准备。
master节点安装
yum -y install etcd docker kubernetes
etcd配置
/etc/etcd/etcd.conf
ETCD_NAME=default
ETCD_DATA_DIR="/var/lib/etcd/default.etcd"
ETCD_LISTEN_CLIENT_URLS="http://0.0.0.0:2379"
ETCD_ADVERTISE_CLIENT_URLS="http://localhost:2379"
/etc/kubernetes/apiserver
KUBE_API_ADDRESS="--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,SecurityContextDeny,ResourceQuota"
KUBE_API_ARGS=""
/etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"
# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="--allow-privileged=false"
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://master:8080"
执行脚本依次启动服务
for SERVICES in etcd docker kube-apiserver kube-controller-manager kube-scheduler; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES -l
done
etcd网络配置
etcdctl mk /atomic.io/network/config '{"Network":"172.17.0.0/16"}'
测试
kubectl get nodes
node节点安装
yum -y install flannel docker kubernetes
/etc/sysconfig/flanneld
# Flanneld configuration options
FLANNEL_ETCD="http://192.168.51.198:2379"
# etcd url location. Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://192.168.51.198:2379"
# etcd config key. This is the configuration key that flannel queries
# For address range assignment
FLANNEL_ETCD_PREFIX="/atomic.io/network"
# Any additional options that you want to pass
#FLANNEL_OPTIONS=""
/etc/kubernetes/config
KUBE_LOGTOSTDERR="--logtostderr=true"
# journal message level, 0 is debug
KUBE_LOG_LEVEL="--v=0"
# Should this cluster be allowed to run privileged docker containers
KUBE_ALLOW_PRIV="--allow-privileged=false"
# How the controller-manager, scheduler, and proxy find the apiserver
KUBE_MASTER="--master=http://192.168.51.198:8080"
/etc/kubernetes/kubelet、
# The address for the info server to serve on (set to 0.0.0.0 or "" for all interfaces)
KUBELET_ADDRESS="--address=0.0.0.0"
# The port for the info server to serve on
KUBELET_PORT="--port=10250"
# You may leave this blank to use the actual hostname
KUBELET_HOSTNAME="--hostname-override=192.168.51.205"
# location of the api-server
KUBELET_API_SERVER="--api-servers=http://192.168.51.198:8080"
# pod infrastructure containerKUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=192.168.51.199:5000/pause"
KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=192.168.51.232:5000/pause:v2"
KUBELET_ARGS="--cluster-dns=192.168.51.198 --cluster-domain=atomic.io/network"
node节点服务脚本启动
for SERVICES in kube-proxy kubelet docker flanneld; do
systemctl restart $SERVICES
systemctl enable $SERVICES
systemctl status $SERVICES
done
测试
kubectl get nodes
NAME STATUS AGE
node1 Ready 5d
node2 Ready 5d
至此集群环境搭建基本完成