使用 boto3 从 EKS 内部访问 S3

Accessing S3 from inside EKS using boto3

我在 EKS(弹性 Kubernetes 服务)上部署了一个 Python 应用程序。此应用程序使用适用于 Python (boto3) 的 AWS 开发工具包将大型文件保存在 S3 存储桶中。 EKS集群和S3 bucket都在同一个region

我的问题是,默认情况下如何处理这两个服务(EKS 和 S3)之间的通信? 这两种服务是直接通过 Amazon 网络进行内部通信,还是通过 Internet 进行外部通信?

如果他们通过互联网通信,是否有关于如何在两个服务之间建立直接内部连接的分步指南?

您可以为您的 EKS 节点 IAM 角色添加 S3 访问权限,this link 向您展示了如何为 EKS 节点 IAM 角色添加 ECR 注册表访问权限,但对于 S3 是一样的。

另一种方法是让环境变量在您的容器中可用,请参阅 this link,但我推荐第一种方法。

how is communication between the two services (EKS and S3) handled by default?

默认情况下,您的 EKS 的网络拓扑提供通往 public AWS S3 endpoints.

的路由

Do both services communicate directly and internally through the Amazon network, or do they communicate externally via the Internet?

您的集群需要具有对上述 public AWS S3 端点的网络访问权限。例如,public 子网中的工作节点 运行 或在私有子网中使用 NAT 网关。

...is there a step by step guide on how to establish a direct internal connection between both services?

您在运行 EKS 的 VPC 中为 S3 创建 VPC 端点,以确保与 S3 的网络通信保持在 AWS 网络内。 S3 的 VPC 端点支持 interface and gateway type. Try this article 要了解 S3 端点的基础知识,您可以使用相同的方法在运行 EKS 的 VPC 中创建端点。然后,从您的 pods 向 S3 发出的请求将使用端点连接到 AWS 网络中的 S3。