第 19 章 使用 RHEL 系统角色管理容器
podman RHEL 系统角色管理 Red Hat Enterprise Linux 系统上的容器。此角色使用 Ansible 配置 Podman,管理容器生命周期,甚至将容器化应用程序部署为 systemd 服务。
19.1. 为 Podman 和其他容器工具配置镜像 registry 管理 复制链接链接已复制到粘贴板!
使用 podman RHEL 系统角色,您可以在多个 RHEL 系统中自动化 Podman 管理,包括 registry 配置。您可以在 Ansible playbook 中定义 registry 配置,而不是手动编辑文件。
podman RHEL 系统角色使用 podman_registries_conf 变量,它接受包含 registry 设置的字典。然后,该角色会创建一个置入文件,例如在 /etc/containers/registries.conf.d/ 中应用您的配置,遵循管理系统配置的最佳实践。
先决条件
- 您已准备好控制节点和受管节点。
- 您以可在受管主机上运行 playbook 的用户身份登录到控制节点。
-
用于连接到受管节点的帐户具有这些节点的
sudo权限。
流程
创建一个包含以下内容的 playbook 文件,如
~/playbook.yml:--- - name: Configure Podman registries with RHEL system roles hosts: managed-node-01.example.com vars: podman_registries_conf: unqualified-search-registries: - "registry.access.redhat.com" - "docker.io" - "my-company-registry.com" registry: - location: "my-company-registry.com" - location: "my-local-registry:5000" insecure: true tasks: - name: Include the podman system role ansible.builtin.include_role: name: redhat.rhel_system_roles.podman示例 playbook 中指定的设置包括如下:
-
Unqualified-search-registries:在使用简短镜像名称时(例如podman pull <my-image> )时,扩展 registry Podman 搜索的列表。Podman 在默认 registry 后搜索 my-company-registry.com 中的镜像。 -
[registry]: 定义给定 registry 的特定属性。例如,您可以通过将insecure=true设置为运行在 my-local-registry:5000 的本地 registry 来启用不安全连接。
podman_use_new_toml_formatter变量生成与 Podman 兼容的 TOML 配置文件。此变量通过 true TOML 格式而不是之前使用的 Jinja 模板,支持所有 TOML 功能(包括表和内联表)来增强 Podman 角色。默认情况下禁用新格式器,以保持与之前格式器的行为的兼容性。要启用新格式器,请在配置中设置
podman_use_new_toml_formatter: true:podman_use_new_toml_formatter: true podman_containers_conf: containers: annotations: - environment=production - status=tier2-
验证 playbook 语法:
$ ansible-playbook --syntax-check ~/playbook.yml请注意,这个命令只验证语法,不能防止错误的、但有效的配置。
运行 playbook:
$ ansible-playbook ~/playbook.yml
验证
在主机上运行
podman info命令:$ ansible managed-node-01.example.com -m command -a 'podman info'验证 registeries 部分:
registries: my-company-registry.com: Blocked: false Insecure: false Location: my-company-registry.com MirrorByDigestOnly: false Mirrors: null Prefix: my-company-registry.com PullFromMirror: "" my-local-registry:5000: Blocked: false Insecure: true Location: my-local-registry:5000 MirrorByDigestOnly: false Mirrors: null Prefix: my-local-registry:5000 PullFromMirror: "" search: - registry.access.redhat.com - docker.io - my-company-registry.com