如何使用自定义映像在 Ansible 中创建 Google Kubernetes (GKE) 集群?

How to create Google Kubernetes (GKE) cluster in Ansible with custom image?

我过去曾使用此模式创建 GKE,效果很好,但现在我需要定义要使用的自定义图像类型。

这是我正在使用的 ansible 剧本。

- name: GCE
  hosts: localhost
  gather_facts: no
  vars_files:
    - vars/default.yml

  tasks:
    - name: create cluster
      gcp_container_cluster:
        name: "{{ cluster_name }}"
        initial_node_count: "{{ node_count}}"
        initial_cluster_version: "{{ cluster_kubernetes_version }}"
        master_auth:
          username: admin
          password: "{{ cloud_admin }}"
        node_config:
          machine_type:  e2-medium
          disk_size_gb: "{{ disk_size_gb }}"
        location: "{{ cluster_zone}}"
        project: "{{ project }}"
        auth_kind: "{{ auth_kind }}"
        service_account_file: "{{ service_account_file }}"
        state: present
        scopes: "{{ scopes }}"
      register: cluster
    - name: create a node pool
      google.cloud.gcp_container_node_pool:
        name: default-pool
        autoscaling:
          enabled: yes
          min_node_count: "{{ node_count}}"
          max_node_count: "{{ max_node_count }}"
        initial_node_count: "{{ node_count }}"
        cluster: "{{ cluster }}"
        location: "{{ cluster_zone}}"
        config:
          machine_type: e2-medium
          disk_size_gb: "{{ disk_size_gb }}"
        project: "{{ gce_project}}"
        auth_kind: serviceaccount
        service_account_file: "{{ service_account_file }}"
        state: presen

我正在尝试使用具有 16 个内核和 70GB RAM 的基于 E2 的映像。规范并不重要,因为我无法指定已经预先配置的 'machine type'。

是否仍然可以使用ansible创建集群?我是否需要创建自定义图像类型以供参考?

澄清一下,没有抛出任何错误。将 machine_type 定义为 e2-medium 不允许我分配我需要的资源并定义具有所需资源的实例。我在问如何说使用 e2-medium 作为基础并将 ram 分配增加到 70GB 或者这是否可行?

IIUC,您应该能够将您的机器类型引用为 e2-custom-16-71680

即:

- name: your-cluster
  google.cloud.gcp_container_cluster:
    ...
    node_config:
      machine_type: e2-custom-16-71680
      disk_size_gb: "{{ disk_size_gb }}"
    ...

用于指定自定义机器类型的(隐藏)文档:

https://cloud.google.com/compute/docs/instances/creating-instance-with-custom-machine-type#gcloud