Description
Use GKE resource_labels for the cluster’s environment and owner. Manage Kubernetes pod labels and IAM permissions separately.
Potential impact
A cluster without labels can be difficult to assign to a team in cost reports or inventory.
Remediation
Set your team’s keys and values in google.cloud.gcp_container_cluster.resource_labels. Keep secrets out of labels and update them when ownership or purpose changes.
Examples
The create tasks name different clusters, my-cluster1 and my-cluster. Point gcp_credentials_file to the service account’s JSON credentials file. For an existing cluster, look it up by project, location and name, then call setResourceLabels with its current labelFingerprint and the full set of labels you want to keep.
Before
- name: Create the GKE cluster
google.cloud.gcp_container_cluster:
name: my-cluster1
initial_node_count: 2
location: us-central1-a
project: "{{ gcp_project }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_credentials_file }}"
state: present
After
- name: Create the GKE cluster
google.cloud.gcp_container_cluster:
name: my-cluster
initial_node_count: 2
location: us-central1-a
project: "{{ gcp_project }}"
auth_kind: serviceaccount
service_account_file: "{{ gcp_credentials_file }}"
state: present
resource_labels:
env: prod
owner: platform