基于kubeadm部署kubernetes集群(一)

2021-04-18 08:26

阅读:458

1.systemctl stop firewalld && systemctl disable firewalld  #关闭防火墙,关闭开机自动开启防火墙
2.vim /etc/selinux/config  修改第6行,SELINUX=disabled
3.swapoff -a  #关闭swap设置 将/etc/fstab文件中所有设置为swap的设备关闭
4.yes | cp /etc/fstab /etc/fstab_bak  #备份/etc/fstab
5.grep -v swap /etc/fstab_bak > /etc/fstab   #重写/etc/fstab
6.vim /etc/hosts   #更改hosts文件,配置域名

  192.168.33.9 master.example.com
  192.168.33.10 node1.example.com
  192.168.33.11 node2.example.com
7.安装docker
  yum -y install docker
  systemctl start docker && systemctl enable docker #启动docker并设置开机启动
  #启动时可能会报错:Job for docker.service failed because。。。参考另一篇博客点击此处即可查看
8.配置阿里云镜像源
  vim /etc/yum.repos.d/k8s.repo
    
[kubernetes]
      name=kubernetes repo

       baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/gpgcheck=0

 9.安装kubelet kubeadm kubectl

  #这里需要注意,如果你直接运行指令yum -y install kubelet kubeadm kubectl,这里将会自动为你下载最新版本,我们这里采用低版本(1.13.0)进行安装
  yum -y install kubelet-1.13.0 kubeadm-1.13.0 kubernetes-cni-0.6.0 kubectl-1.13.0
  systemctl enable kubelet && systemctl start kubelet
 10.执行脚本远程拉取镜像(脚本附在最后)

 11.master节点-配置kubectl、flannel网络(注意这里的ip地址用本机ip)

  kubeadm init --kubernetes-version=v1.13.1 --apiserver-advertise-address 192.168.0.9 --pod-network-cidr=10.244.0.0/16

  注意这里完成操作后会有这样一段提示:

    You can now join any number of machines by running the following on each node

       as root:

      kubeadm join 192.168.0.9:6443 --token vatur3.j0y4md12rz4h04mp --discovery-token-ca-cert-hash sha256:f684729944a449a5ab20d40a664b1b3fca99a8d            33c09fb5db8e1ce125c6e4632
  将kubeadm这段指令记好,随后添加节点需要用到

 12.配置kubectl

  echo "export KUBECONFIG=/etc/kubernetes/admin.conf" >> ~/.bash_profile

  source ~/.bash_profile  

 13.

  curl https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml -o kube-flannel.yml
  docker tag k8s.gcr.io/flannel:v0.10.0-amd64 quay.io/coreos/flannel:v0.11.0-amd64  #更改镜像名
  kubectl apply -f kube-flannel.yml
 14.执行 kubectl get nodes

  此时进行确认,若master节点 not ready,重启docker即可:

  systemctl restart docker


  kubectl get nodes
  NAME           STATUS    ROLES    AGE    VERSION
  master.example.com    Ready    master    25m    v1.13.0

 15.此时master节点已初步部署完成


评论


亲,登录后才可以留言!