管理镜像
使用 Alauda Container Platform 时,你可以与镜像进行交互,具体取决于镜像的 registry 所在位置、这些 registry 所需的认证要求,以及你希望构建和部署的行为方式。
镜像拉取策略
pod 中的每个容器都有一个容器镜像。在你创建镜像并将其推送到 registry 后,就可以在 pod 中引用它。
镜像拉取策略概述
当 Alauda Container Platform 创建容器时,它会使用容器 imagePullPolicy 来确定在启动容器之前是否应拉取镜像。imagePullPolicy 有三种可能的值:
imagePullPolicy 的取值表:
如果未指定容器的 imagePullPolicy 参数,Alauda Container Platform 会根据镜像标签进行设置:
- 如果标签为 latest,Alauda Container Platform 会将 imagePullPolicy 默认为 Always。
- 否则,Alauda Container Platform 会将 imagePullPolicy 默认为 IfNotPresent。
使用 image pull secret
如果你使用的是 Alauda Container Platform 镜像 registry,那么你的 pod ServiceAccount 应该已经具有正确的权限,无需执行额外操作。
但是,在其他场景中,例如跨 Alauda Container Platform 项目引用镜像,或从受保护的 registry 引用镜像时,则需要额外的配置步骤。
允许 pod 引用来自其他受保护 registry 的镜像
要从其他私有或受保护的 registry 拉取受保护的容器,你必须使用容器客户端凭据(例如 Podman)创建一个 pull secret,并将其添加到你的 ServiceAccount 中。
容器客户端使用配置文件来存储登录受保护或不受保护 registry 的认证详情:
如果你之前登录过受保护或不受保护的 registry,这些文件会保存你的认证信息。
创建 pull secret
你可以获取 image pull secret,以便从私有容器镜像 registry 或 repository 拉取镜像。你可以参考 从私有 Registry 拉取镜像。
在工作负载中使用 pull secret
你可以通过以下任一方式使用 pull secret,允许工作负载从私有 registry 拉取镜像:
- 将 secret 关联到
ServiceAccount,这会自动将该 secret 应用于使用该 ServiceAccount 的所有 pod。 - 在 pod 规范中定义
imagePullSecrets,这对于 GitOps 或 ArgoCD 这类环境很有用。
你可以通过将 secret 添加到你的 ServiceAccount 来为 pod 拉取镜像。请注意,ServiceAccount 的名称应与 pod 使用的 ServiceAccount 名称匹配。
示例输出:
除了将 secret 关联到 ServiceAccount 之外,你也可以在 pod 或工作负载定义中直接引用它。这对于 ArgoCD 等 GitOps 工作流很有用。例如:
示例 pod 规范:
示例 ArgoCD 工作流: