Azure AKS - 如何在来自不同可用性区域的节点上的 pods 运行 的公共磁盘上安装卷?

Azure AKS - how to mount a volume on a common disk for pods running on nodes from different availability zones?

我是 运行 一个 AKS 集群,位于不同可用性区域的 3 个节点上(用于 HA)。每个集群上有一个 API 运行 和 pods。

计划将 FileBeat 添加为 DaemonSet(每个节点上一个 pod),Logstash 从每个 FileBeat 实例收集日志。我选择了 DaemonSet 而不是 SidecarProxy 模式以在节点上消耗更少的资源。

为了 FileBeat 能够从 API pods 读取日志,我想在托管的 Azure 磁盘上安装一个卷,API 可以在其中写入日志FileBeat 可以从中读取文件。

Azure Disk当然只驻留在一个区域。所以问题是如果节点与磁盘不在同一个 AZ 中,则无法附加卷:

AttachVolume.Attach failed for volume "logging-persistent-volume" : Retriable: false, RetryAfter: 0s, HTTPStatusCode: 400, RawError: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 400, RawError: { "error": { "code": "BadRequest", "message": "Disk /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/<resource group>/providers/Microsoft.Compute/disks/<disk name> cannot be attached to the VM because it is not in zone '3'." } }

我对 Kubernetes 和 Azure 还很陌生。那么,有没有办法在这种环境下为所有 API pods 共享一个卷?

感谢任何帮助! 谢谢!

无法(至少我知道)将一个 AZ 中的磁盘挂载到另一个 AZ 中的 VM,这也是错误消息所指示的。

此外,Azure Disks are mounted as ReadWriteOnce它一次只能用于一个 pod

Since Azure Disks are mounted as ReadWriteOnce, they're only available to a single pod. For storage volumes that can be accessed by multiple pods simultaneously, use Azure Files.

为了让多个 pods 跨多个区域共享同一个卷,您需要 select 另一个存储提供商。

如果 Azure 文件满足您的性能要求等,它是一个选项。在 Storage options for applications in Azure Kubernetes Service (AKS)

中查看更多信息

另一种方法

由于您采用的是 deamonset 方法,其中 Filebeat 运行 在每个节点上一次,您可以将主机文件夹 /var/lib/docker/containers 装载到文件 beat 容器中并从那里转发日志。

虽然这需要您的应用程序登录到 STDOUTSTDERR,因为这些日志最终位于 /var/lib/docker/containers 下。它也是您在 运行 kubectl logsdocker logs 时看到的那些日志。如果您的应用程序当前登录到文件系统,您将必须重新配置它们以登录到 STDOUT/STDERR,或者将日志文件符号链接到 /dev/stdout(或 /proc/1/fd ,请看这个例子:)

这样每个 filebeat pod 都负责从它 运行 所在的节点转发日志。

Run filebeat on Kubernetes guide

中描述了这种方法

回答你的问题:

您可以在其间添加一个存储解决方案来管理 Azure 磁盘,然后使用该存储解决方案创建您的卷。例如 Ceph,您可以使用 rook operator 进行设置。

解决您的问题:

如果您让 API 记录到标准输出,kubernetes 会将这些日志文件写入磁盘的特定位置。然后 Filebeat 可以从每个节点上的这个位置读取并将您的日志发送到您想要的任何位置。这是在 kubernetes 环境中用于日志记录的标准做法,除非您有特定需要将这些日志写入卷,否则我不建议这样做。

根据 filebeat docs:

You deploy Filebeat as a DaemonSet to ensure there’s a running instance on each node of the cluster.

The Docker logs host folder (/var/lib/docker/containers) is mounted on the Filebeat container. Filebeat starts an input for the files and begins harvesting them as soon as they appear in the folder.