美文网首页
kubernetes(k8s)集群搭建

kubernetes(k8s)集群搭建

作者: 猪丶八戒 | 来源:发表于2018-07-30 14:52 被阅读0次

    1.安装配置Kubernetes Master

    [root@server2 ~]# yum -y install etcd kubernetes-master
    [root@server2 ~]# vim /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"
    
    [root@server2 ~]# vim /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=192.168.10.0/16" #改为自己的ip段
    KUBE_ADMISSION_CONTROL="--admission-control=NamespaceLifecycle,NamespaceExists,LimitRanger,SecurityContextDeny,ResourceQuota"
    KUBE_API_ARGS=""
    
    [root@localhost ~]# vi /etc/kubernetes/config
    ###
    # kubernetes system config
    #
    # The following values are used to configure various aspects of all
    # kubernetes services, including
    #
    #   kube-apiserver.service
    #   kube-controller-manager.service
    #   kube-scheduler.service
    #   kubelet.service
    #   kube-proxy.service
    # logging to stderr means we get it in the systemd journal
    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://172.168.93.254:8080"
    
    

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

    [root@server2 ~]# for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES ; done
    

    1.2 在etcd中定义flannel网络

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

    2 安装配置Kubernetes Node

    yum -y install flannel kubernetes-node
    
    • 为flannel网络指定etcd服务,修改/etc/sysconfig/flanneld文件
    [root@server3 ~]# vim /etc/sysconfig/flanneld
    FLANNEL_ETCD="http://192.168.10.233:2379" # MASTER节点
    FLANNEL_ETCD_KEY="/atomic.io/network"
    
    • 修改/etc/kubernetes/config文件
    [root@server3 ~]# vim /etc/kubernetes/config
    KUBE_LOGTOSTDERR="--logtostderr=true"
    KUBE_LOG_LEVEL="--v=0"
    KUBE_ALLOW_PRIV="--allow-privileged=false"
    KUBE_MASTER="--master=http://192.168.10.233:8080" # MASTER节点
    
    • 修改对应node的配置文件/etc/kubernetes/kubelet
    [root@server3 ~]# vim /etc/kubernetes/kubelet
    KUBELET_ADDRESS="--address=0.0.0.0"
    KUBELET_PORT="--port=10250"
    KUBELET_HOSTNAME="--hostname-override=172.25.27.3" #修改成对应Node的IP
    KUBELET_API_SERVER="--api-servers=http://172.25.27.2:8080" #指定Master节点的API Server
    KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
    
    • 在所有Node节点上启动kube-proxy,kubelet,docker,flanneld等服务,并设置开机启动。
    [root@server3 ~]# for SERVICES in kube-proxy kubelet docker flanneld;do systemctl restart $SERVICES;systemctl enable $SERVICES;systemctl status $SERVICES; done
    

    3.验证集群是否安装成功

    在master上执行如下命令

    [root@server2 ~]# kubectl get node
    NAME          LABELS                               STATUS    AGE
    172.25.27.3   kubernetes.io/hostname=172.25.27.3   Ready     14m
    

    相关文章

      网友评论

          本文标题:kubernetes(k8s)集群搭建

          本文链接:https://www.haomeiwen.com/subject/nfdfvftx.html