码迷,mamicode.com
首页 > Web开发 > 详细

基于kubeadm部署kubernetes集群(一)

时间:2020-02-08 19:42:10      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:docke   aliyun   echo   roo   running   master   系统版本   firewalld   target   

一、主机规划

角色名称    配置    域名    IP地址
master    2C8G/4G    master.example.com    192.168.0.1
node1    2C4G/2G    node1.example.com    192.168.0.2
node2    2C4G/2G    node2.example.com    192.168.0.3

二、软件要求

操作系统版本: CentOS Linux release 7.3.1611 (Core)

Docker版本:1.13.1, build 07f3374/1.13.1

Kubernetes版本: v1.13.1

三、部署步骤

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节点已初步部署完成

 

###远程拉取镜像,tag镜像py脚本

#coding:utf8
import os

S_registry = registry.cn-beijing.aliyuncs.com/imcto/
#S_registry = ‘registry.cn-shenzhen.aliyuncs.com/cp_m/‘
D_registry = k8s.gcr.io/

master_image = [kube-apiserver:v1.13.1,kube-controller-manager:v1.13.1,
                kube-scheduler:v1.13.1,kube-proxy:v1.13.1,pause:3.1,
                etcd:3.2.24,coredns:1.2.6,flannel:v0.10.0-amd64]
#master_image = [‘flannel:v0.10.0-amd64‘]

#下载镜像
def PullImage(registry,images):
    print("-共%s个镜像" %(len( images),))
    index = 1
    for image in images:
        print("开始下载第[%d]个镜像---> [%s]" %(index, image))
        cmd = "docker pull " + registry + image
        os.system(cmd)
        print("done!")
        index += 1

#更改tag
def TagImage(sregistry,dregistry,images):
    print("一共%s个镜像" %(len(images),))
    index = 1
    for image in images :
        print("开始tag第[%d]个镜像---> [%s] ---> [%s]" %(index, sregistry+image, dregistry+image))
        cmd = "docker tag " + sregistry+image + " " + dregistry + image
        os. system(cmd)
        print("done!")
        index += 1

#run
if __name__==__main__:
   # PullImage(S_registry , master_image)
    TagImage(S_registry, D_registry, master_image)

 

基于kubeadm部署kubernetes集群(一)

标签:docke   aliyun   echo   roo   running   master   系统版本   firewalld   target   

原文地址:https://www.cnblogs.com/weisunblog/p/12275711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!