繁体   English   中英

Ansible K8s 模块 - 一次应用多个 Yaml 文件

[英]Ansible K8s Module - Apply Multiple Yaml Files at Once

编写 Ansible 剧本,我们从 GIT 存储库中提取项目,然后将所有提取的 yaml 应用到 Kubernetes 集群。

我只看到了一个将单个 yaml 文件应用于 Kubernetes 集群的示例,而不是一次应用多个。 例如:

- name: Apply metrics-server manifest to the cluster.
  community.kubernetes.k8s:
    state: present
    src: ~/metrics-server.yaml

有没有办法应用多个yaml文件? 就像是:

- name: Apply Services to the cluster.
  community.kubernetes.k8s:
    state: present
    src: ~/svc-*.yaml

或者:

- name: Apply Ingresses to the cluster.
  community.kubernetes.k8s:
    state: present
    dir: ~/ing/

也许我应该查看另一个 Ansible K8s 模块?

或者我们应该直接在 Ansible 任务中运行 kubectl 命令。 例如:

- name: Apply Ingresses to the cluster.
  command: kubectl apply -f ~/ing/*.yaml

使用 Ansible 实现这一目标的最佳方法是什么?

您可以将 k8s Ansible 模块与“with_fileglob”递归模式一起使用。 下面的代码应该可以满足您的要求。

- name: Apply K8s resources
        k8s:
          definition: "{{ lookup('template', '{{ item }}') | from_yaml }}"
        with_fileglob:
          - "~/ing/*.yaml"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM