基于Kubespray的生产级Kubernetes部署

本文详细介绍了如何利用Kubespray在VSphere环境下部署生产级别的Kubernetes集群,包括前置条件、CentOS系统模板准备、虚拟机配置、Kubespray安装步骤、K8s集群连接、存储类配置以及Helm的安装和配置。

基于Kubespray的生产级Kubernetes部署

0.源码地址

https://github.com/wiselyman/k8s-installation

1. 前置条件

​ 安装EXSI(VMware vSphere Hypervisor,本例地址为:192.168.1.50):http://dl1.technet24.ir/Downlads/Software/VMware/vCenter/67u3/VMware-VMvisor-Installer-6.7.0.update03-14320388.x86_64.iso

​ 安装VCenter(VMware vCenter Server Appliance,本例地址为:192.168.1.51):http://dl1.technet24.ir/Downloads/Software/VMware/vCenter/67u3/VMware-VCSA-all-6.7.0-14367737.iso

使用U盘将VMware-VMvisor-Installer-6.7.0.update03-14320388.x86_64.iso刻盘安装EXSI系统到一台物理机,然后打开VMware-VCSA-all-6.7.0-14367737.iso。在vcsa-ui-installer目录下按照不同的系统使用对应的界面安装VCenter。

当然如果你有直接的机器或者虚拟机也是可以的,我们只需要忽略和VMware相关的步骤即可,这次规划9台虚拟机(物理机),分别为3台master(ip:192.168.1.54-56),6台node(ip:192.168.1.57-62)。

2. 准备CentOS系统模板

  • Vsphere client下创建虚拟机目录,名称为k8s

    在这里插入图片描述

    外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-4fH7Bcjo-1570673764176)(images/vcenter-new-folder.png)]

  • VCenter下创建CentOS虚拟机:虚拟机名称为centos7

  • 安装CentOS 7.6虚拟机

  • 安装VMware Tools

    yum install -y open-vm-tools
    
  • 安装govc:https://github.com/vmware/govmomi/releases

    yum install wget
    wget https://github.com/vmware/govmomi/releases/download/prerelease-v0.21.0-58-g8d28646/govc_linux_amd64.gz
    gzip -d govc_linux_amd64.gz
    chmod +x govc_linux_amd64
    mv govc_linux_amd64 /usr/local/bin/govc
    
  • 配置govc

    vi .bash_profile 
    
    export GOVC_URL='192.168.1.51'
    export GOVC_USERNAME='administrator@vsphere.local'
    export GOVC_PASSWORD='Wyf.38476'
    export GOVC_INSECURE=1
    
    source .bash_profile 
    
  • 激活虚拟机UUID,后面为虚拟机名称

    govc vm.change -e="disk.enableUUID=1" -vm='centos7'
    
  • 安装perl和nettools,ansible定制虚拟机ip需使用

    yum install perl net-tools
    
  • 关闭防火墙

     systemctl stop firewalld && systemctl disable firewalld
    
  • 时间同步

    yum -y install ntp  && ntpdate ntp1.aliyun.com && systemctl start ntpd && systemctl enable ntpd
    
  • 操作机免密登陆虚拟机

    产生公钥与私钥对:

    ssh-keygen
    

    将本机的公钥复制到远程机器的authorized_keys文件中:

    ssh-copy-id root@192.168.1.5*
    
  • 将虚拟机制成模板
    在这里插入图片描述

3. 准备虚拟机

  • 安装ansible

    pip3 install PyVmomi
    pip3 install ansible
    
  • 编写ansible playbook:vm.yml

    - hosts: 127.0.0.1
      connection: local
      become: root
      gather_facts: false
      serial: 1
      tasks:
        - name:  Create Master Nodes
          vmware_guest:
            hostname: "{
         
         { vcenter_hostname }}"
            username: "{
         
         { vcenter_username }}"
            password: "{
         
         { vcenter_password }}"
            validate_certs: no
            datacenter: "{
         
         { datacenter }}"
            state: present
            folder: "{
         
         { folder }}"
            template: "{
         
         { template }}"
            name: "{
         
         { item.key }}"
            cluster: "{
         
         { cluster }}"
            disk:
              - size_gb: 30
                type: thin
                datastore: datastore1
            hardware:
              memory_mb: 2048
              num_cpus: 2
              scsi: paravirtual
            networks:
              - 
VMware vCenter Server 6.7 U3 VMware vCenter Server Appliance File size: 3.93 GB File type: iso Name: VMware-VCSA-all-6.7.0-14367737.iso Release Date: 2019-08-20 Build Number: 14367737 vCenter Server Appliance ISO. It includes the UI and CLI installer for install/upgrade/migration for VMware vCenter Server Appliance, VMware Platform Services Controller, VMware vSphere Update Manager and Update Manager Download Service (UMDS). MD5SUM: dff12f195347a61a45d3aee3278ebfca SHA1SUM: 6989f3e17278545d77251c46152c4e08e1c32db4 SHA256SUM: d0bc2c26d6313a92323ac5f8cab8838324613e6762e3a749646bac6496d4d838 VMware vCenter Server Appliance Update Bundle File size: 2.01 GB File type: zip Name: VMware-vCenter-Server-Appliance-6.7.0.40000-14367737-updaterepo.zip Release Date: 2019-08-20 Build Number: 14367737 Use this package to update from any released VMware vCenter Server Appliance 6.7 to VMware vCenter Server 6.7U3 Appliance MD5SUM: ecda33c94a71a86ab24147eb4c17eb89 SHA1SUM: 2c0759b4189f1cd4214834cdb96ec5984f059200 SHA256SUM: f1c9b4197c06fa50122d860dc51463319ae5037b9eb4ccd6c2b882d44e8fe473 VMware vCenter Server for Windows File size: 2.07 GB File type: iso Name: VMware-VIM-all-6.7.0-14367737.iso Release Date: 2019-08-20 Build Number: 14367737 Installer for VMware vCenter Server, VMware Platform Services Controller, VMware vSphere Update Manager, Update Manager Download Service (UMDS) and other vCenter Server-related modules. It enables installation of vCenter Server on Windows (Requires a 64-bit capable server). MD5SUM: 066f87b31cbfeaaf7c5777c4f3db1c01 SHA1SUM: 6aa6f192570afc89dd48e365848cbf87a87572b0 SHA256SUM: 74d758be32804856eefca00573547f001e153f2850fa815c2c2a79891432ec24 VMware vSphere Hypervisor (ESXi ISO) image (Includes VMware Tools) File size: 314.66 MB File type: iso Name: VMware-VMvisor-Installer-6.7.0.update03-14320388.x86_64.iso Release Date: 2019-08-20 Build Number: 14320388 Boot your server with this image in order to install or upgrade to ESXi (ESXi requires 64-bit capable servers). This ESXi image includes VMware Tools. MD5SUM: cafb95ae04245eb3e93fed1602b0fd3b SHA1SUM: 415f08313062d1f8d46162dc81a009dbdbc59b3b SHA256SUM: fcbaa4cd952abd9e629fb131b8f46a949844405d8976372e7e5b55917623fbe0 VMware vSphere Hypervisor (ESXi) Offline Bundle File size: 433.54 MB File type: zip Name: update-from-esxi6.7-6.7_update03.zip Release Date: 2019-08-20 Build Number: 14320388 Including VMware Tools. Use the image profiles and the VIB packages with VMware Image BuContains VIB packages MD5SUM: b3a89ab239caf1e10bac7d60277ad995 SHA1SUM: 590aabc3358c45ca7ee3702d50995ce86ac43bf8 SHA256SUM: 5a08550644574ef69f63cbedcaddc3d571eb324f31c1616526ae41ce310ec7c7
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值