Kubernetes on ARM,基于HypriotOS

简介: Kubernetes是一个基于Docker的集群管理系统,现在也可以在ARM集群上运行。这里介绍基于HypriotOS操作系统的Kubernetes安装和使用过程(基于树莓派)。也可以在多种基于ARMbian操作系统 (https://www.armbian.com/)的ARM板上运行(参见 https://www.armbian.com/download/)。

Kubernetes是一个基于Docker的集群管理系统,现在也可以在ARM集群上运行。这 里介绍基于HypriotOS操作系统的Kubernetes安装和使用过程(基于树莓派)。也可以在多种基于ARMbian操作系统 (https://www.armbian.com/)的ARM板上运行(参见 https://www.armbian.com/download/)。

1、烧录操作系统固件 HypriotOS 到 SD cards

硬件上, 至少两个Raspberry Pis 能够相互连接,并且连接到Internet。

首先, 我们需要一个操作系统,下载和烧写 HypriotOS。最快速的方式是使用 flash tool,如下:

flash --hostname node01 https://github.com/hypriot/image-builder-rpi/releases/download/v1.4.0/hypriotos-rpi-v1.4.0.img.zip

对所有的树莓派执行上面的操作,然后启动。

然后, SSH进入Raspberry Pis:

ssh pirate@node01.local

首次启动密码为 hypriot

2、安装 Kubernetes

需要root 权限,以root账户进入系统,如下:

sudo su -

为了安装Kubernetes和依赖软件, 需要执行一些命令。首先, 安装kubernetes APT 仓库的key,添加软件安装源:

$ curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | apt-key add - $ echo "deb http://apt.kubernetes.io/ kubernetes-xenial main" > /etc/apt/sources.list.d/kubernetes.list 

… 安装 kubeadm 到所有节点:

$ apt-get update && apt-get install -y kubeadm

上面的操作结束后, 初始化 Kubernetes ,在master node 使用:

$ kubeadm init --pod-network-cidr 10.244.0.0/16 

这里的命令,添加 --pod-network-cidr 很重要!因为我们将使用 flannel 虚拟网络,关于 flannel 的注意事项如下,使用之前务必了解:

Some notes about flannel: We picked flannel here because that’s the only available solution for ARM at the moment (this is subject to change in the future though).

flannel can use and is using in this example the Kubernetes API to store metadata about the Pod CIDR allocations, and therefore we need to tell Kubernetes first which subnet we want to use. The subnet we chose here is somehow fixed, because the flannel configuration file that we’ll use later in this guide predefines the equivalent subnet. Of course, you can adapt both.

如果通过 WIFI连接而非有线, 添加 --apiserver-advertise-address=<wifi-ip-address> 作为参数来执行 kubeadm init ,以通过WiFi公布Kubernetes’ API。 还有一些其他的 kubeadm init参数,你可以去尝试。

当 Kubernetes 初始化后, 终端窗口显示如下:

init

为了启动集群, 需要运行 (as a regular user):

$ sudo cp /etc/kubernetes/admin.conf $HOME/ $ sudo chown $(id -u):$(id -g) $HOME/admin.conf $ export KUBECONFIG=$HOME/admin.conf 

下一步, 如上面的输出所说明, 通过 kubeadm join 命令添加集群的节点。如(在节点机上执行):

$ kubeadm join --token=bb14ca.e8bbbedf40c58788 192.168.0.34 

几秒钟后,你将在 master node上看得见所有的节点,通过执行下面的命令:

$ kubectl get nodes 

终端显示的信息如下:

k8S

最后, 我们需要设置flannel v0.7.1 ,作为Pod network driver. 不要使用 v0.8.0 ,因为有一个已知的 bug ,将会引起 CrashLoopBackOff 错误。在 master node 执行:

$ curl -sSL https://rawgit.com/coreos/flannel/v0.7.1/Documentation/kube-flannel-rbac.yml | kubectl create -f - $ curl -sSL https://rawgit.com/coreos/flannel/v0.7.1/Documentation/kube-flannel.yml | sed "s/amd64/arm/g" | kubectl create -f - 

终端显示的信息如下:

k8S

然后等待 flannel 和其他 cluster-internal Pods 的运行 Running ,查看运行情况:

$ kubectl get po --all-namespaces 

很好,看起来都在 Running:

show-namespaces

现在Kubernetes已经设置成功! 下一步, 我们在集群上来实际启动一个服务。

3、测试安装是否成功

启动一个简单的服务,验证下集群是否运行正常,如下:

$ kubectl run hypriot --image=hypriot/rpi-busybox-httpd --replicas=3 --port=80 

该命令启动名为 hypriot的服务,镜像来自于 hypriot/rpi-busybox-httpd ,端口为 80。该服务的副本设为3,将启动3个容器实例。

下一步,暴露创建的部署后的Pods为稳定的name 和 IP的服务:

$ kubectl expose deployment hypriot --port 80 

好了! 现在检查想要的容器是否启动和运行:

$ kubectl get endpoints hypriot 

将看到三个endpoints (= containers) like this:

show-endpoints

使用curl 检查服务service是否已经起来:

curl-service

服务响应返回的HTML如上,很好!下一步,我们将从集群外部来访问这个服务。

4、从外面访问服务

我们将使用 Ingress Controller示范例程,来管理外部的输入请求,实现服务的访问。以及,使用 Traefik 来进行负载均衡。如果希望俩节 Ingress 和 Traefik的更多内容,建议阅读下面的内容:

In contrast to Docker Swarm, Kubernetes itself does not provide an option to define a specific port that you can use to access a service. According to Lucas this is an important design decision; routing of incoming requests should be handled by a third party, such as a load balancer or a webserver, but not by the core product. The core Kubernetes should be lean and extensible, and encourage others to build tools on top of it for their specific needs.

Regarding load balancers in front of a cluster, there is the Ingress API object and some sample Ingress Controllers. Ingress is a built-in way of exposing Services to the outside world via an Ingress Controller that anyone can build. An Ingress rule defines how traffic should flow from the node the Ingress controller runs on to services inside of the cluster.

首先,部署traefik作为负载均衡器:

$ kubectl apply -f https://raw.githubusercontent.com/hypriot/rpi-traefik/master/traefik-k8s-example.yaml 

Label the node you want to be the load balancer. Then the Traefik Ingress Controller will land on the node you specified. Run:

$ kubectl label node <load balancer-node> nginx-controller=traefik 

Lastly, create an Ingress object that makes Traefik load balance traffic on port 80 to the hypriot service:

$ cat > hypriot-ingress.yaml <<EOF
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
 name: hypriot
spec:
 rules:
 - http:
 paths:
 - path: /
 backend:
 serviceName: hypriot
 servicePort: 80
EOF
$ kubectl apply -f hypriot-ingress.yaml 

Visit the loadbalancing node’s IP address in your browser and you should see a nice web page:

curl-service

If you don’t see a website there yet, run:

$ kubectl get pods 

… and make sure all hypriot Pods are in the Running state.

Wait until you see that all Pods are running, and a nice Hypriot website should appear!

5、重置 cluster

If you wanna reset the whole cluster to the state after a fresh install, just run this on each node:

$ kubeadm reset 

In addition, it is recommended to delete some additional files as it is mentioned here.

6、可选: 部署Kubernetes信息面板

The dashboard is a wonderful interface to visualize the state of the cluster. Start it with:

$ kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/master/src/deploy/recommended/kubernetes-dashboard-arm.yaml

Edit the kubernetes-dashboard service to use type: ClusterIP to type: NodePort, see Accessing Kubernetes Dashboard for more details.

$ kubectl -n kube-system edit service kubernetes-dashboard 

The following command provides the port that the dashboard is exposed at on every node with the NodePort function of Services, which is another way to expose your Services to the outside of your cluster:

$ kubectl -n kube-system get service kubernetes-dashboard -o template --template="{{ (index .spec.ports 0).nodePort }}" | xargs echo 

Then you can checkout the dashboard on any node’s IP address on that port! Make sure to use https when accessing the dashboard, for example if running on port 31657 access it at https://node:31657.

Newer versions of the Kubernetes Dashboard require either a Kubeconfig or Token to view information on the dashboard. Bearer tokens are recommended to setup proper permissions for a user, but to test the replicaset-controller-token Token may be used to test.

kubectl -n kube-system describe secret `kubectl -n kube-system get secret | grep replicaset-controller-token | awk '{print $1}'` | grep token: | awk '{print $2}' 

7、继续 follow-up?

It was our goal to show that Kubernetes indeed works well on ARM (and ARM 64-bit!). For more examples including the AMD64 platform, check out the official kubeadm documentation.

We might follow-up this blog post with a more in-depth post about the current and planned state of Kubernetes officially on ARM and more, so stay tuned and tell Lucas if that’s something you’re interested in reading.

As always, use the comments below to give us feedback and share this post on Twitter, Google or Facebook.

本文转自开源中国-Kubernetes on ARM,基于HypriotOS

相关实践学习
深入解析Docker容器化技术
Docker是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的Linux机器上,也可以实现虚拟化,容器是完全使用沙箱机制,相互之间不会有任何接口。Docker是世界领先的软件容器平台。开发人员利用Docker可以消除协作编码时“在我的机器上可正常工作”的问题。运维人员利用Docker可以在隔离容器中并行运行和管理应用,获得更好的计算密度。企业利用Docker可以构建敏捷的软件交付管道,以更快的速度、更高的安全性和可靠的信誉为Linux和Windows Server应用发布新功能。 在本套课程中,我们将全面的讲解Docker技术栈,从环境安装到容器、镜像操作以及生产环境如何部署开发的微服务应用。本课程由黑马程序员提供。 &nbsp; &nbsp; 相关的阿里云产品:容器服务 ACK 容器服务 Kubernetes 版(简称 ACK)提供高性能可伸缩的容器应用管理能力,支持企业级容器化应用的全生命周期管理。整合阿里云虚拟化、存储、网络和安全能力,打造云端最佳容器化应用运行环境。 了解产品详情: https://www.aliyun.com/product/kubernetes
相关文章
|
弹性计算 Kubernetes Ubuntu
ack-kubernetes-elastic-workload,ECI这个能不能重新打个包支持下arm
ack-kubernetes-elastic-workload,ECI这个能不能重新打个包支持下arm
159 2
|
4月前
|
人工智能 算法 调度
阿里云ACK托管集群Pro版共享GPU调度操作指南
本文介绍在阿里云ACK托管集群Pro版中,如何通过共享GPU调度实现显存与算力的精细化分配,涵盖前提条件、使用限制、节点池配置及任务部署全流程,提升GPU资源利用率,适用于AI训练与推理场景。
404 1
|
4月前
|
弹性计算 监控 调度
ACK One 注册集群云端节点池升级:IDC 集群一键接入云端 GPU 算力,接入效率提升 80%
ACK One注册集群节点池实现“一键接入”,免去手动编写脚本与GPU驱动安装,支持自动扩缩容与多场景调度,大幅提升K8s集群管理效率。
290 89
|
9月前
|
资源调度 Kubernetes 调度
从单集群到多集群的快速无损转型:ACK One 多集群应用分发
ACK One 的多集群应用分发,可以最小成本地结合您已有的单集群 CD 系统,无需对原先应用资源 YAML 进行修改,即可快速构建成多集群的 CD 系统,并同时获得强大的多集群资源调度和分发的能力。
412 9
|
9月前
|
资源调度 Kubernetes 调度
从单集群到多集群的快速无损转型:ACK One 多集群应用分发
本文介绍如何利用阿里云的分布式云容器平台ACK One的多集群应用分发功能,结合云效CD能力,快速将单集群CD系统升级为多集群CD系统。通过增加分发策略(PropagationPolicy)和差异化策略(OverridePolicy),并修改单集群kubeconfig为舰队kubeconfig,可实现无损改造。该方案具备多地域多集群智能资源调度、重调度及故障迁移等能力,帮助用户提升业务效率与可靠性。
|
11月前
|
存储 Kubernetes 监控
K8s集群实战:使用kubeadm和kuboard部署Kubernetes集群
总之,使用kubeadm和kuboard部署K8s集群就像回归童年一样,简单又有趣。不要忘记,技术是为人服务的,用K8s集群操控云端资源,我们不过是想在复杂的世界找寻简单。尽管部署过程可能遇到困难,但朝着简化复杂的目标,我们就能找到意义和乐趣。希望你也能利用这些工具,找到你的乐趣,满足你的需求。
996 33
|
11月前
|
Kubernetes 开发者 Docker
集群部署:使用Rancher部署Kubernetes集群。
以上就是使用 Rancher 部署 Kubernetes 集群的流程。使用 Rancher 和 Kubernetes,开发者可以受益于灵活性和可扩展性,允许他们在多种环境中运行多种应用,同时利用自动化工具使工作负载更加高效。
625 19
|
11月前
|
人工智能 分布式计算 调度
打破资源边界、告别资源浪费:ACK One 多集群Spark和AI作业调度
ACK One多集群Spark作业调度,可以帮助您在不影响集群中正在运行的在线业务的前提下,打破资源边界,根据各集群实际剩余资源来进行调度,最大化您多集群中闲置资源的利用率。
|
Prometheus Kubernetes 监控
OpenAI故障复盘 - 阿里云容器服务与可观测产品如何保障大规模K8s集群稳定性
聚焦近日OpenAI的大规模K8s集群故障,介绍阿里云容器服务与可观测团队在大规模K8s场景下我们的建设与沉淀。以及分享对类似故障问题的应对方案:包括在K8s和Prometheus的高可用架构设计方面、事前事后的稳定性保障体系方面。
|
11月前
|
Prometheus Kubernetes 监控
OpenAI故障复盘丨如何保障大规模K8s集群稳定性
OpenAI故障复盘丨如何保障大规模K8s集群稳定性
443 0
OpenAI故障复盘丨如何保障大规模K8s集群稳定性

热门文章

最新文章