GKE Inference Gateway

このドキュメントでは、Google Cloud Managed Service for Prometheus を使用して GKE Inference Gateway から指標を収集できるように、Google Kubernetes Engine の Deployment を構成する方法について説明します。このドキュメントでは、次の方法について説明します。

  • GKE Inference Gateway を設定して指標を報告する。
  • エクスポートされた指標を収集するために、Managed Service for Prometheus の ClusterPodMonitoring リソースを構成する。
  • Cloud Monitoring のダッシュボードにアクセスして指標を表示する。

以下の手順は、Managed Service for Prometheus でマネージド コレクションを使用している場合にのみ適用されます。セルフデプロイ コレクションを使用している場合は、GKE Inference Gateway のドキュメントでインストール情報をご覧ください。

以下の手順は一例であり、ほとんどの Kubernetes 環境で機能します。セキュリティ ポリシーや組織のポリシーの制限により、アプリケーションやエクスポータのインストールに問題がある場合は、オープンソース ドキュメントでサポート情報を確認することをおすすめします。

GKE Inference Gateway の詳細については、GKE Inference Gateway をご覧ください。

前提条件

Managed Service for Prometheus とマネージド コレクションを使用して GKE Inference Gateway エクスポータから指標を収集するには、Deployment が次の要件を満たしている必要があります。

  • クラスタで Google Kubernetes Engine バージョン 1.28.15-gke.2475000 以降を実行している必要があります。
  • マネージド コレクションを有効にして、Managed Service for Prometheus を実行する必要があります。詳細については、マネージド コレクションを使ってみるをご覧ください。

GKE Inference Gateway エクスポータは、Prometheus 形式の指標を自動的に公開します。別途インストールする必要はありません。

GKE Inference Gateway エクスポータが想定されるエンドポイントで指標を出力していることを確認するには、次の操作を行います。

  1. Secret、ServiceAccount、ClusterRole、ClusterBinding を追加します。GKE Inference Gateway エクスポータのオブザーバビリティ エンドポイントは、認証トークンによって保護されています。認証情報を取得するために、クライアントには、接続された ClusterRole を持つサービス アカウントにマッピングする Secret が必要です(nonResourceURLs: "/metrics", verbs: get ルールの場合)。詳細については、サービス アカウントの Secret を作成するをご覧ください。

  2. 次のコマンドを使用してポート転送を設定します。

    kubectl -n NAMESPACE_NAME port-forward POD_NAME 9090
    
  3. 別のウィンドウで、次の操作を行います。

    1. 次のコマンドを実行してトークンを取得します。

      TOKEN=$(kubectl -n default get secret inference-gateway-sa-metrics-reader-secret  -o jsonpath='{.secrets[0].name}' -o jsonpath='{.data.token}' | base64 --decode)
      
    2. curl ユーティリティを使用して、エンドポイント localhost:9090/metrics にアクセスします。

      curl -H "Authorization: Bearer $TOKEN" localhost:9090/metrics
      

サービス アカウントの Secret を作成する

保護された GKE Inference Gateway エクスポータ エンドポイントの場合、Managed Service for Prometheus Operator には、gmp-system Namespace での指標の収集を承認するための Secret が必要です。

クラスタで Autopilot モードを使用している場合は、gmp-systemgke-gmp-system に置き換えます。

次の Secret、ServiceAccount、ClusterRole、ClusterRoleBinding の構成を使用できます。

# 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: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: inference-gateway-metrics-reader
rules:
- nonResourceURLs:
  - /metrics
  verbs:
  - get
---
apiVersion: v1
kind: ServiceAccount
metadata:
  name: inference-gateway-sa-metrics-reader
  namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: inference-gateway-sa-metrics-reader-role-binding
  namespace: default
subjects:
- kind: ServiceAccount
  name: inference-gateway-sa-metrics-reader
  namespace: default
roleRef:
  kind: ClusterRole
  name: inference-gateway-metrics-reader
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: Secret
metadata:
  name: inference-gateway-sa-metrics-reader-secret
  namespace: default
  annotations:
    kubernetes.io/service-account.name: inference-gateway-sa-metrics-reader
type: kubernetes.io/service-account-token
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: inference-gateway-sa-metrics-reader-secret-read
rules:
- resources:
  - secrets
  apiGroups: [""]
  verbs: ["get", "list", "watch"]
  resourceNames: ["inference-gateway-sa-metrics-reader-secret"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: gmp-system:collector:inference-gateway-sa-metrics-reader-secret-read
  namespace: default
roleRef:
  name: inference-gateway-sa-metrics-reader-secret-read
  kind: ClusterRole
  apiGroup: rbac.authorization.k8s.io
subjects:
- name: collector
  namespace: gmp-system
  kind: ServiceAccount

詳細については、エクスポータの指標とオブザーバビリティ ガイドをご覧ください。

構成の変更をローカル ファイルから適用するには、次のコマンドを実行します。

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Terraform を使用して構成を管理することもできます。

ClusterPodMonitoring リソースを定義する

ターゲット検出を行うために、Managed Service for Prometheus Operator には、同じ Namespace 内の GKE Inference Gateway エクスポータに対応する ClusterPodMonitoring リソースが必要です。

次の ClusterPodMonitoring 構成を使用できます。

# 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: monitoring.googleapis.com/v1
kind: ClusterPodMonitoring
metadata:
  name: inference-optimized-gateway-monitoring
  labels:
    app.kubernetes.io/name: inference-optimized-gateway
    app.kubernetes.io/part-of: google-cloud-managed-prometheus
spec:
  endpoints:
  - port: metrics
    scheme: http
    interval: 5s
    path: /metrics
    authorization:
      type: Bearer
      credentials:
        secret:
          name: inference-gateway-sa-metrics-reader-secret
          key: token
          namespace: default
  selector:
    matchLabels:
      app: inference-gateway-ext-proc

GKE Inference Gateway は、別の Namespace から Secret にアクセスする必要があるため、PodMonitoring リソースではなく ClusterPodMonitoring リソースを使用します。

ClusterPodMonitoring 構成の matchLabels セレクタで、inference-gateway-ext-procapp の値を GKE Inference Gateway Deployment のラベルに置き換えることができます。

構成の変更をローカル ファイルから適用するには、次のコマンドを実行します。

kubectl apply -n NAMESPACE_NAME -f FILE_NAME

Terraform を使用して構成を管理することもできます。

構成を確認する

Metrics Explorer を使用すると、GKE Inference Gateway エクスポータが正しく構成されていることを確認できます。Cloud Monitoring が指標を取り込むまでに 1~2 分かかる場合があります。

指標が取り込まれていることを確認します。

  1. Google Cloud コンソールで Metrics explorer のページに移動します。

    [Metrics Explorer] に移動

    検索バーを使用してこのページを検索する場合は、小見出しが [Monitoring] の結果を選択します。

  2. クエリビルダー ペインのツールバーで、[MQL] または [PROMQL] という名前のボタンを選択します。
  3. [言語] で [PromQL] が選択されていることを確認します。言語切り替えボタンは、クエリの書式設定と同じツールバーにあります。
  4. 次のクエリを入力して実行します。
    inference_model_request_total{cluster="CLUSTER_NAME", namespace="NAMESPACE_NAME"}

ダッシュボードを表示する

Cloud Monitoring インテグレーションには、[GKE Inference Gateway Prometheus Overview] ダッシュボードが含まれています。ダッシュボードは、インテグレーションを構成すると自動的にインストールされます。インテグレーションをインストールすることなく、ダッシュボードの静的プレビューを表示することもできます。

インストールされているダッシュボードを表示する手順は次のとおりです。

  1. Google Cloud コンソールで [ダッシュボード] ページに移動します。

    [ダッシュボード] に移動

    検索バーを使用してこのページを検索する場合は、小見出しが [Monitoring] の結果を選択します。

  2. [ダッシュボード リスト] タブを選択します。
  3. [統合] カテゴリを選択します。
  4. ダッシュボードの名前(GKE Inference Gateway Prometheus Overview など)をクリックします。

ダッシュボードの静的プレビューを表示する手順は次のとおりです。

  1. Google Cloud コンソールで [インテグレーション] ページに移動します。

    [インテグレーション] に移動

    検索バーを使用してこのページを検索する場合は、小見出しが [Monitoring] の結果を選択します。

  2. [デプロイメント プラットフォーム] フィルタの [Kubernetes Engine] をクリックします。
  3. GKE Inference Gateway インテグレーションを見つけ、[詳細を表示] をクリックします。
  4. [ダッシュボード] タブを選択します。

トラブルシューティング

指標の取り込みに関する問題のトラブルシューティングについては、取り込み側の問題のトラブルシューティングエクスポータからの収集に関する問題をご覧ください。