【问题标题】:How to deploy microservices in azure kubernetes using ansible and helm?如何使用 ansible 和 helm 在 azure kubernetes 中部署微服务?
【发布时间】:2021-10-03 02:23:58
【问题描述】:

我需要将多个微服务(支付、订单)部署到不同的环境(开发、质量保证)中。

根据我的分析,我希望我们通过以下步骤实现这一目标

  1. 为不同的环境创建单独的集群

  2. 根据环境创建多个变量文件。

我们只能根据我们的部署传递集群名称和变量文件。因此它将根据我们的输入进行部署。

我正在尝试实现相同的功能,但我不确定如何通过实时使用 ansible 和 helm 部分来配置上述场景。

有人请给我建议吗?

参考 https://docs.ansible.com/ansible/latest/collections/community/kubernetes/k8s_module.html

【问题讨论】:

    标签: azure ansible kubernetes-helm helmfile


    【解决方案1】:

    如果您打算设置 CI/CD 并仅使用 helm,您可以在没有 ansible 的情况下部署服务。

    一旦在 CI/CD 中设置了上下文,Helm 就会使用上下文,相应的服务将部署到该特定环境。

    你可以只使用头盔。

    但是使用 ansible

    您可以编写将使用适当的 K8s 上下文开发或 QA 的剧本,并且进一步的 ansible 将简单地部署掌舵。

    示例剧本,但如果您的情况不需要任何内容​​,您可以删除额外的部分

    ---
    - hosts: localhost
      connection: local
      vars:
        helm_namespace: "ansible-helm-jenkins-demo"
        helm_release_name: "ansible-helm-jenkins-demo"
        helm_version: "v3.2.3"
        helm_binary_directory: /tmp/helm
        helm_archive_name: "helm-{{ helm_version }}-{{ ansible_system | lower }}-amd64.tar.gz"
        helm_binary: "{{ helm_binary_directory}}/{{ ansible_system | lower }}-amd64/helm"
    
      tasks:
        - name: Init Helm folders
          file:
            path: "{{ helm_binary_directory }}"
            state: directory
    
        - name: Check if Helm Binary Present
          stat:
            path: "{{ helm_binary }}"
          register: helm_binary_present
    
        - name: Unarchive Helm binary
          unarchive:
            src: "https://get.helm.sh/{{ helm_archive_name }}"
            dest: "{{ helm_binary_directory }}"
            remote_src: yes
          when: not helm_binary_present.stat.exists
    
        - name: Create Helm Namespace
          community.kubernetes.k8s:
            name: "{{ helm_namespace }}"
            api_version: v1
            kind: Namespace
            state: present
    
        - name: Deploy Helm Chart
          community.kubernetes.helm:
            name: "{{ helm_release_name }}"
            chart_ref: "{{ playbook_dir }}/../../helm/ansible-helm-jenkins-demo"
            release_namespace: "{{ helm_namespace }}"
            binary_path: "{{ helm_binary }}"
            values: "{{ chart_values | default({}) }}"
    

    Github 参考:https://github.com/sabre1041/ansible-helm-jenkins-demo

    【讨论】:

      猜你喜欢
      • 2020-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2018-09-22
      • 2021-02-04
      • 2021-11-05
      相关资源
      最近更新 更多