在Mac上具有vagrant和virtualbox的kubernetes生产集群

For development purposes, it would be great to have a Kubernetes Production Cluster locally, and with this article, I am going through the basic setup in order to start using a good one.

出于开发目的,最好在本地拥有一个Kubernetes生产集群,在本文中,我将进行基本设置,以便开始使用一个好的集群。

Kubespray进行救援 (Kubespray to the rescue)

There are few open-source solutions to achieve the task of deploying Production-Ready Kubernetes clusters, but I selected Kubespray.

很少有开源解决方案可以完成部署生产就绪型Kubernetes集群的任务,但是我选择了Kubespray。

It comes with Ansible playbooks (deploy, upgrade, utils and extras) and with plenty of tests.

它随附Ansible剧本(部署,升级,实用程序和其他功能)以及大量测试。

What is supposed to be already installed:

应该已经安装了什么:

  • Vagrant

    流浪汉
  • Virtualbox

    虚拟箱
  • Python + Pip

    Python +点

Let’s clone the official repo:

让我们克隆官方仓库:

git clone https://github.com/kubernetes-sigs/kubespray

Afterward, moving into the cloned repo, we can start the installation of the tools required:

之后,进入克隆的仓库,我们可以开始安装所需的工具:

cd kubespray && pip3 install -r requirements.txt# ORcd kubespray && pip install -r requirements.txt

Once everything has been correctly installed, we can start Vagrant:

正确安装所有组件后,我们可以启动Vagrant:

vagrant up

This command will spawn the VMs, install Kubernetes on them, and configure the networking. When invoked without customizations, it is grabbing a sample configuration that is located in /inventory/sample. Inner YAML files allow customization of whatever is desired for the planned cluster. In addition, the Vagrantfile contains all the necessary specifications for the spawned VMs (so it allows us to configure the network, VM’s image, its properties, etc…).

该命令将生成VM,在其上安装Kubernetes,并配置网络。 在没有自定义的情况下调用时,它将获取/ inventory / sample中的样本配置。 内部YAML文件允许自定义计划群集所需的任何内容。 此外, Vagrantfile包含生成的VM的所有必要规范(因此,它允许我们配置网络,VM的映像,其属性等)。

When the process completes, and the cluster is successfully created, we could use the configuration automatically injected in the artifacts folder.

当该过程完成并且成功创建集群后,我们可以使用自动注入到工件文件夹中的配置。

Let’s move into the .vagrant folder in order to access it:

让我们进入.vagrant文件夹以对其进行访问:

cd .vagrant/provisioners/ansible/inventory/artifacts

There are 3 files:

有3个文件:

admin.conf     kubectl    kubectl.sh

The one we need is the “admin.conf”, which contains the configuration for our newly created local cluster (and set Kubectl to use it).

我们需要的是“ admin.conf ”,其中包含我们新创建的本地集群的配置(并设置Kubectl来使用它)。

export KUBECONFIG=$(pwd)/admin.conf

So let’s check the connection to our cluster:

因此,让我们检查与集群的连接:

$ kubectl cluster-infoKubernetes master is running at https://172.18.8.101:6443To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

Cool, we are connected to the cluster now.

太好了,我们现在已连接到集群。

By default, Virtualbox is using a NAT network type, which is isolating the VMs created, thus we would need to use port forwarding in order to access the desired VM (or VMs) from outside.

默认情况下,Virtualbox使用的是NAT网络类型,它隔离了创建的VM,因此我们将需要使用端口转发才能从外部访问所需的VM。

$ vagrant statusCurrent machine states:k8s-1                     running (virtualbox) # usually master node
k8s-2 running (virtualbox)
k8s-3 running (virtualbox)

And listing Virtualbox instances

并列出Virtualbox实例

$ vboxmanage list vms"kubespray_k8s-1_1599909087609_21866" {30ba6c6e-6a1d-4647-8f67-9f3f8276d660}
"kubespray_k8s-2_1599909125366_77977" {f618bfd4-fe82-4437-8e57-2bce2bb9e2b1}
"kubespray_k8s-3_1599909169592_4503" {86275e53-025f-4021-85a8-2ff23a0099cb}

So, what we would like to do, it’s exposing the k8s-1 machine with the id “30ba6c6e-6a1d-4647–8f67–9f3f8276d660”. With the NAT network, we need to use port-forwarding from the host to the guest and it is possible to do so:

因此,我们要做的是,将ID为“ 30ba6c6e-6a1d-4647–8f67–9f3f8276d660 ”的k8s-1机器公开。 对于NAT网络,我们需要使用从主机到来宾的端口转发,并且可以这样做:

vboxmanage controlvm 30ba6c6e-6a1d-4647–8f67–9f3f8276d660 natpf1 "master-node,tcp,,6443,,6443"

This command is creating a rule for port-forwarding for the k8s-1 master node. “master-node” is an arbitrary name you desire, TCP the protocol, between the two commas we don’t specify any IPs (done twice), and for both host/guest we assign the same port (6443 in this case).

此命令正在为k8s-1主节点创建端口转发规则。 “ master-node”是您想要的任意名称,即TCP协议,在两个逗号之间,我们没有指定任何IP(完成两次),并且为两个主机/来宾分配了相同的端口(在这种情况下为6443)。

Once fired, the command is exposing our cluster through port-forwarding.

一旦触发,该命令将通过端口转发公开我们的集群。

There are lots of things that could be configured with Kubespray such as Network management solution, Ingress controller, number of nodes, etc... I recommend checking the official page at the following link https://kubespray.io/

Kubespray可以配置很多东西,例如网络管理解决方案,Ingress控制器,节点数等。我建议您通过以下链接检查官方页面: https://kubespray.io/

Hope it helped!

希望能有所帮助!

Cheers :)

干杯:)

翻译自: https://itnext.io/kubernetes-production-cluster-with-vagrant-and-virtualbox-on-mac-8718586f179f

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值