【发布时间】:2019-10-13 16:24:23
【问题描述】:
我启动 GCP 集群没有问题,但我不知道如何让 k8s ansible 模块工作。我宁愿让 api_key 验证到 k8s 模块。
我的剧本如下。
- name: Hello k8s
hosts: all
tasks:
- name: Create a cluster
register: cluster
gcp_container_cluster:
name: thecluster
initial_node_count: 1
master_auth:
username: admin
password: TheRandomPassword
node_config:
machine_type: g1-small
disk_size_gb: 10
oauth_scopes:
- "https://www.googleapis.com/auth/compute"
- "https://www.googleapis.com/auth/devstorage.read_only"
- "https://www.googleapis.com/auth/logging.write"
- "https://www.googleapis.com/auth/monitoring"
zone: europe-west3-c
project: second-network-255214
auth_kind: serviceaccount
service_account_file: "{{ lookup('env', 'GOOGLE_CREDENTIALS') }}"
state: present
- name: Show results
debug: var=cluster
- name: Create temporary file for CA
tempfile:
state: file
suffix: build
register: ca_crt
- name: Save content to file
copy:
content: "{{ cluster.masterAuth.clusterCaCertificate |b64decode }}"
dest: "{{ ca_crt.path }}"
- name: Create a k8s namespace
k8s:
host: "https://{{ cluster.endpoint }}"
ca_cert: "{{ ca_crt.path }}"
api_key: "{{ cluster.HOW_I_GET_THE_API_KEY}}" <<<-- Here is what I want!!!
name: testing
api_version: v1
kind: Namespace
state: present
有什么想法吗?
【问题讨论】:
-
我希望它在
cluster.masterAuth中,我看到你已经debug:编辑了它,所以你没有在那个数据结构中找到token吗? -
没错。我使用 google_client_config 在 terraform 中实现了相同的任务。我想在 ansible 中会有一个 simikar 模块。
-
我已尝试使用空的 master_auth 映射并删除 master_auth 条目。也许可以用 k8s_auth 模块完成,但我不知道如何配置它。
-
不,我的意思是
cluster.masterAuth已经包含clusterCaCertificate--cluster.masterAuth还包含什么? -
如果我在 master_auth 块中传递用户名或密码,除了 clusterCaCertificate 之外,我还会在 masterAuth 中获取它们(用户名和密码)。对于身份验证,我认为不需要用户名和密码。理想的情况是为 GCP 服务帐户获取 access_token。此外,我认为 access_token 不仅在集群上下文中有效,而且在整个 GCP 中都有效。所以与 gcp_container_cluster 无关,但应该有一个 gcp_iam_service_account_token 或一个 oauth 模块可以完成这项工作。
标签: kubernetes ansible google-compute-engine google-kubernetes-engine