Gke Observability

作者 google55b4e13eba6d無授權條款21K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Configures GKE observability, including Cloud Logging, Cloud Monitoring, and managed Prometheus. Use when configuring GKE monitoring, setting up GKE logging, or configuring Prometheus metrics collection, and to troubleshoot Managed Service for Prometheus (GMP) issues such as missing metrics, unhealthy scrape targets, PodMonitoring misconfiguration, rule/alert evaluation failures, and monitoring permission errors. Don't use to configure local application logging frameworks or external APMs outside GKE.

精選僅含說明DevOps & Cloud
AI 產生的概覽

設定 GKE 可觀測性(Cloud Logging、Cloud Monitoring、代管 Prometheus),並排解 GMP 問題。

功能
提供啟用 GKE 記錄、監控與代管 Prometheus 的參考指引,包含黃金路徑元件清單、gcloud 指令與成本說明。也說明如何診斷 Managed Service for Prometheus 的問題,例如指標缺漏、抓取目標異常、PodMonitoring 設定錯誤、規則評估失敗與權限錯誤。並提供指標、告警、節點健康與記錄查詢語言範例。
適用情境
適用於設定 GKE 監控、記錄或 Prometheus 指標收集,或排解 GMP 問題(如指標缺漏、抓取目標失敗、監控權限錯誤)。不適用於 GKE 之外的本機應用程式記錄框架或外部 APM。
執行需求
僅為說明文件,不含指令碼。需要 GKE 叢集以及 gcloud CLI、kubectl,並能存取 Cloud Monitoring 與 Cloud Logging;文中也引用若干用於叢集檢查的 MCP 工具。

GKE Observability

This reference covers monitoring, logging, and metrics configuration for GKE. The golden path enables comprehensive observability including control-plane metrics.

MCP Tools: get_cluster, list_k8s_events, get_k8s_logs, get_k8s_cluster_info, describe_k8s_resource. CLI-only: gcloud container clusters update --monitoring=..., gcloud logging read

Golden Path Observability Defaults

SettingGolden Path ValueNotes
loggingConfig componentsSYSTEM_COMPONENTS, WORKLOADSFull workload logging
monitoringConfig componentsSYSTEM_COMPONENTS, STORAGE, POD, DEPLOYMENT, STATEFULSET, DAEMONSET, HPA, JOBSET, CADVISOR, KUBELET, DCGM, APISERVER, SCHEDULER, CONTROLLER_MANAGERFull suite including control-plane
managedPrometheusConfig.enabledtrueGoogle-managed Prometheus
advancedDatapathObservabilityConfig.enableMetricstrueDataplane V2 flow metrics
loggingServicelogging.googleapis.com/kubernetesCloud Logging
monitoringServicemonitoring.googleapis.com/kubernetesCloud Monitoring

Control-Plane Metrics (Golden Path Addition)

The golden path adds three control-plane monitoring components not present in default clusters:

ComponentWhat It Monitors
APISERVERAPI server request latency, error rates, admission webhook performance
SCHEDULERScheduling latency, pending pods, scheduling failures
CONTROLLER_MANAGERController work queue depth, reconciliation latency

These are critical for diagnosing cluster-level issues (slow API responses, scheduling delays, stuck controllers).

Enabling Full Monitoring

Say this whenever you hand over a --monitoring command:

  1. Control-plane metrics are NOT enabled by default. State this outright in your answer — do not leave it implied by the fact that you are supplying an enable command. API_SERVER, SCHEDULER, and CONTROLLER_MANAGER are off on every new cluster and collect nothing until explicitly turned on, and the same is true of DCGM, CADVISOR, KUBELET, and kube-state (POD, DEPLOYMENT, STATEFULSET, DAEMONSET, HPA, STORAGE, JOBSET). SYSTEM is the only package on by default. A user asking "why are there no API server metrics" has almost always simply never enabled them.
  2. The flag replaces, it does not append. The set supplied to --monitoring overrides the previous setting entirely, so omitting a component silently turns it off. Always pass the full desired list, and always include SYSTEM — it cannot be disabled while monitoring is on, and never on Autopilot.
  3. These metrics bill per sample ingested via Managed Service for Prometheus. Enabling the full suite on a large cluster is a real cost increase; mention it rather than presenting the list as free.

The gcloud flag and the API field use different spellings for the same components. Do not copy names between them:

Componentgcloud --monitoring=monitoringConfig API enum
SystemSYSTEMSYSTEM_COMPONENTS
API serverAPI_SERVERAPISERVER
Controller mgrCONTROLLER_MANAGERCONTROLLER_MANAGER

The remaining components share a spelling. Using an API enum in the CLI flag (or the reverse) fails the command — this is a common and confusing error.

bash
# Enable golden path monitoring suitegcloud container clusters update <CLUSTER_NAME> --region <REGION> \  --monitoring=SYSTEM,API_SERVER,SCHEDULER,CONTROLLER_MANAGER,STORAGE,POD,DEPLOYMENT,STATEFULSET,DAEMONSET,HPA,JOBSET,CADVISOR,KUBELET,DCGM \  --quiet
# Enable Managed Prometheusgcloud container clusters update <CLUSTER_NAME> --region <REGION> \  --enable-managed-prometheus \  --quiet
# Enable Dataplane V2 observability metricsgcloud container clusters update <CLUSTER_NAME> --region <REGION> \  --enable-dataplane-v2-flow-observability \  --quiet

Managed Prometheus

Golden path enables Google Managed Prometheus for metrics collection and querying.

Querying metrics:

  • Use Cloud Monitoring Metrics Explorer in the console
  • Use PromQL via the Prometheus UI or API
  • Grafana dashboards via Managed Grafana

Key GKE metrics:

MetricSourceUse
container_cpu_usage_seconds_totalcAdvisorPod CPU usage
container_memory_working_set_bytescAdvisorPod memory usage
kube_pod_status_phasekube-state-metricsPod lifecycle
apiserver_request_duration_secondsAPI ServerControl plane latency
scheduler_scheduling_attempt_duration_secondsSchedulerScheduling performance
kubernetes.io/node/cpu/core_usage_timeCloud MonitoringNode CPU
DCGM_FI_DEV_GPU_UTILDCGMGPU utilization

Live Resource Usage (kubectl-only)

No MCP or gcloud equivalent exists for live resource usage. Use kubectl top:

bash
kubectl top pods --all-namespaces --sort-by=cpukubectl top nodeskubectl top pods --containers -n <NAMESPACE>  # per-container breakdown

Cloud Logging (gcloud-only)

Querying cluster logs (no MCP equivalent — use gcloud logging read):

bash
# System component logsgcloud logging read \  'resource.type="k8s_cluster" AND resource.labels.cluster_name="<CLUSTER_NAME>"' \  --project <PROJECT_ID> --limit 50 \  --quiet
# Workload logs for a specific namespacegcloud logging read \  'resource.type="k8s_container" AND resource.labels.cluster_name="<CLUSTER_NAME>" AND resource.labels.namespace_name="<NAMESPACE>"' \  --project <PROJECT_ID> --limit 50 \  --quiet
# Audit logs (who did what)gcloud logging read \  'resource.type="k8s_cluster" AND logName:"cloudaudit.googleapis.com"' \  --project <PROJECT_ID> --limit 50 \  --quiet

Diagnostic Settings

For security monitoring and troubleshooting, enable control-plane audit logs:

bash
# View current logging configgcloud container clusters describe <CLUSTER_NAME> --region <REGION> \  --format="yaml(loggingConfig)" \  --quiet

Alerting

Set up alerts for critical conditions:

ConditionMetricThreshold
High API server latencyapiserver_request_duration_secondsP99 > 5s
Pod crash loopskube_pod_container_status_restarts_total> 5 in 10min
Node not readykube_node_status_conditioncondition=Ready, status!=True
High GPU utilizationDCGM_FI_DEV_GPU_UTIL> 95% sustained
PVC near capacitykubelet_volume_stats_used_bytes / capacity> 85%
Scheduling failuresscheduler_schedule_attempts_total{result="error"}> 0

Prerequisite: The kube_* series above (e.g., kube_pod_status_phase, kube_pod_container_status_restarts_total, kube_node_status_condition) come from kube-state-metrics, which GKE does not collect by default. Deploy the Managed Prometheus kube-state-metrics package first.

Proposing Dashboards & Alerts (Production Rules)

When designing or proposing alerting and dashboard strategies for GKE:

  1. Always explicitly name Google Cloud Monitoring as the platform to implement these alerts and dashboards.
  2. Always include API server latency (via apiserver_request_duration_seconds metric) on the dashboard as a critical indicator of control plane health, alongside node CPU/Memory and pod crash loops.

Node Health (Production Rules)

A comprehensive assessment of node health relies on analyzing these two metrics together:

  1. kubernetes.io/node/status_condition (filtered by status_condition="Ready"): Use this to track healthy nodes. Note that it will only report values for nodes that have successfully bootstrapped.
  2. compute.googleapis.com/instance_group/size (filtered by instance_group_name="gke-<cluster_name>-.*"): Use this to track the total number of nodes in a specific cluster. Note that it does not differentiate between healthy and unhealthy nodes.

Cost Considerations

Monitoring and logging have associated costs:

  • Cloud Logging: Charged per GiB ingested beyond free tier (50 GiB/project/month)
  • Cloud Monitoring: Free for GKE system metrics; custom metrics charged per time series
  • Managed Prometheus: Charged per samples ingested

To reduce costs in non-production:

bash
# Reduce to system-only monitoringgcloud container clusters update <CLUSTER_NAME> --region <REGION> \  --monitoring=SYSTEM \  --quiet

Distributed Tracing & Continuous Profiling (Recommended)

Not golden path defaults — recommended for production microservice architectures and performance-sensitive workloads.

  • Cloud Trace: Add OpenTelemetry SDK to your app with the opentelemetry-operations-go (or equivalent) exporter. Traces appear in Cloud Trace console. Identifies cross-service latency bottlenecks.
  • Cloud Profiler: Add the Cloud Profiler agent to your app. Profiles CPU and memory usage in production with low overhead. Identifies hotspots and compares across versions.

Recent additions:

  • Managed OpenTelemetry for GKE (Preview): Managed in-cluster OTLP endpoint plus auto-instrumentation for traces, metrics, and logs. Requires GKE 1.34.1-gke.2178000+; enable with gcloud beta container clusters update ... --managed-otel-scope=COLLECTION_AND_INSTRUMENTATION_COMPONENTS.
  • PSI (Pressure Stall Information) metrics: cAdvisor container_pressure_{cpu,memory,io}_{waiting,stalled}_seconds_total series (beta in Kubernetes 1.34) can be collected via a Managed Prometheus ClusterNodeMonitoring resource; GKE's documented collection path requires GKE 1.35+.

LQL Query Examples

Common Logging Query Language patterns for GKE troubleshooting:

# Error logs for a specific containerresource.type="k8s_container" AND resource.labels.container_name="my-app" AND severity>=ERROR
# OOMKilled eventsresource.type="k8s_event" AND jsonPayload.reason="OOMKilling"
# Pod scheduling failuresresource.type="k8s_event" AND jsonPayload.reason="FailedScheduling"
# Audit logs (who did what)resource.type="k8s_cluster" AND logName:"cloudaudit.googleapis.com"

Troubleshooting Managed Prometheus (GMP)

Diagnose GMP ingestion, rule, and query problems. Stay read-only (kubectl get / describe / logs) and propose config changes; do not mutate live resources directly.

First: split ingestion-side vs query-side

Before anything else, query the up metric in the Metrics Explorer PromQL tab in Cloud Monitoring. If up returns data, ingestion works and the problem is query-side (Grafana / PromQL / permissions). If up is empty, the problem is ingestion-side (collectors, scrape config, or write permission).

Ingestion-side

  1. Check GMP system pods. They run in gmp-system on Standard clusters and gke-gmp-system on Autopilot. Look for gmp-operator, collector (DaemonSet), and rule-evaluator not Running or with high restarts:

    bash
    kubectl get pods -n gmp-system            # gke-gmp-system on Autopilotkubectl logs -n gmp-system -l app.kubernetes.io/name=collector -c prometheus

    A collector in CrashLoopBackOff with OOMKilled usually means high metric cardinality - drop unneeded series/labels (see cost section below) or apply a VPA to the collector.

  2. Check PodMonitoring / ClusterPodMonitoring. The three classic mistakes:

    • spec.selector.matchLabels does not match the target Pod labels.
    • A PodMonitoring only discovers targets in its own namespace - use ClusterPodMonitoring for cluster-wide scope.
    • spec.endpoints.port must reference the named container port (e.g. port: web), not the port number.
  3. Enable target status for scrape errors. Propose patching OperatorConfig in gmp-public with features.targetStatus.enabled: true; once applied, kubectl describe podmonitoring <name> and read Active Targets, Unhealthy Targets, and Last Error (for example connection refused, HTTP 404, context deadline exceeded). Disable it again when done - it can OOM the operator on large clusters.

Permissions (403 / no data written)

GMP components inherit the node service account. Ingestion needs roles/monitoring.metricWriter (error Permission monitoring.timeSeries.create denied in collector logs); the rule-evaluator and query paths need roles/monitoring.viewer (403 / PermissionDenied). If a query app (like Grafana) uses Workload Identity, the bound Google service account also needs roles/monitoring.viewer.

Rule and alert evaluation

Rule scope is decided by the resource kind: Rules (single namespace), ClusterRules (whole cluster), and GlobalRules (all data in the metrics scope). You must use GlobalRules to write rules against Cloud Monitoring metrics - a Rules/ClusterRules resource silently returns no data for them. Check rule-evaluator logs (-c evaluator) for parse/permission errors.

Query-side (Grafana / PromQL)

  • Data source must point at the GMP frontend query proxy, not localhost:9090, and the HTTP Method must be GET - POST fails with no match[] parameter provided.
  • Grafana template variables: use the two-argument form label_values(<metric>, <label>); the single-argument label_values(<label>) is not supported by the GMP API.
  • Cloud Monitoring metrics that exist for multiple resource types need a monitored_resource label matcher, otherwise the query fails with series selector must specify a label matcher on monitored resource name.

Cost, cardinality, and quota

Use the Cloud Monitoring Metrics Management page to find the metrics driving billable samples and high cardinality. Reduce them with metricRelabeling in the PodMonitoring (action: drop for whole metrics, action: labeldrop for unbounded labels like user_id/request_id) or by raising the scrape interval. 429 / RESOURCE_EXHAUSTED errors mean you have hit the Cloud Monitoring API ingestion or query quota - optimize first, then request a quota increase.

Supporting Links

來源與署名

來源:google/skills位於skills/cloud/gke-observability提交55b4e13

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架

更多來自 google/skills 的技能

Dpop Adoption

google

精選

指導為 Google OAuth 平台實作 OAuth 2.0 DPoP(RFC 9449)傳送方約束的更新權杖。

Security21K今天更新

Finding Google Skills

google

精選

Google platform decision and setup guidance, loaded on demand from Google's skill catalog. Use when a developer is choosing or setting up part of their stack, such as where to run a service, a database, storage, messaging, authentication, analytics, ads, or AI model serving, and a Google product is a reasonable candidate - whether or not a vendor is named - or when a request names a Google product or API. Brings in the matching Google skill so the answer can weigh Google options, their trade-offs, and when they are not the right fit. Skip when the stack is already settled on another provider and no Google product is named, or the task involves no platform choice.

待分類21K今天更新

Spanner Basics

google

精選

指導 Google Cloud Spanner 的執行個體與資料庫管理、結構定義設計、查詢與效能診斷。

Data & Analytics21K今天更新

Secops Triage

google

精選

引導 SOC 分析師對 Google SecOps 安全警示進行分診,從調查到結案或升級。

Security21K今天更新

Secops Investigate

google

精選

指導 SOC 分析師在 Google SecOps 中使用 UDM 查詢與時間軸進行深入的安全事件與實體調查。

Security21K今天更新

Secops Hunt

google

精選

指導在 Google SecOps 中使用 UDM 查詢、IoC 回溯、普遍性與異常分析進行主動威脅狩獵。

Security21K今天更新