GithubHelp home page GithubHelp logo

vagrant-ubuntu-k8s-cluster's Introduction

项目说明

本项目演示如何使用 Vagrant+VirtualBox 搭建 Kubernetes 集群,并针对国内的网络环境做了优化。

使用方法

准备工作

在使用本项目之前,需先在当前操作系统中安装以下软件:

搭建集群

请打开 Powershell/Bash 等命令行终端环境并执行以下命令:

git clone https://github.com/owlman/vagrant-ubuntu-k8s-cluster.git
cd vagrant-ubuntu-k8s-cluster
vagrant up

以上命令会自动构建出以下三台虚拟的服务器主机:

主机名 IP地址 内存 处理器数量 操作系统
k8s-master 192.168.100.21 2G 2 Ubuntu 20.04
k8s-worker1 192.168.100.22 2G 2 Ubuntu 20.04
k8s-worker2 192.168.100.23 2G 2 Ubuntu 20.04

根据在vagrantfile中的定义,Vagrant 在构建上述虚拟机的同时还会自动执行scripts目录中的脚本,这些脚本将会自动为虚拟机配置、安装 Docker 与 Kubernetes 环境,以下是其安装软件的版本信息:

Docker-CE:  20.10.17
Kubernetes: 1.21.1
    kube-apiserver: v1.21.1
    kube-proxy: v1.21.1
    kube-controller-manager: v1.21.1
    kube-scheduler: v1.21.1
    pause: 3.4.1
    coredns: v1.8.0
    etcd: 3.4.13-0  

基本操作

  1. 启动、重启与关闭虚拟机:

    # 启动所有虚拟机
    vagrant up
    # 启动指定的虚拟机
    vagrant up <主机名>
    # 重启所有虚拟机
    vagrant reload
    # 重启指定的虚拟机
    vagrant reload <主机名>
    # 关闭所有虚拟机
    vagrant halt
    # 关闭指定的虚拟机
    vagrant halt <主机名>
  2. 使用 SSH 的方式进入指定虚拟机:

    vagrant ssh  <主机名>
  3. 销毁虚拟机

    # 销毁所有虚拟机
    vagrant destroy -f
    # 销毁指定的虚拟机
    vagrant destroy <主机名> -f

使用 Kubectl

如果想使用 kubectl 命令行工具在本地远程操作这个虚拟的 Kubernetes 集群,可打开 Powershell/Bash 等命令行终端环境并进入到vagrant-ubuntu-k8s-cluster目录中,然后执行以下命令:

mkdir ~/.kube
cp ./configs/config  ~/.kube/

如果一切顺利,当我们在本地的命令行终端中输入kubectl get nodes命令时,就能看到如下输出了:

NAME          STATUS     ROLES                  AGE   VERSION
k8s-master    Ready      control-plane,master   22h   v1.21.1
k8s-worker1   Ready      <none>                 20h   v1.21.1
k8s-worker2   Ready      <none>                 21h   v1.21.1

vagrant-ubuntu-k8s-cluster's People

Contributors

owlman avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.