Configurer l'observabilité GKE Dataplane V2

Cette page explique comment configurer des clusters Google Kubernetes Engine (GKE) avec l'observabilité de GKE Dataplane V2, à partir de la version 1.32 ou ultérieure de GKE. Pour plus d'informations sur les avantages et les exigences de l'observabilité GKE Dataplane V2, consultez la page À propos de l'observabilité GKE Dataplane V2.

Avant de commencer

Avant de commencer, effectuez les tâches suivantes :

  • Activez l'API Google Kubernetes Engine.
  • Activer l'API Google Kubernetes Engine
  • Si vous souhaitez utiliser Google Cloud CLI pour cette tâche, installez puis initialisez gcloud CLI. Si vous avez déjà installé la gcloud CLI, obtenez la dernière version en exécutant la commande gcloud components update. Il est possible que les versions antérieures de gcloud CLI ne permettent pas d'exécuter les commandes de ce document.

Configurer les métriques GKE Dataplane V2

Pour collecter des métriques, vous devez configurer des métriques GKE Dataplane V2. Vous pouvez configurer des métriques GKE Dataplane V2 lorsque vous créez un cluster ou lorsque vous mettez à jour un cluster exécuté avec GKE Dataplane V2. Vous pouvez activer ou désactiver les métriques GKE Dataplane V2 en utilisant gcloud CLI.

Nous vous recommandons d'activer les métriques GKE Dataplane V2 et Google Cloud Managed Service pour Prometheus sur votre cluster GKE. Une fois les deux activées, les métriques GKE Dataplane V2 sont envoyées à Google Cloud Managed Service pour Prometheus.

Créer un cluster Autopilot avec les métriques GKE Dataplane V2 activées

Lorsque vous créez des clusters GKE Autopilot, GKE active les métriques GKE Dataplane V2 par défaut sur le cluster sans nécessiter d'option spécifique.

Pour utiliser les métriques GKE Dataplane V2 de cluster GKE Autopilot avec Google Cloud Managed Service pour Prometheus, configurez la ressource ClusterPodMonitoring pour récupérer les métriques et les envoyer à Google Cloud Managed Service pour Prometheus.

  1. Créez un fichier manifeste ClusterPodMonitoring :

    # Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # #     https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.  apiVersion: monitoring.googleapis.com/v1 kind: ClusterPodMonitoring metadata:   name: advanced-datapath-observability-metrics spec:   selector:     matchLabels:       k8s-app: cilium   endpoints:   - port: flowmetrics     interval: 60s     metricRelabeling:     # only keep denormalized pod flow metrics     - sourceLabels: [__name__]       regex: 'pod_flow_(ingress|egress)_flows_count'       action: keep     # extract pod name     - sourceLabels: [__name__, destination]       regex: 'pod_flow_ingress_flows_count;([a-zA-Z0-9-\.]+)/([a-zA-Z0-9-\.]+)'       replacement: '${2}'       targetLabel: pod_name       action: replace     - sourceLabels: [__name__, source]       regex: 'pod_flow_egress_flows_count;([a-zA-Z0-9-\.]+)/([a-zA-Z0-9-\.]+)'       replacement: '${2}'       targetLabel: pod_name       action: replace     # extract workload name by removing 2 last "-XXX" parts     - sourceLabels: [pod_name]       regex: '([a-zA-Z0-9-\.]+)((-[a-zA-Z0-9\.]+){2})'       replacement: '${1}'       targetLabel: workload_name       action: replace     # extract workload name by removing one "-XXX" part when pod name has only 2 parts (eg. daemonset)     - sourceLabels: [pod_name]       regex: '([a-zA-Z0-9\.]+)((-[a-zA-Z0-9\.]+){1})'       replacement: '${1}'       targetLabel: workload_name       action: replace     # extract pod namespace     - sourceLabels: [__name__, destination]       regex: 'pod_flow_ingress_flows_count;([a-zA-Z0-9-\.]+)/([a-zA-Z0-9-\.]+)'       replacement: '${1}'       targetLabel: namespace_name       action: replace     - sourceLabels: [__name__, source]       regex: 'pod_flow_egress_flows_count;([a-zA-Z0-9-\.]+)/([a-zA-Z0-9-\.]+)'       replacement: '${1}'       targetLabel: namespace_name       action: replace     # extract remote workload name     - sourceLabels: [__name__, source]       regex: 'pod_flow_ingress_flows_count;([a-zA-Z0-9-\.]+)/([a-zA-Z0-9-\.]+)'       replacement: '${2}'       targetLabel: remote_workload       action: replace     - sourceLabels: [__name__, destination]       regex: 'pod_flow_egress_flows_count;([a-zA-Z0-9-\.]+)/([a-zA-Z0-9-\.]+)'       replacement: '${2}'       targetLabel: remote_workload       action: replace     # extract remote workload namespace     - sourceLabels: [__name__, source]       regex: 'pod_flow_ingress_flows_count;([a-zA-Z0-9-\.]+)/([a-zA-Z0-9-\.]+)'       replacement: '${1}'       targetLabel: remote_namespace       action: replace     - sourceLabels: [__name__, destination]       regex: 'pod_flow_egress_flows_count;([a-zA-Z0-9-\.]+)/([a-zA-Z0-9-\.]+)'       replacement: '${1}'       targetLabel: remote_namespace       action: replace     # default remote workload class to "pod"     - replacement: 'pod'       targetLabel: remote_class       action: replace     # extract remote workload class from reserved identity     - sourceLabels: [__name__, source]       regex: 'pod_flow_ingress_flows_count;reserved:([^/]*)'       replacement: '${1}'       targetLabel: remote_class       action: replace     - sourceLabels: [__name__, destination]       regex: 'pod_flow_egress_flows_count;reserved:([^/]*)'       replacement: '${1}'       targetLabel: remote_class       action: replace   targetLabels:     metadata: [] 
  2. Appliquez le fichier manifeste ClusterPodMonitoring :

    kubectl apply -f ClusterPodMonitoring.yaml 

Créer un cluster standard avec les métriques GKE Dataplane V2 activées

Pour activer les métriques GKE Dataplane V2, créez un cluster avec l'option --enable-dataplane-v2-metrics :

gcloud container clusters create CLUSTER_NAME \     --enable-dataplane-v2 \     --enable-ip-alias \     --enable-managed-prometheus \     --enable-dataplane-v2-metrics 

Remplacez les éléments suivants :

  • CLUSTER_NAME : nom du cluster

L'option --enable-managed-prometheus indique à GKE d'utiliser les métriques avec Google Cloud Managed Service pour Prometheus.

Activer les métriques GKE Dataplane V2 sur un cluster existant

Pour activer les métriques GKE Dataplane V2 sur un cluster existant, exécutez la commande suivante :

gcloud container clusters update CLUSTER_NAME \     --enable-dataplane-v2-metrics 

Remplacez CLUSTER_NAME par le nom de votre cluster.

Désactiver les métriques GKE Dataplane V2

Pour désactiver les métriques GKE Dataplane V2, procédez comme suit :

gcloud container clusters update CLUSTER_NAME \     --disable-dataplane-v2-metrics 

Remplacez CLUSTER_NAME par le nom de votre cluster.

Configurer les outils d'observabilité GKE Dataplane V2

Vous pouvez utiliser un point de terminaison privé pour accéder aux outils de dépannage de l'observabilité de GKE Dataplane V2. Pour activer les outils d'observabilité de GKE Dataplane V2, vous devez disposer d'un cluster configuré avec GKE Dataplane V2. Vous pouvez activer les outils d'observabilité de GKE Dataplane V2 sur un nouveau cluster ou sur un cluster existant.

Créer un cluster Autopilot avec l'observabilité activée

Pour créer un cluster GKE Autopilot avec l'observabilité GKE Dataplane V2 activée, procédez comme suit :

gcloud container clusters create-auto CLUSTER_NAME \     --enable-dataplane-v2-flow-observability \     --location COMPUTE_LOCATION 

Remplacez les éléments suivants : * CLUSTER_NAME : nom de votre cluster. * COMPUTE_LOCATION : emplacement Compute Engine du cluster.

Créer un cluster standard avec l'observabilité activée

Pour créer un cluster GKE Standard avec l'observabilité GKE Dataplane V2 activée, procédez comme suit :

gcloud container clusters create CLUSTER_NAME \     --enable-dataplane-v2 \     --enable-ip-alias \     --enable-dataplane-v2-flow-observability \     --location COMPUTE_LOCATION 

Remplacez les éléments suivants : * CLUSTER_NAME : nom de votre cluster. * COMPUTE_LOCATION : emplacement Compute Engine du cluster.

Activer les outils d'observabilité de GKE Dataplane V2 sur un cluster existant

Pour activer l'observabilité de GKE Dataplane V2 sur un cluster existant, exécutez la commande suivante :

gcloud container clusters update CLUSTER_NAME \     --enable-dataplane-v2-flow-observability \     --location COMPUTE_LOCATION 

Remplacez les éléments suivants :

Désactiver les outils d'observabilité GKE Dataplane V2

Pour désactiver les outils d'observabilité de GKE Dataplane V2 sur un cluster existant, exécutez la commande suivante :

gcloud container clusters update CLUSTER_NAME \     --disable-dataplane-v2-flow-observability 

Remplacez CLUSTER_NAME par le nom de votre cluster.

Utiliser la CLI Hubble

Utilisez l'outil de CLI Hubble sur le cluster après avoir activé la fonctionnalité d'observabilité de GKE Dataplane V2.

  1. Définissez l'alias pour le binaire hubble-cli :

    alias hubble="kubectl exec -it -n gke-managed-dpv2-observability deployment/hubble-relay -c hubble-cli -- hubble" 
  2. Pour vérifier l'état de Hubble, lorsque la fonctionnalité d'observabilité GKE Dataplane V2 est activée, utilisez la CLI Hubble dans tous les clusters Autopilot :

    hubble status 
  3. Pour afficher le trafic actuel, utilisez la CLI Hubble comme suit :

    hubble observe 

Déployer la distribution binaire de l'interface utilisateur Hubble

Une fois l'observabilité GKE Dataplane V2 activée, vous pouvez déployer l'interface utilisateur Open Source Hubble.

  1. Activez l'observabilité dans votre cluster GKE :

    1. Créez un cluster GKE avec l'observabilité activée :

      gcloud container clusters create-auto hubble-rc-auto \     --location COMPUTE_LOCATION \     --cluster-version VERSION \     --enable-dataplane-v2-flow-observability 

      Remplacez les éléments suivants :

    2. Vous pouvez également activer l'observabilité dans un cluster existant :

      gcloud container clusters update CLUSTER_NAME \     --location COMPUTE_LOCATION \     --enable-dataplane-v2-flow-observability 

      Remplacez les éléments suivants :

  2. Configurez kubectl pour vous connecter au cluster :

    gcloud container clusters get-credentials CLUSTER_NAME \     --location COMPUTE_LOCATION 

    Remplacer

  3. Déployez l'interface utilisateur de Hubble :

    # Copyright 2025 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # #     https://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License.  apiVersion: v1 kind: ServiceAccount metadata:   name: hubble-ui   namespace: gke-managed-dpv2-observability --- kind: ClusterRole apiVersion: rbac.authorization.k8s.io/v1 metadata:   name: hubble-ui   labels:     app.kubernetes.io/part-of: cilium rules:   - apiGroups:       - networking.k8s.io     resources:       - networkpolicies     verbs:       - get       - list       - watch   - apiGroups:       - ""     resources:       - componentstatuses       - endpoints       - namespaces       - nodes       - pods       - services     verbs:       - get       - list       - watch   - apiGroups:       - apiextensions.k8s.io     resources:       - customresourcedefinitions     verbs:       - get       - list       - watch   - apiGroups:       - cilium.io     resources:       - "*"     verbs:       - get       - list       - watch --- kind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata:   name: hubble-ui   labels:     app.kubernetes.io/part-of: cilium roleRef:   apiGroup: rbac.authorization.k8s.io   kind: ClusterRole   name: hubble-ui subjects:   - kind: ServiceAccount     name: hubble-ui     namespace: gke-managed-dpv2-observability --- apiVersion: v1 kind: ConfigMap metadata:   name: hubble-ui-nginx   namespace: gke-managed-dpv2-observability data:   nginx.conf: |     server {         listen       8081;         # uncomment for IPv6         # listen       [::]:8081;         server_name  localhost;         root /app;         index index.html;         client_max_body_size 1G;         location / {             proxy_set_header Host $host;             proxy_set_header X-Real-IP $remote_addr;             # CORS             add_header Access-Control-Allow-Methods "GET, POST, PUT, HEAD, DELETE, OPTIONS";             add_header Access-Control-Allow-Origin *;             add_header Access-Control-Max-Age 1728000;             add_header Access-Control-Expose-Headers content-length,grpc-status,grpc-message;             add_header Access-Control-Allow-Headers range,keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout;             if ($request_method = OPTIONS) {                 return 204;             }             # /CORS             location /api {                 proxy_http_version 1.1;                 proxy_pass_request_headers on;                 proxy_hide_header Access-Control-Allow-Origin;                 proxy_pass http://127.0.0.1:8090;             }             location / {                 # double `/index.html` is required here                 try_files $uri $uri/ /index.html /index.html;             }         }     } --- kind: Deployment apiVersion: apps/v1 metadata:   name: hubble-ui   namespace: gke-managed-dpv2-observability   labels:     k8s-app: hubble-ui     app.kubernetes.io/name: hubble-ui     app.kubernetes.io/part-of: cilium spec:   replicas: 1   selector:     matchLabels:       k8s-app: hubble-ui   template:     metadata:       labels:         k8s-app: hubble-ui         app.kubernetes.io/name: hubble-ui         app.kubernetes.io/part-of: cilium     spec:       securityContext:         fsGroup: 1000         seccompProfile:           type: RuntimeDefault       serviceAccount: hubble-ui       serviceAccountName: hubble-ui       containers:         - name: frontend           image: quay.io/cilium/hubble-ui:v0.13.2           ports:             - name: http               containerPort: 8081           volumeMounts:             - name: hubble-ui-nginx-conf               mountPath: /etc/nginx/conf.d/default.conf               subPath: nginx.conf             - name: tmp-dir               mountPath: /tmp           terminationMessagePolicy: FallbackToLogsOnError           securityContext:             allowPrivilegeEscalation: false             readOnlyRootFilesystem: true             runAsUser: 1000             runAsGroup: 1000             capabilities:               drop:                 - all         - name: backend           image: quay.io/cilium/hubble-ui-backend:v0.13.2           env:             - name: EVENTS_SERVER_PORT               value: "8090"             - name: FLOWS_API_ADDR               value: "hubble-relay.gke-managed-dpv2-observability.svc:443"             - name: TLS_TO_RELAY_ENABLED               value: "true"             - name: TLS_RELAY_SERVER_NAME               value: relay.gke-managed-dpv2-observability.svc.cluster.local             - name: TLS_RELAY_CA_CERT_FILES               value: /var/lib/hubble-ui/certs/hubble-relay-ca.crt             - name: TLS_RELAY_CLIENT_CERT_FILE               value: /var/lib/hubble-ui/certs/client.crt             - name: TLS_RELAY_CLIENT_KEY_FILE               value: /var/lib/hubble-ui/certs/client.key           ports:             - name: grpc               containerPort: 8090           volumeMounts:             - name: hubble-ui-client-certs               mountPath: /var/lib/hubble-ui/certs               readOnly: true           terminationMessagePolicy: FallbackToLogsOnError           securityContext:             allowPrivilegeEscalation: false             readOnlyRootFilesystem: true             runAsUser: 1000             runAsGroup: 1000             capabilities:               drop:                 - all       volumes:         - configMap:             defaultMode: 420             name: hubble-ui-nginx           name: hubble-ui-nginx-conf         - emptyDir: {}           name: tmp-dir         - name: hubble-ui-client-certs           projected:             # note: the leading zero means this number is in octal representation: do not remove it             defaultMode: 0400             sources:               - secret:                   name: hubble-relay-client-certs                   items:                     - key: ca.crt                       path: hubble-relay-ca.crt                     - key: tls.crt                       path: client.crt                     - key: tls.key                       path: client.key --- kind: Service apiVersion: v1 metadata:   name: hubble-ui   namespace: gke-managed-dpv2-observability   labels:     k8s-app: hubble-ui     app.kubernetes.io/name: hubble-ui     app.kubernetes.io/part-of: cilium spec:   type: ClusterIP   selector:     k8s-app: hubble-ui   ports:     - name: http       port: 80       targetPort: 8081 
  4. Appliquez le fichier manifeste hubble-ui-132.yaml :

    kubectl apply -f hubble-ui-132.yaml 
  5. Exposez le service avec le transfert de port :

    kubectl -n gke-managed-dpv2-observability port-forward service/hubble-ui 16100:80 --address='0.0.0.0' 
  6. Accédez à l'interface utilisateur de Hubble dans votre navigateur Web :

    http://localhost:16100/

Étapes suivantes