- Kubernetesオペレータ・ユーザーズ・ガイド
- TimesTen Kubernetesオペレータからのメトリックの公開
- TimesTen Kubernetesオペレータ・メトリックの公開方法のデモンストレーション
TimesTen Kubernetesオペレータ・メトリックの公開方法のデモンストレーション
TimesTen Kubernetesオペレータが、独自の機能に関するメトリックおよびTimesTenClassicまたはTimesTenScaleoutオブジェクトのステータスを公開する方法を示す例を順を追って説明します。PrometheusがKubernetesクラスタにインストールされており、ネームスペースでPrometheusサーバーが実行されているとします。
-
httpsとhttpのどちらか: httpsを選択します。
METRICS_SCHEME
環境変数は、メトリックをhttpsとhttpのどちらで使用可能にするかを決定します。"1"
(デフォルト)に設定すると、httpsです。 -
ServiceMonitorオブジェクトを作成するか: TimesTenオペレータでServiceMonitorオブジェクトを作成します。このオブジェクトには、PrometheusがTimesTenオペレータをスクレイプ・ターゲットとして構成するために必要な情報が含まれています。
CREATE_SERVICEMONITOR
環境変数は、TimesTenオペレータがServiceMonitorオブジェクトを作成するかどうかを決定します。"1"
(デフォルト)に設定すると、TimesTenオペレータがオブジェクトを作成します。 -
TimesTenオペレータ・ポッドの外部でTimesTenオペレータ・メトリックを公開するか: TimesTenオペレータ・ポッドの外部でメトリックを公開し、Prometheusがそこからメトリックをスクレイプできるようにします。
EXPOSE_METRICS
環境変数は、メトリックがTimesTenオペレータ・ポッドの外部で公開されるかどうかを決定します。"1"
(デフォルト)に設定すると、メトリックを公開する必要があります。つまり、TimesTenオペレータは、Kubernetesクラスタ内の他のポッドで/metrics
エンドポイントを使用できるようにするKubernetesサービス(timesten-operator
)を作成します。
TimesTen Operator環境変数に対してデフォルト設定を選択したため、operator.YAML
YAMLマニフェスト・ファイルでこれらの変数を変更する必要はありません。
- 「TimesTenオペレータの概要」のステップに従って、TimesTenオペレータを起動します。
- (オプション)ネームスペースで実行されているTimesTenオペレータ・デプロイメントを確認します。
出力。kubectl describe deployment timesten-operator
Name: timesten-operator Namespace: mynamespace CreationTimestamp: Wed, 24 Jan 2024 20:48:48 +0000 Labels: <none> Annotations: deployment.kubernetes.io/revision: 1 Selector: name=timesten-operator Replicas: 1 desired | 1 updated | 1 total | 1 available | 0 unavailable StrategyType: RollingUpdate MinReadySeconds: 0 RollingUpdateStrategy: 25% max unavailable, 25% max surge Pod Template: Labels: name=timesten-operator Service Account: timesten-operator Containers: timesten-operator: Image: container-registry.oracle.com/timesten/timesten:22.1.1.27.0 Ports: 8081/TCP, 8080/TCP Host Ports: 0/TCP, 0/TCP Command: /timesten/operator/operator/timesten-operator Liveness: http-get http://:probes/healthz delay=10s timeout=10s period=30s #success=1 #failure=3 Readiness: http-get http://:probes/healthz delay=10s timeout=10s period=10s #success=1 #failure=1 Environment: WATCH_NAMESPACE: (v1:metadata.namespace) POD_NAME: (v1:metadata.name) OPERATOR_NAME: timesten-operator EXPOSE_METRICS: 1 METRICS_SCHEME: https EXPOSE_PROBES: 1 CREATE_SERVICEMONITOR: 1 Mounts: <none> Volumes: <none> Conditions: Type Status Reason ---- ------ ------ Available True MinimumReplicasAvailable Progressing True NewReplicaSetAvailable OldReplicaSets: <none> NewReplicaSet: timesten-operator-7f77c749fd (1/1 replicas created) Events: Type Reason Age From Message ---- ------ ---- ---- ------- Normal ScalingReplicaSet 73s deployment-controller Scaled up replica set timesten-operator-7f77c749fd to 1
EXPOSE_METRICS
およびCREATE_SERVICEMONITOR
TimesTenオペレータの環境変数は1
(デフォルト)に設定されており、METRICS_SCHEME
はhttps
(デフォルト)に設定されています。 - TimesTenオペレータが適切なKubernetes Secretを作成したことを確認します。
kubectl get secrets
出力:
NAME TYPE DATA AGE ... timesten-operator-metrics Opaque 1 11m timesten-operator-metrics-client Opaque 3 11m
TimesTenオペレータは、
timesten-operator-metrics
Kubernetes Secretを作成しました。このシークレットには、https/TLS用としてTimesTenオペレータに必要な証明書が含まれます。このシークレットは、TimesTenオペレータによって内部的に使用されます。TimesTenオペレータは、
timesten-operator-metrics
Kubernetes Secretも作成しました。このシークレットには、PrometheusサーバーがTimesTenオペレータ・ポッドからメトリックをスクレイプするために必要なファイルが含まれます。 - 適切なファイルが
timesten-operator-metrics-client
Kubernetes Secretにあることを確認します。kubectl describe secret timesten-operator-metrics-client
出力:
Name: timesten-operator-metrics-client Namespace: mynamespace Labels: <none> Annotations: <none> Type: Opaque Data ==== ca.crt: 1465 bytes client.crt: 1277 bytes client.key: 1675 bytes
シークレットには、次のファイルが含まれます。-
ca.crt
: TimesTenオペレータによって使用される自己署名証明書を認証するためにクライアントが必要とする認証局ファイル。 -
client.crt
: メトリックをスクレイプしようとしているクライアントを認証するためにTimesTenオペレータが使用するクライアント証明書。 -
client.key
: client.crtファイルに関連付けられた秘密キー。
-
- TimesTenオペレータによって
timesten-operator
ServiceMonitorオブジェクトが作成されたことを確認します。kubectl describe servicemonitor timesten-operator
出力:
Name: timesten-operator Namespace: mynamespace Labels: app=timesten-operator database.timesten.oracle.com=timesten-operator Annotations: deployment.kubernetes.io/revision: 1 API Version: monitoring.coreos.com/v1 Kind: ServiceMonitor Metadata: Creation Timestamp: 2024-03-24T20:49:33Z Generation: 1 Owner References: API Version: apps/v1 Block Owner Deletion: true Controller: true Kind: Deployment Name: timesten-operator UID: 3084af2d-90ca-49d1-874a-cde1174f50b5 Resource Version: 282625424 UID: 6337b813-9d62-43b0-8594-60e387e7a30d Spec: Endpoints: Bearer Token Secret: Key: Interval: 15s Path: /metrics Port: metrics Scheme: https Tls Config: Ca: Secret: Key: ca.crt Name: timesten-operator-metrics-client Cert: Secret: Key: client.crt Name: timesten-operator-metrics-client Key Secret: Key: client.key Name: timesten-operator-metrics-client Server Name: timesten-operator.mynamespace.svc.cluster.local Namespace Selector: Selector: Match Labels: App: timesten-operator Events: <none>
このServiceMonitorオブジェクトの重要な情報を見てみましょう。-
app=timesten-operator
ラベルがあります。app=timesten-operator
に一致するラベルの付いたポッドがある場合、Prometheusはそこからメトリックをスクレイプします。TimesTenオペレータ・ポッドには、app=timesten-operator
ラベルが含まれます。したがって、Prometheusはそこからメトリックをスクレイプします。後で説明します。 - Prometheusは、
/metrics
エンドポイントからメトリックをスクレイプします。 - メトリックは、httpsを使用して公開されます。
- TimesTenオペレータは、
timesten-operator-metrics
およびtimesten-operator-metrics-client
Kubernetes SecretをServiceMonitorオブジェクトに配置しました。これらのシークレットはPrometheusオペレータによって使用されます。
Prometheusオペレータは、このServiceMonitorオブジェクトの情報に基づいてPrometheusサーバー構成ファイルを編集します。
-
- TimesTenオペレータが適切なKubernetesサービスを作成したことを確認します。
kubectl describe service timesten-operator
出力:
Name: timesten-operator Namespace: mynamespace Labels: app=timesten-operator database.timesten.oracle.com=timesten-operator Annotations: deployment.kubernetes.io/revision: 1 Selector: name=timesten-operator Type: ClusterIP IP Family Policy: SingleStack IP Families: IPv4 IP: 10.96.169.59 IPs: 10.96.169.59 Port: metrics 8080/TCP TargetPort: 8080/TCP Endpoints: 10.244.8.180:8080 Port: probe 8081/TCP TargetPort: 8081/TCP Endpoints: 10.244.8.180:8081 Session Affinity: None Events: <none>
- ネームスペースでPrometheusサーバーが実行されていることを確認します。
kubectl get pods
出力。
NAME READY STATUS RESTARTS AGE prometheus-sampleprometheusserver-0 2/2 Running 0 10d ...
prometheus-sampleprometheusserver-0
Prometheusサーバーがネームスペースで実行されています。 - Prometheusオペレータが
timesten-operator
ServiceMonitorオブジェクトの情報に基づいてPrometheusサーバー構成ファイルを編集したことを確認します。kubectl exec prometheus-sampleprometheusserver-0 -c prometheus -- cat /etc/prometheus/config_out/prometheus.env.yaml
出力。
global: evaluation_interval: 30s scrape_interval: 30s external_labels: prometheus: mynamespace/sampleprometheusserver prometheus_replica: prometheus-sampleprometheusserver-0 scrape_configs: - job_name: serviceMonitor/mynamespace/timesten-operator/0 honor_labels: false kubernetes_sd_configs: - role: endpoints namespaces: names: - mynamespace scrape_interval: 15s metrics_path: /metrics scheme: https tls_config: insecure_skip_verify: false ca_file: /etc/prometheus/certs/secret_mynamespace_timesten-operator-metrics-client_ca.crt cert_file: /etc/prometheus/certs/secret_mynamespace_timesten-operator-metrics-client_client.crt key_file: /etc/prometheus/certs/secret_mynamespace_timesten-operator-metrics-client_client.key server_name: timesten-operator.mynamespace.svc.cluster.local relabel_configs: - source_labels: - job target_label: __tmp_prometheus_job_name - action: keep source_labels: - __meta_kubernetes_service_label_app - __meta_kubernetes_service_labelpresent_app regex: (timesten-operator);true - action: keep source_labels: - __meta_kubernetes_endpoint_port_name regex: metrics - source_labels: - __meta_kubernetes_endpoint_address_target_kind - __meta_kubernetes_endpoint_address_target_name separator: ; regex: Node;(.*) replacement: ${1} target_label: node - source_labels: - __meta_kubernetes_endpoint_address_target_kind - __meta_kubernetes_endpoint_address_target_name separator: ; regex: Pod;(.*) replacement: ${1} target_label: pod - source_labels: - __meta_kubernetes_namespace target_label: namespace - source_labels: - __meta_kubernetes_service_name target_label: service - source_labels: - __meta_kubernetes_pod_name target_label: pod - source_labels: - __meta_kubernetes_pod_container_name target_label: container - action: drop source_labels: - __meta_kubernetes_pod_phase regex: (Failed|Succeeded) - source_labels: - __meta_kubernetes_service_name target_label: job replacement: ${1} - target_label: endpoint replacement: metrics - source_labels: - __address__ target_label: __tmp_hash modulus: 1 action: hashmod - source_labels: - __tmp_hash regex: 0 action: keep metric_relabel_configs: []
Prometheusには、TimesTenオペレータ・メトリックをスクレイプするために必要な情報があります。
- TimesTenClassicオブジェクトを確認してデプロイします。
確認。
cat sample.yaml
出力。
apiVersion: timesten.oracle.com/v2 kind: TimesTenClassic metadata: name: sample spec: ttspec: storageClassName: oci storageSize: 250G image: container-registry.oracle.com/timesten/timesten:22.1.1.27.0 imagePullSecret: sekret
デプロイ:
kubectl create -f sample.yaml
出力:
timestenclassic.timesten.oracle.com/sample created
- 数分待ってから、
sample
TimesTenClassicオブジェクトがNormal
状態であることを確認します。kubectl get ttc sample
出力:
NAME STATE ACTIVE AGE sample Normal sample-0 2m37s
- TimesTen演算子のメトリックの一部を確認します。ブラウザで、Prometheusサーバーに移動します。
- Prometheusサーバー検索バーに、TimesTenオペレータ・メトリックを入力します。たとえば、timesten_classic_state_normalです。次に、「Execute」をクリックします。
出力。
timesten_classic_state_normal{container="timesten-operator", endpoint="metrics", instance="10.244.8.180:8080", job="timesten-operator", name="sample", namespace="mynamespace", pod="timesten-operator-7f77c749fd-2lt5x", service="timesten-operator"} 1
1つのTimesTenClassicオブジェクト(
sample
)があり、これはNormal
状態です。 - Prometheusサーバー検索バーに、2番目のTimesTenオペレータ・メトリックを入力します。たとえば、timesten_classic_state_not_normalです。次に、「Execute」をクリックします。
出力。
timesten_classic_state_not_normal{container="timesten-operator", endpoint="metrics", instance="10.244.8.180:8080", job="timesten-operator", name="sample", namespace="mynamespace", pod="timesten-operator-7f77c749fd-2lt5x", service="timesten-operator"} 0
1つのTimesTenClassicオブジェクト(
sample
)があり、これはNormal
またはInitializing
状態です。0
の値は、他の状態ではないことを示します。 - Prometheusサーバー検索バーに、3番目のTimesTenオペレータ・メトリックを入力します。たとえば、timesten_classic_stateです。次に、「Execute」をクリックします。
出力。
timesten_classic_state{container="timesten-operator", endpoint="metrics", instance="10.244.8.180:8080", job="timesten-operator", name="sample", namespace="mynamespace", pod="timesten-operator-7f77c749fd-2lt5x", service="timesten-operator", state="Initializing"} 0
timesten_classic_state{container="timesten-operator", endpoint="metrics", instance="10.244.8.180:8080", job="timesten-operator", name="sample", namespace="mynamespace", pod="timesten-operator-7f77c749fd-2lt5x", service="timesten-operator", state="Normal"} 1
sample
TimesTenClassicオブジェクトはInitializing
状態ではなくなりました。現在はNormal
状態です。
- Prometheusサーバー検索バーに、TimesTenオペレータ・メトリックを入力します。たとえば、timesten_classic_state_normalです。次に、「Execute」をクリックします。
おめでとうございます。これで、TimesTenオペレータ・メトリックの公開、スクレイプおよび公開方法を示す例の説明は終わりです。