K8S集群简易搭建版(未配证书, 配证书烦死人......)

默认已经安装好docker: docker安装请参考: Ubuntu安装Docker

关闭交换区

  • swap打开的情况下,kubelet无法正常运行

    root@node01:~# sudo swapoff -a
    root@node01:~# free -h
                  total        used        free      shared  buff/cache   available
    Mem:           3.5G        1.1G        672M        7.4M        1.8G        2.2G
    Swap:            0B          0B          0B
    

安装K8S

  • vim /etc/apt/sources.list 添加阿里云镜像

    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    
  • apt-get update 更新apt源

  • 下载K8S组件

    sudo apt install -y kubelet kubeadm kubectl
    
    • ps: 网络不好的话会下的比较久
  • 启动kubelet

    sudo systemctl enable kubelet && sudo systemctl start kubelet
    
  • 安装完后查看版本

    root@node01:~# kubelet --version
    Kubernetes v1.17.3
    

master 节点初始化

  • 由于kubeadm 默认从官网k8s.grc.io下载所需镜像,国内无法访问,因此需要通过–image-repository指定阿里云镜像仓库地址。

    kubeadm init --image-repository registry.aliyuncs.com/google_containers --kubernetes-version v1.17.3 --pod-network-cidr=10.244.0.0/16
    
    • 执行成功最终行会看到:

      kubeadm join 192.168.180.130:6443 --token zwoa7g.rwd7nb16k3z8aygg 
          --discovery-token-ca-cert-hash sha256:5a214e1ca05b75aa88e9ace7691092f6159307cd727fa1306d48608a0a51b297 
      
  • 在其他主机上依次执行token join命令

  • 查看集群所有节点:

    root@node01:~# kubectl get nodes -o wide
    NAME     STATUS   ROLES    AGE   VERSION   INTERNAL-IP       EXTERNAL-IP   OS-IMAGE             KERNEL-VERSION     CONTAINER-RUNTIME
    node01   Ready    master   20h   v1.17.3   192.168.180.130   <none>        Ubuntu 18.04.2 LTS   5.3.0-42-generic   docker://19.3.8
    node02   Ready    <none>   20h   v1.17.3   192.168.180.131   <none>        Ubuntu 18.04.2 LTS   5.3.0-42-generic   docker://19.3.8
    node03   Ready    <none>   20h   v1.17.3   192.168.180.132   <none>        Ubuntu 18.04.2 LTS   5.3.0-42-generic   docker://19.3.8
    node04   Ready    <none>   20h   v1.17.3   192.168.180.133   <none>        Ubuntu 18.04.2 LTS   5.3.0-42-generic   docker://19.3.8
    node05   Ready    <none>   20h   v1.17.3   192.168.180.134   <none>        Ubuntu 18.04.2 LTS   5.3.0-42-generic   docker://19.3.8
    
原文地址:https://www.cnblogs.com/ronnieyuan/p/12603946.html