美文网首页
Kubernetes集群部署

Kubernetes集群部署

作者: 再让我吃一口 | 来源:发表于2019-02-15 10:42 被阅读0次

    Kubernetes

    什么是kubernetes就不介绍了,直接来部署。

    本文示例安装环境

    3台虚拟机(1台master主节点,2台node工作节点)
    master:192.168.188.151
    node1 :192.168.188.152
    node2 :192.168.188.153

    部署master节点

    • 安装etcd和Kubernetes
    yum -y install etcd kubernetes
    
    • 配置etcd
    #查看etcd配置文件
    cat /etc/etcd/etcd.conf |grep -Ev '^[[:space:]].*|^#'
    #修改配置
    vim /etc/etcd/etcd.conf
    #etcd配置
    TCD_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"
    
    • 配置Kubernetes API Server
    #查看apiserver配置文件
    cat /etc/kubernetes/apiserver |grep -Ev '^[[:space:]].*|^#'
    #修改配置
    vim /etc/kubernetes/apiserver
    #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=""
    
    • 启动etcd、kube-apiserver、kube-controller-manager、kube-scheduler服务
    for SERVICES in etcd kube-apiserver kube-controller-manager kube-scheduler; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
    done
    
    • 在etcd中配置flannel网络
    #设置网段
    etcdctl mk /atomic.io/network/config '{"Network":"172.10.0.0/16"}'
    #查看设置是否成功
    etcdctl get /atomic.io/network/config
    

    部署node节点

    • 安装flannel和Kubernetes
    yum -y install flannel kubernetes
    
    • 配置flannel
    cat /etc/sysconfig/flanneld |grep -Ev '^[[:space:]].*|^#'
    #修改flannel配置
    vim /etc/sysconfig/flanneld
    #flannel配置   修改ENDPOINTS为master节点的ip
    FLANNEL_ETCD_ENDPOINTS="http://192.168.188.151:2379"
    FLANNEL_ETCD_PREFIX="/atomic.io/network"
    

    -配置Kubernetes

    #查看kubernetes配置文件
    cat /etc/kubernetes/config |grep -Ev '^[[:space:]].*|^#'
    #修改Kubernetes配置
    vim /etc/sysconfig/flanneld
    #Kubernetes配置   修改KUBE_MASTER为master节点的ip
    KUBE_LOGTOSTDERR="--logtostderr=true"
    KUBE_LOG_LEVEL="--v=0"
    KUBE_ALLOW_PRIV="--allow-privileged=false"
    KUBE_MASTER="--master=http://192.168.188.151:8080"
    

    -配置kubelet

    #修改kubelet配置
    vim /etc/sysconfig/flanneld
    #kubelet配置   修改HOSTNAME为自身节点的ip,API_SERVER为master节点的ip
    KUBELET_ADDRESS="--address=0.0.0.0"
    KUBELET_PORT="--port=10250"
    KUBELET_HOSTNAME="--hostname-override=192.168.188.152"
    KUBELET_API_SERVER="--api-servers=http://192.168.188.151:8080"
    KUBELET_POD_INFRA_CONTAINER="--pod-infra-container-image=registry.access.redhat.com/rhel7/pod-infrastructure:latest"
    KUBELET_ARGS=""
    
    • 开启kube-proxy,kubelet,docker,flanneld服务
    for SERVICES in kube-proxy kubelet docker flanneld; do
    systemctl restart $SERVICES
    systemctl enable $SERVICES
    systemctl status $SERVICES
    done
    

    环境验证

    • 回到master节点服务器,输入
    kubectl get nodes
    
    验证

    会发现两个node节点的状态已经处于Ready状态了。

    相关文章

      网友评论

          本文标题:Kubernetes集群部署

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