17-Containers-Container Environment Variables
concepts/containers/container-environment-variables/
Container Environment Variables 容器环境变量
This page describes the resources available to Containers in the Container environment.
Container environment
The Kubernetes Container 环境为容器提供了几个重要的资源:
- A filesystem, which is a combination of an image and one or more volumes. 文件系统, 存储卷
- Information about the Container itself. 关于容器本身的信息。
- Information about other objects in the cluster. 有关群集中其他对象的信息。
Container information
容器的主机名是运行容器的pod的名称。它可以通过libc中的hostname
命令或gethostname
函数调用获得。
pod名称和命名空间作为环境变量通过 downward API.
POD定义中的用户定义环境变量也可用于容器,Docker映像中静态指定的任何环境变量也是如此。
Cluster information
创建容器时正在运行的所有服务的列表可作为环境变量提供给该容器。这些环境变量与docker链接的语法匹配。
对于映射到名为bar的容器的名为foo的服务,定义了以下变量:
FOO_SERVICE_HOST=<the host the service is running on>
FOO_SERVICE_PORT=<the port the service is running on>
如果启用了DNS加载项,则服务具有专用的IP地址并可通过DNS供容器使用。域名解析服务
What's next
- Learn more about Container lifecycle hooks.
- Get hands-on experience attaching handlers to Container lifecycle events.
本作品采用《CC 协议》,转载必须注明作者和本文链接