树莓派kubernetes_在树莓派上自动部署ha kubernetes

树莓派kubernetes

Learn how to create a HA Kubernetes cluster on Raspberry Pis.

了解如何在Raspberry Pis上创建HA Kubernetes集群。

This guide demonstrates how to implement enterprise-grade security, observability, and overall cluster management in a learning environment. All the information in this guide is based on the Raspbernetes project.

本指南演示了如何在学习环境中实现企业级安全性,可观察性和整体群集管理。 本指南中的所有信息均基于Raspbernetes项目。

The Raspbernetes project started with a goal to automate the setup and management of a Kubernetes cluster on Raspberry Pis. It aims to be completely declarative and idempotent.

Raspbernetes项目的目标是在Raspberry Pis上自动设置和管理Kubernetes集群。 它旨在完全声明和幂等。

Check out more about the project → https://github.com/raspbernetes

查看有关该项目的更多信息→ https://github.com/raspbernetes

先决条件 (Prerequisites)

Hardware — We recommend to have at least 4 raspberry pis. This guide used 3 Pis as master nodes and an additional Pi as the worker node. You can addmore Pis to create additional master or worker nodes.

硬件—我们建议至少有4个覆盆子pi。 本指南使用3个Pi作为主节点,并使用另一个Pi作为工作节点。 您可以添加更多的Pi,以创建其他主节点或工作节点。

Software — You will need the following CLI tools to be able to follow the steps in this guide:

软件-您将需要以下CLI工具才能执行本指南中的步骤:

Finally, you will need to clone this repository: https://github.com/raspbernetes/k8s-cluster-installation

最后,您将需要克隆此存储库: https : //github.com/raspbernetes/k8s-cluster-installation

闪存SD卡 (Flash SD Cards)

To configure each node with a unique IP and hostname we use cloud-init. This is a method for cross-platform cloud instance initialization which also works for bare-metal installations.

要为每个节点配置唯一的IP和主机名,我们使用cloud-init。 这是用于跨平台云实例初始化的方法,该方法也适用于裸机安装。

The operating system used in this guide will be Ubuntu 20.04, run the following command to download the image:

本指南中使用的操作系统为Ubuntu 20.04,运行以下命令下载映像:

# Download the Ubuntu 20.04 Focal image for Raspberry Pis
curl -L "http://cdimage.ubuntu.com/releases/focal/release/ubuntu- 20.04.1-preinstalled-server-arm64+raspi.img.xz" -o ~/Downloads/ubuntu-20.04.1-preinstalled-server-arm64+raspi.img.xz# Extract the downloaded files
unxz -T 0 ~/Downloads/ubuntu-20.04.1-preinstalled-server-arm64+raspi.img.xz

The following steps will configure networking for the nodes automatically using cloud-init on boot( steps 4 to 6 must be repeated for each node):

以下步骤将在启动时使用cloud-init为节点自动配置节点的联网(必须对每个节点重复步骤4至6):

  1. Open the cloud-config file.

    打开cloud-config文件。

  2. Update the gateway4 value to match the IP of your router. (If unsure you can find this IP using this guide)

    更新gateway4值以匹配路由器的IP。 (如果不确定,可以使用本指南找到此IP)

  3. Update the ssh_authorized_keys value with your own keys, enabling secure SSH access to each node without further configuration. (Highly recommended and there are a lot of guides that will explain how to setup SSH keys if you haven’t already)

    使用您自己的密钥更新ssh_authorized_keys值,无需进一步配置即可启用对每个节点的安全SSH访问。 (强烈建议您,并且有很多指南将介绍如何设置SSH密钥(如果尚未安装的话))

  4. Update the hostname value to be unique per node.

    hostname值更新为每个节点唯一。

  5. Update the addresses value to be a unique IP per node.

    addresses值更新为每个节点的唯一IP。

  6. Flash the OS image and cloud-init configuration onto the Raspberry Pi using the following command:

    使用以下命令将OS映像和cloud-init配置刷新到Raspberry Pi上:
flash \
--userdata setup/cloud-config.yml \
~/Downloads/ubuntu-20.04.1-preinstalled-server-arm64+raspi.img

集群配置 (Cluster Configuration)

基本设定 (Basic Setup)

Note: This will initialize your cluster with default CRI & CNI configuration, for more advanced configuration, check the “Advanced Setup” options.

注意:这将使用默认的CRI和CNI配置初始化您的群集,要进行更高级的配置,请选中“ 高级设置 ”选项。

Now we have all our Raspberry Pi nodes running and are configured with a unique hostname, IP, we now need to declare these values in the Ansible inventory file.

现在,我们所有的Raspberry Pi节点都在运行,并配置有唯一的主机名IP,现在我们需要在Ansible 库存文件中声明这些值。

See below for an example of how I configured my 3 master nodes and 1 worker node.

有关如何配置3个主节点和1个工作节点的示例,请参见下文。

[masters]
k8s-master-01 hostname=k8s-master-01 ansible_host=192.168.1.121 ansible_user=pi
k8s-master-02 hostname=k8s-master-02 ansible_host=192.168.1.122 ansible_user=pi
k8s-master-03 hostname=k8s-master-03 ansible_host=192.168.1.123 ansible_user=pi[workers]
k8s-worker-01 hostname=k8s-worker-01 ansible_host=192.168.1.131 ansible_user=pi

When the inventory has been configured with all hosts, there is one last thing we must configure. We need to assign a VIP (“Virtual IP”) that will be used to load-balance across the HA master nodes.

在为清单配置了所有主机后,我们必须配置的最后一件事。 我们需要分配一个VIP(“虚拟IP”),该IP将用于在HA主节点之间进行负载平衡。

Open masters.yml and configure the keepalived_vip value to an unassigned IP. For my configuration I use 192.168.1.200 .

打开masters.yml并将keepalived_vip值配置为未分配的IP。 对于我的配置,我使用192.168.1.200

Run the following command to verify SSH connectivity.

运行以下命令以验证SSH连接。

env ANSIBLE_CONFIG=ansible/ansible.cfg ansible all -m ping

A successful response should look something like the following:

成功的响应应类似于以下内容:

k8s-master-01 | SUCCESS => {
...
"ping": "pong"
...
}

Note: If your output returns success for each ping then you can continue, otherwise there may be some misconfiguration of either the inventory file or network connectivity issues.

注意:如果您的输出在每次ping操作中都返回成功,那么您可以继续,否则清单文件或网络连接问题可能配置有误。

Now we’ve tested network connectivity we can run the automation scripts that will take care of deploying Kubernetes using the following:

现在我们已经测试了网络连接,我们可以运行自动化脚本,该脚本将使用以下方法来部署Kubernetes:

env ANSIBLE_CONFIG=ansible/ansible.cfg ansible-playbook ansible/playbooks/all.yml

Once successfully completed you can use kubectl to interact with your Kubernetes cluster:

成功完成后,您可以使用kubectl与Kubernetes集群进行交互:

kubectl get nodes --kubeconfig ansible/playbooks/output/k8s-config.yaml

The expected output should look something like the following:

预期的输出应类似于以下内容:

NAME            STATUS     ROLES    AGE     VERSION
k8s-master-01 Ready master 4m45s v1.18.2
k8s-master-02 Ready master 70s v1.18.2
k8s-master-03 Ready master 79s v1.18.2
k8s-worker-01 Ready <none> 16s v1.18.2

Congratulations! You now have a running Kubernetes cluster running on Raspberry Pis.

恭喜你 ! 现在,您已经在树莓派上运行了一个正在运行的Kubernetes集群。

进阶设定 (Advanced Setup)

This section is an appendage to the “Basic Setup” however, will explore more of the advanced configuration that is available.

本节是“基本设置”的附录,但是,将探讨更多可用的高级配置。

The configuration options can be found in the group_vars folder where you have the files all.yml, masters.yml, and workers.yml. These files contain the configurable variables of each role.

配置选项可在发现group_vars文件夹,你必须将文件all.ymlmasters.ymlworkers.yml 。 这些文件包含每个角色的可配置变量。

清理 (Cleanup)

Tear down the cluster and remove everything using the following command:

拆除群集并使用以下命令删除所有内容:

env ANSIBLE_CONFIG=ansible/ansible.cfg ansible-playbook ansible/playbooks/nuke.yml

摘要 (Summary)

You’ve successfully created a Kubernetes cluster with a highly available topology on Raspberry Pis.

您已经成功创建了一个Raspberry Pis上具有高可用性拓扑的Kubernetes集群。

You have learned how to configure networking, flash your operating system, set up some basic cluster configuration, and now have the Kubernetes cluster to continue your learning.

您已经了解了如何配置网络,刷新操作系统,设置了一些基本的集群配置,并且现在有了Kubernetes集群来继续学习。

If you like our open source project, feel free to contribute, especially if you have use cases that aren’t available currently! There is, even more, to discover in the Raspbernetes Github org here.

如果您喜欢我们的开源项目,请随时贡献力量,特别是如果您有当前尚不可用的用例! 还有就是,甚至更多,在Raspbernetes Github的组织发现在这里

Did you find this useful? Drop a comment or leave us a like!

你觉得这有用吗? 发表评论或给我们一个赞!

翻译自: https://itnext.io/automated-ha-kubernetes-deployment-on-raspberry-pis-408f38cd836c

树莓派kubernetes

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值