kubernetes集群搭建

  • 安装机器环境准备
  • master节点安装
  • node节点安装
  • 测试

1,安装环境准备

我的集群安装准备了4台虚拟机

  • 192.168.122.11 master节点
  • 192.168.122.12 node1节点
  • 192.168.122.13 node2节点
  • 192.168.122.14 node3节点
  • 四台机器都安装了centos7系统,安装过程中选择了最小安装,点选了右侧的基础开发组件

  • 配置网络


  • 修改hosts文件


  • 可以通过ping命令测试网络是否设置成功

    -网络配置成功之后,修改centos系统的yum源,163的源

  • yum install -y wget
    rm -f /etc/yum.repos.d/CentOS-Base.repo
    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
    yum clean all
    yum makecache
    关闭防火墙
  • systemctl stop firewalld
    systemctl disable firewalld
    systemctl status firewalld

关闭selinux

修改/etc/selinux/config 文件 将SELINUX=enforcing改为SELINUX=disabled

reboot重启机器

扫描二维码关注公众号,回复: 2733146 查看本文章

至此所有机器完成基础环境准备。

2,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

3,node节点安装

yum -y install flannel docker kubernetes

/etc/sysconfig/flanneld

# Flanneld configuration options
FLANNEL_ETCD="http://192.168.122.11:2379"
# etcd url location.  Point this to the server where etcd runs
FLANNEL_ETCD_ENDPOINTS="http://192.168.122.11: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.122.11: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.122.12"
    
    # location of the api-server
    KUBELET_API_SERVER="--api-servers=http://192.168.122.11:8080"
    
    # pod infrastructure container
    #KUBELET_POD_INFRA_CONTAINER=""
    
    
    KUBELET_ARGS="--cluster-dns=192.168.122.11 --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

4,测试

[root@master ~]# kubectl get nodes
NAME             STATUS     AGE
192.168.122.12   NotReady   56m
192.168.122.13   NotReady   14m
192.168.122.14   NotReady   14m




猜你喜欢

转载自blog.csdn.net/shengerjianku/article/details/80438221