且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 Ansible 中检索已创建的 Google Kubernetes (GKE) 集群的凭据?

更新时间:2021-12-06 22:15:03

当您使用 gcp_container_cluster 创建集群时,返回值将包括 kubeconfig 文件的存储路径.您可以使用带有 {{ cluster.kubectlPath }} 的示例引用此路径.

When you create the cluster using the gcp_container_cluster, the return value will include the path where the kubeconfig file is stored. You can refer to this path using your example with {{ cluster.kubectlPath }}.

当你想使用k8s模块时,你可以定义kubeconfig 文件路径 用于模块.. 它看起来像这样:

When you want to use the k8s module, you can define the kubeconfig file path to use for the module.. It will look something like this:

    - name: "Create Google Kubernetes Engine Cluster to be setup with with kubectl"
      gcp_container_cluster:
        name: "{{cluster_name}}"
        kubectlPath: /path/to/save/config
        [...]
      register: cluster
    - name: "Create k8s resource"
      k8s:
        kubeconfig: "{{ cluster.kubectlPath }}"
        definition:
          [...]

我在回应"中误读了该文件部分阐明了要写入此路径的文件必须设置此字段,此字段没有默认值.

I misread the document, in the "response" section it clarifies that this field must be set for the file to be written in this path, there is no default value for this field.