apiVersion:apps/v1kind:Deployment# or StatefulSetmetadata:name:"SERVICE_NAME"spec:template:spec:containers:-name:"CONTAINER_NAME"volumeMounts:-mountPath:"/etc/ssl/MONITORING_TARGET_NAME-cert"name:"MONITORING_TARGET_NAME-cert"readOnly:truevolumes:-name:"MONITORING_TARGET_NAME-cert"secret:secretName:"MONITORING_TARGET_NAME-cert"[...]
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[],[],null,["# Encrypt metrics from your applications\n\nAll metrics data must be encrypted in transit to ensure security. The monitoring\ncomponent of Google Distributed Cloud (GDC) air-gapped appliance provides in-transit encryption and\nauthentication through mutual Transport Layer Security (mTLS). The mTLS method\nverifies the identity of both parties in a network connection, confirming they\nare who they claim to be.\n\nThis page explains how to set up mTLS for your metrics server.\n\nBefore you begin\n----------------\n\nTo get the permissions that you need to manage `MonitoringTarget` custom\nresources, ask your Organization IAM Admin or Project IAM Admin to grant you one\nof the associated `MonitoringTarget` roles.\n\nDepending on the level of access and permissions you need, you might obtain\ncreator, editor, or viewer roles for this resource in an organization or a\nproject. For more information, see [Prepare IAM permissions](/distributed-cloud/hosted/docs/latest/appliance/platform/pa-user/obs-iam-permissions).\n\nAfter obtaining the necessary permissions, complete these steps before enabling\nmetrics encryption:\n\n1. Deploy your metrics server.\n2. [Collect metrics from your workloads](/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/collect-metrics).\n3. Ensure your `MonitoringTarget` custom resource shows a `Ready` status, like\n in the following example:\n\n apiVersion: monitoring.gdc.goog/v1\n kind: MonitoringTarget\n [...]\n status:\n conditions:\n - lastTransitionTime: \"2023-10-27T15:27:51Z\"\n message: \"\"\n observedGeneration: 1\n reason: Ready\n status: True\n type: Ready\n\n4. [Query and view metrics on dashboards](/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/query-and-view-metrics#query-and-view-metrics-on-dashboards)\n to confirm that your metrics server is sending the expected data.\n\n | **Note:** If metrics are not showing up, resolve any issues with your `MonitoringTarget` configuration before enabling mTLS. Review the [Collect metrics](/distributed-cloud/hosted/docs/latest/appliance/application/ao-user/collect-metrics) documentation to ensure your configuration is correct.\n\nMount the certificate\n---------------------\n\nYour workload needs to use a certificate that is automatically generated when\nyou enable mTLS on the `MonitoringTarget` custom resource. Add a volume and\nvolume mount for this certificate using the following template: \n\n apiVersion: apps/v1\n kind: Deployment # or StatefulSet\n metadata:\n name: \"\u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e\"\n spec:\n template:\n spec:\n containers:\n - name: \"\u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e\"\n volumeMounts:\n - mountPath: \"/etc/ssl/\u003cvar translate=\"no\"\u003eMONITORING_TARGET_NAME\u003c/var\u003e-cert\"\n name: \"\u003cvar translate=\"no\"\u003eMONITORING_TARGET_NAME\u003c/var\u003e-cert\"\n readOnly: true\n volumes:\n - name: \"\u003cvar translate=\"no\"\u003eMONITORING_TARGET_NAME\u003c/var\u003e-cert\"\n secret:\n secretName: \"\u003cvar translate=\"no\"\u003eMONITORING_TARGET_NAME\u003c/var\u003e-cert\"\n [...]\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e: the name of your `Deployment` or `StatefulSet` object.\n- \u003cvar translate=\"no\"\u003eCONTAINER_NAME\u003c/var\u003e: the name of the container where you are adding the volume mount.\n- \u003cvar translate=\"no\"\u003eMONITORING_TARGET_NAME\u003c/var\u003e: the name of your `MonitoringTarget` custom resource. The secret name is based on this name. For example, a `my-mon-target` resource creates a `my-mon-target-cert` secret name.\n\nServe metrics\n-------------\n\nYour metrics server must serve metrics from an mTLS-enabled HTTP server. You\nmight want to encrypt metrics in one of the following two scenarios:\n\n- **For applications you own**: Modify the source code to support mTLS and configure the metrics server with the mTLS certificate.\n- **For applications you don't own** : Consult the application's documentation to enable an HTTPS metrics endpoint. Apply the necessary configuration, like configuring command-line arguments or deploying a `config` file.\n\nEnable mTLS metrics collection\n------------------------------\n\nAdd the following label to the `metadata` section of your `MonitoringTarget`\ncustom resource to enable the collection of encrypted metrics: \n\n monitoring.gdc.goog/enable-mtls: \"true\"\n\nThe custom resource must look like the following example: \n\n apiVersion: monitoring.gdc.goog/v1\n kind: MonitoringTarget\n metadata:\n namespace: my-project-namespace\n name: \"\u003cvar translate=\"no\"\u003eSERVICE_NAME\u003c/var\u003e\"\n labels:\n monitoring.gdc.goog/enable-mtls: \"true\" # Enable mTLS metrics collection\n spec:\n [...]\n\nTo verify that you enabled mTLS authentication, check that your\n`MonitoringTarget` custom resource shows a `Ready` status for the certificate\nand the certificate secret, like in the following example: \n\n apiVersion: monitoring.gdc.goog/v1\n kind: MonitoringTarget\n [...]\n status:\n conditions:\n - lastTransitionTime: \"2023-11-09T11:15:10Z\"\n message: \"admin,user-vm-1,user-vm-2,org-1-system\"\n observedGeneration: 2\n reason: Ready\n status: \"True\"\n type: Ready\n - lastTransitionTime: \"2023-11-09T11:14:43Z\"\n message: \"Certificate is ready\"\n observedGeneration: 2\n reason: Ready\n status: \"True\"\n type: CertificateReady\n - lastTransitionTime: \"2023-11-09T11:15:10Z\"\n message: \"Successfully created secret\"\n observedGeneration: 2\n reason: Ready\n status: \"True\"\n type: CertificateSecretReady\n\n| **Note:** Certificates reside in the org infrastructure cluster. Only certificate *secrets* exist in Kubernetes clusters."]]