• K8s-Centos7.4使用kubeadm部署kubernetes1.15


    kubeadm部署kubernetes1.15

        环境准备:
            IP                  角色          系统
            192.168.1.201       master     Centos7.4
            192.168.1.202       node1      Centos7.4
            192.168.1.203       node2      Centos7.4

        先决条件:
            1.三个节点都需要设置本地解析,关闭firewalld和iptables以及selinux
                vim /etc/hosts      # 在最后添加
                    192.168.1.201       master
                    192.168.1.202       node1
                    192.168.1.203       node2
                systemctl stop firewalld && systemctl disable firewalld         # 关闭防火墙并设置为开机关闭
                iptables -F            # 清空Iptables规则
                vim /etc/sysconfig/selinux
                    改:SELINUX=enforcing
                    为:SELINUX=disabled
            2.配置时间同步(ntp)
                master节点:
                    yum install ntp -y         # 安装ntp服务
                    vim /etc/ntp.conf       # 修改ntp服务配置文件,添加在server处添加以下内容:
                        server 127.127.1.0
                        fudge  127.127.1.0  stratum 10
                    systemctl restart ntpd && systemctl enable ntpd     # 重启ntpd服务并设置为开机自起
                node节点:
                    yum install ntpdate -y      # 安装客户端时间同步工具
                    ntpdate 192.168.1.201       # 同步ntp服务端
            3.三个节点都需要设置yum源:docker源(aliyun),kubernetes源(aliyun),epel源(epel-release)
                配置docker源:
                    安装必要的一些系统工具:
                        yum install -y yum-utils device-mapper-persistent-data lvm2
                    添加docker-ce源:
                        yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
                    查询yum源中docker-ce的版本
                        yum list docker-ce.x86_64 --showduplicates | sort -r
                    安装指定版本的docker-ce
                        yum -y install docker-ce-[VERSION]
                        例如:
                            yum -y install docker-ce-17.03.0.ce.1-1.el7.centos
                配置kubernetes源:
                    cat <<EOF > /etc/yum.repos.d/kubernetes.repo
                    [kubernetes]
                    name=Kubernetes
                    baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
                    enabled=1
                    gpgcheck=0
                    repo_gpgcheck=1
                    gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
                    EOF
                配置阿里云yum源:
                    wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
                配置epel源:
                    yum install epel-release -y
        开始安装:
            master节点:
                1.安装对应版本的相关组件:
                    yum -y install docker-ce-18.06.3.ce-3.el7 kubelet-1.15.1-0 kubeadm-1.15.1-0 kubectl-1.15.1-0
                2.启动docker服务并设置为开机自启动:
                    systemctl enable docker
                    systemctl start docker
                3.确保以下两个值为1:
                    [root@master ~]# cat /proc/sys/net/bridge/bridge-nf-call-ip6tables
                    1
                    [root@master ~]# cat /proc/sys/net/bridge/bridge-nf-call-iptables
                    1
                4.配置kubelet服务网为开机自启动:
                    systemctl enable kubelet
                5.配置kubeadm:
                    将k8s组件的镜像提前上传至服务器并解压:
                        tar xf kubeadm-basic.images.tar.gz
                    提前导入kube-basic镜像:
                        docker load -i apiserver.tar
                        docker load -i coredns.tar
                        docker load  -i etcd.tar
                        docker load -i kubec-con-man.tar
                        docker load -i pause.tar
                        docker load -i proxy.tar
                        docker load -i scheduler.tar
                    查看镜像:
                        REPOSITORY                           TAG                 IMAGE ID            CREATED             SIZE
                        k8s.gcr.io/kube-apiserver            v1.15.1             68c3eb07bfc3        11 months ago       207MB
                        k8s.gcr.io/kube-proxy                v1.15.1             89a062da739d        11 months ago       82.4MB
                        k8s.gcr.io/kube-scheduler            v1.15.1             b0b3c4c404da        11 months ago       81.1MB
                        k8s.gcr.io/kube-controller-manager   v1.15.1             d75082f1d121        11 months ago       159MB
                        k8s.gcr.io/coredns                   1.3.1               eb516548c180        18 months ago       40.3MB
                        k8s.gcr.io/etcd                      3.3.10              2c4adeb21b4f        19 months ago       258MB
                        k8s.gcr.io/pause                     3.1                 da86e6ba6ca1        2 years ago         742kB
                    初始化集群:
                        kubeadm init --kubernetes-version=v1.15.1 --pod-network-cidr=10.244.0.0/16 --service-cidr=10.96.0.0/12 --ignore-preflight-errors=Swap
                        --kubernetes-version=   # 指定下载镜像的标签
                        --pod-network-cidr=     # 指定pod的网络地址
                        --service-cidr=         # 指定service的网络地址
                            生成加入群集的命令:
                                kubeadm join 192.168.1.201:6443 --token cktqi6.ybynxbsgnkvmfe46
                                --discovery-token-ca-cert-hash sha256:006bf1440293a10bc93891d2069fb6fd5b94c1f8879fe8e61fdf9c964b13d7c7
                        mkdir -p $HOME/.kube
                        cp -i /etc/kubernetes/admin.conf $HOME/.kube/config
                        chown $(id -u):$(id -g) $HOME/.kube/config
                        kubectl get componentstatus     # 查看master节点各组件是否健康
                    安装flannel插件:
                        将flannel-master.zip从github上面下载下来,并将其上传到服务器上面,具体路径为:https://github.com/coreos/flannel
                            tar xf flannel-master.zip       # 解压,找到其中的kube-flannel.yml这个文件
                            kubectl apply -f /root/flannel-master/Documentation/kube-flannel.yml        # 安装flannel
            node节点:
                前四步与安装master一致,参考上面master的安装步骤即可,此处不再赘述
                使用以下命令将node节点加入到集群中:
                    kubeadm join 192.168.1.201:6443 --token cktqi6.ybynxbsgnkvmfe46
                                --discovery-token-ca-cert-hash sha256:006bf1440293a10bc93891d2069fb6fd5b94c1f8879fe8e61fdf9c964b13d7c7
                        参数解释:
                            --token:令牌即预共享秘钥
                            --discovery-token-ca-cert-hash:节点证书的hash码
            安装完成后:
                使用以下命令在master节点验证:
                    kubectl get nodes       # 获取存在的所有节点

  • 相关阅读:
    作为字节跳动的面试官,有些话我不得不说!
    阿里面试 Java 都问什么?万字总结!
    离职10天,面挂4家公司!
    Nginx 又一牛 X 功能:流量拷贝
    金三银四铜五铁六,Offer收到手软!
    在阿里干了5年招聘,这10条建议我必须分享给你!
    nyoj 1238 最少换乘(dijkstra)
    hdu 1035 Robot Motion(模拟)
    网络工程 POST与GET请求方法的本质区别
    hdu 1279 验证角谷猜想(简单的模拟)
  • 原文地址:https://www.cnblogs.com/Vampire-MIn/p/13255785.html
Copyright © 2020-2023  润新知