GKE Dataplane V2 のオブザーバビリティを設定する


このページでは、GKE バージョン 1.28 以降で、Google Kubernetes Engine(GKE)クラスタを GKE Dataplane V2 オブザーバビリティで構成する方法を示します。GKE Dataplane V2 のオブザーバビリティのメリットと要件の詳細については、GKE Dataplane V2 のオブザーバビリティについてをご覧ください。

始める前に

始める前に、次の作業が完了していることを確認してください。

  • Google Kubernetes Engine API を有効にする。
  • Google Kubernetes Engine API を有効化
  • このタスクに Google Cloud CLI を使用する場合は、gcloud CLI をインストールして初期化する。すでに gcloud CLI をインストールしている場合は、gcloud components update を実行して最新のバージョンを取得する。

GKE Dataplane V2 の指標を構成する

指標を収集するには、GKE Dataplane V2 の指標を構成する必要があります。GKE Dataplane V2 の指標は、クラスタの作成時、または GKE Dataplane V2 で実行されているクラスタの更新時に構成できます。gcloud CLI を使用して、GKE Dataplane V2 の指標を有効または無効にできます。

GKE クラスタで GKE Dataplane V2 の指標と Google Cloud Managed Service for Prometheus を有効にすることをおすすめします。両方が有効になると、GKE Dataplane V2 の指標が Google Cloud Managed Service for Prometheus に送信されます。

GKE Dataplane V2 の指標を有効にして Autopilot クラスタを作成する

新しい GKE Autopilot クラスタを作成すると、GKE ではデフォルトで GKE Dataplane V2 の指標がクラスタで有効になります。特定のフラグを指定する必要はありません。

Google Cloud Managed Service for Prometheus で GKE Autopilot クラスタの GKE Dataplane V2 の指標を使用するには、指標をスクレイピングして Google Cloud Managed Service for Prometheus に送信するように ClusterPodMonitoring リソースを構成します。

  1. 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. ClusterPodMonitoring マニフェストを適用します。

    kubectl apply -f ClusterPodMonitoring.yaml
    

GKE Dataplane V2 の指標を有効にして Standard クラスタを作成する

GKE Dataplane V2 の指標を有効にするには、--enable-dataplane-v2-metrics フラグを使用してクラスタを作成します。

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

次のように置き換えます。

  • CLUSTER_NAME: クラスタの名前。

--enable-managed-prometheus フラグは、Google Cloud Managed Service for Prometheus で指標を使用するように GKE に指示します。

既存のクラスタで GKE Dataplane V2 の指標を有効にする

既存のクラスタで GKE Dataplane V2 の指標を有効にするには、次のコマンドを実行します。

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

CLUSTER_NAME は、使用するクラスタの名前に置き換えます。

GKE Dataplane V2 の指標を無効にする

GKE Dataplane V2 の指標を無効にするには:

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

CLUSTER_NAME は、使用するクラスタの名前に置き換えます。

GKE Dataplane V2 オブザーバビリティ ツールを構成する

プライベート エンドポイントを使用して、GKE Dataplane V2 オブザーバビリティのトラブルシューティング ツールにアクセスできます。GKE Dataplane V2 オブザーバビリティ ツールを有効にするには、GKE Dataplane V2 でクラスタが構成されている必要があります。新しいクラスタまたは既存のクラスタで GKE Dataplane V2 オブザーバビリティ ツールを有効にできます。

オブザーバビリティを有効にした Autopilot クラスタを作成する

GKE Dataplane V2 オブザーバビリティを有効にして GKE Autopilot クラスタを作成するには:

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

CLUSTER_NAME は、使用するクラスタの名前に置き換えます。

オブザーバビリティを有効にした Standard クラスタを作成する

GKE Dataplane V2 オブザーバビリティを有効にして GKE Standard クラスタを作成するには:

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

CLUSTER_NAME は、使用するクラスタの名前に置き換えます。

既存のクラスタで GKE Dataplane V2 オブザーバビリティ ツールを有効にする

既存のクラスタで GKE Dataplane V2 オブザーバビリティを有効にするには、次のコマンドを実行します。

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

CLUSTER_NAME は、使用するクラスタの名前に置き換えます。

GKE Dataplane V2 オブザーバビリティ ツールを無効にする

既存のクラスタで GKE Dataplane V2 オブザーバビリティ ツールを無効にするには、次のコマンドを実行します。

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

CLUSTER_NAME は、使用するクラスタの名前に置き換えます。

Hubble CLI の使用方法

GKE Dataplane V2 のオブザーバビリティ機能を有効にした後、クラスタで Hubble CLI ツールを使用します。

  1. hubble-cli バイナリのエイリアスを定義します。

    alias hubble="kubectl exec -it -n gke-managed-dpv2-observability deployment/hubble-relay -c hubble-cli -- hubble"
    
  2. GKE Dataplane V2 のオブザーバビリティ機能を有効にして Hubble のステータスを確認するには、すべての Autopilot クラスタで Hubble CLI を使用します。

    hubble status
    
  3. 現在のトラフィックを表示するには、次のように Hubble CLI を使用します。

    hubble observe
    

Hubble UI バイナリ配布をデプロイする方法

GKE Dataplane V2 オブザーバビリティを有効にすると、オープンソースの Hubble UI をデプロイできます。

  1. GKE クラスタでオブザーバビリティを有効にします。

    1. オブザーバビリティを有効にして GKE クラスタを作成します。

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

      次のように置き換えます。

    2. または、既存のクラスタでオブザーバビリティを有効にします。

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

      次のように置き換えます。

  2. クラスタに接続するように kubectl を構成します。

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

    次のように置き換えます。

  3. Hubble UI をデプロイします。

    # Copyright 2024 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.11.0
              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.11.0
              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. hubble-ui-128.yaml マニフェストを適用します。

    kubectl apply -f hubble-ui-128.yaml
    
  5. ポート転送を使用して Service を公開します。

    kubectl -n gke-managed-dpv2-observability port-forward service/hubble-ui 16100:80 --address='0.0.0.0'
    
  6. ウェブブラウザで Hubble UI にアクセスします。

    http://localhost:16100/

次のステップ