gpt4 book ai didi

azure - 从 Windows docker 容器访问 Azure 实例元数据服务 (169.254.169.254)

转载 作者:行者123 更新时间:2023-12-02 23:25:39 27 4
gpt4 key购买 nike

Azure VM 可以查询Instance Metadata Service位于 169.254.159.254 获取数据。但是,这在虚拟机上运行的 Windows 容器中不起作用。

Windows 容器如何查询只能从主机虚拟机访问的实例元数据服务?

例如,当使用如下 Windows 容器时:docker run -it --rm mcr.microsoft.com/windows/servercore:ltsc2019

并查询如下数据: Invoke-RestMethod -Headers @{"Metadata"="true"} -Method GET -Uri http://169.254.169.254/metadata/instance?api-version=2019 -06-01

结果如下:

At line:1 char:1
+ Invoke-RestMethod -Headers @{"Metadata"="true"} -Method GET -Uri http ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExc
eption
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

最佳答案

恐怕我们无法从 Azure VM 上的 Windows 容器访问 Azure 实例元数据服务端点,因为 Docker 上的容器与 VM 网络隔离在不同的网络中,并且 IMDS 只能从VM 级别内的不可路由 IP 地址。

Azure's IMDS is a REST Endpoint that is available at a well-knownnon-routable IP address (169.254.169.254), it can be accessed onlyfrom within the VM. Communication between the VM and IMDS never leavesthe Host.

The Instance Metadata Service endpoint is accessible only from withinthe running virtual machine instance on a non-routable IP address. Inaddition, any request with an X-Forwarded-For header is rejected by theservice.

下图描述了与现有虚拟机集成的容器。获取更多详情here .

enter image description here

当您在 Azure VM 上生成容器化应用程序时,容器通过默认的 docker 虚拟化 nat NIC 与容器外部进行通信。例如,在 Azure VM 上,有一个额外的 IP 地址 172.22.48.1用于与网络中的 guest 操作系统连接的 docker 实例 172.18.4.0/24 .

enter image description here

编辑

来自Known issues and FAQ ,

Metadata calls must be made from the primary IP address assigned tothe primary network card of the VM.

当您从 Azure VM 上的容器调用元数据时,它实际上使用 NAT 网卡(它具有与主网卡不同的 MAC 地址)而不是主网卡。

关于azure - 从 Windows docker 容器访问 Azure 实例元数据服务 (169.254.169.254),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63274486/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com