Ensure that Cloud Monitoring is enabled for your Google Kubernetes Engine (GKE) clusters to collect metrics emitted by your Kubernetes applications and the GKE infrastructure. Cloud Monitoring helps track cluster health, application reliability, and performance metrics.
PoC代码[已公开]
id: gcloud-gke-monitoring-disabled
info:
name: GKE Clusters Without Cloud Monitoring Enabled
author: princechaddha
severity: medium
description: |
Ensure that Cloud Monitoring is enabled for your Google Kubernetes Engine (GKE) clusters to collect metrics emitted by your Kubernetes applications and the GKE infrastructure. Cloud Monitoring helps track cluster health, application reliability, and performance metrics.
impact: |
Without monitoring enabled, it becomes difficult to identify and address performance bottlenecks, security threats, and potential failures in your GKE clusters. Basic information such as CPU usage, memory usage, and disk usage would not be available for observability metrics.
remediation: |
Enable Cloud Monitoring for your GKE clusters using:
gcloud container clusters update CLUSTER_NAME --region=REGION --monitoring=SYSTEM,API_SERVER,SCHEDULER,CONTROLLER_MANAGER,DAEMONSET,DEPLOYMENT,HPA,POD,STATEFULSET,STORAGE,CADVISOR,KUBELET,DCGM
reference:
- https://cloud.google.com/kubernetes-engine/docs/how-to/monitoring
- https://www.trendmicro.com/cloudoneconformity/knowledge-base/gcp/GKE/enable-and-configure-cloud-monitoring.html
tags: cloud,devops,gcp,gcloud,gke,kubernetes,monitoring,observability,gcp-cloud-config
flow: |
code(1)
for(let projectId of iterate(template.projectIds)){
set("projectId", projectId)
code(2)
for(let cluster of iterate(template.clusters)){
cluster = JSON.parse(cluster)
set("clusterName", cluster.name)
set("location", cluster.location)
code(3)
}
}
self-contained: true
code:
- engine:
- sh
- bash
source: |
gcloud projects list --format="json(projectId)"
extractors:
- type: json
name: projectIds
internal: true
json:
- '.[].projectId'
- engine:
- sh
- bash
source: |
gcloud container clusters list --project $projectId --format="json(name,location)"
extractors:
- type: json
name: clusters
internal: true
json:
- '.[]'
- engine:
- sh
- bash
source: |
gcloud container clusters describe $clusterName --location $location --project $projectId --format="json(monitoringService)"
matchers:
- type: word
words:
- '"monitoringService": "none"'
extractors:
- type: dsl
dsl:
- '"GKE cluster " + clusterName + " in " + location + " of project " + projectId + " does not have Cloud Monitoring enabled"'
# digest: 4a0a00473045022100c7f351e4167613205be4f5f58df596b99fab803b1b7815cf6fb48597e961dbaa02204d62ac56df1ea09c88adcb73e05ab6d51a11a0c56eb1ed82777c289c8d11e4f2:922c64590222798bb761d5b6d8e72950