[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Defining a Canonical Service\n============================\n\n\n**Note:** Canonical Services are supported automatically in Cloud Service Mesh version 1.6.8 and higher.\n\n[Canonical Services](/service-mesh/v1.23/docs/canonical-service) is a group of workloads\nthat implement the same service(s) and API(s). For supported workload types,\nCloud Service Mesh automatically creates Canonical Service resources based on existing\ninformation from the Kubernetes API Server. This page explains what labels\nautomatically define Canonical Services and how you can manually adjust the\nboundaries of your services.\nThe currently supported workload instance types are:\n\n- Kubernetes Pods (including via Kubernetes Deployments, Kube Run Services, etc.)\n- Virtual Machine instances\n- Mesh-external services (specifically, ServiceEntry resources with a location of `MESH_EXTERNAL`)\n\nWhat defines Canonical Services\n-------------------------------\n\nCloud Service Mesh determines the Canonical Service membership by reading the\n`service.istio.io/canonical-name`\n[label](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/)\non the Kubernetes configuration resource associated with each workload instance:\n\n- For Pods, the label is in the Kubernetes Pod resource\n- For VMs, the label in the Istio [WorkloadEntry](https://istio.io/v1.23/docs/reference/config/networking/workload-entry/) resource\n- For external services, the label is in the Istio [ServiceEntry](https://istio.io/v1.23/docs/reference/config/networking/service-entry/) resource\n\nCanonical Services have the same\n[Kubernetes namespace](https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/)\nas their associated workload instances and cannot span namespaces.\n\nAutomatic labeling rules\n------------------------\n\nCloud Service Mesh automatically groups your Pod- and VM-based workloads into\nCanonical Services with no action on your part.\nYou only need to take action to:\n\n- Adjust labels for user/reader clarity\n- Override the default behavior.\n\n### Automatic labeling in Kubernetes Pods\n\nCanonical Services focus around the Kubernetes `app.kubernetes.io/name` and\n`app` labels. Note that the former label takes precedence.\nIf you use either of these two labels on your workloads, no further work is\nrequired.\n\n### Automatic labeling in Virtual Machines\n\nTo build Canonical Services on your VMs, you must add your VMs to a\nservice mesh by configuring a\n[WorkloadEntry resource](https://istio.io/latest/docs/reference/config/networking/workload-entry/)\nin your Kubernetes API server.\n\nManually labeling\n-----------------\n\nTo manually apply or override a Canonical Service label apply the\n`service.istio.io/canonical-name` label to supported workload resource\nconfigurations.\nIn order for an external service to be recognized as a Canonical Service, you\nmust manually label the applicable ServiceEntry.\n\n### Manual labeling in Kubernetes Pods\n\nTo deploy many Pods at once using a\n[Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/),\nset the `service.istio.io/canonical-name` label on the PodTemplateSpec: \n\n apiVersion: apps/v1\n kind: Deployment\n metadata:\n name: my-deployment\n namespace: my-namespace\n spec:\n replicas: 3\n template:\n metadata:\n labels:\n service.istio.io/canonical-name: my-service\n spec:\n containers:\n ...\n\nTo label the Canonical Service of a single Pod, add the\n`service.istio.io/canonical-name` label to the `labels` section of your Pod\nconfiguration: \n\n apiVersion: v1\n kind: Pod\n metadata:\n name: my-test-pod\n namespace: my-namespace\n labels:\n service.istio.io/canonical-name: my-service\n spec:\n ...\n\n### Label virtual machines manually\n\nTo label the Canonical Service of a single VM/WorkloadEntry, add the\n`service.istio.io/canonical-name` label to the \"labels\" section of your\nWorkloadEntry configuration: \n\n apiVersion: networking.istio.io/v1alpha3\n kind: WorkloadEntry\n metadata:\n name: my-vm-123\n namespace: my-namespace\n labels:\n service.istio.io/canonical-name: my-service\n spec:\n ...\n\n### Label external services manually\n\nTo label the Canonical Service of a single external service/ServiceEntry, add the\n`service.istio.io/canonical-name` label to the \"labels\" section of your\nServiceEntry configuration: \n\n apiVersion: networking.istio.io/v1alpha3\n kind: ServiceEntry\n metadata:\n name: example-com\n namespace: my-namespace\n labels:\n service.istio.io/canonical-name: an-external-service\n spec:\n location: MESH_EXTERNAL\n ...\n\nWhat's next\n-----------\n\n- [Learn about Canonical Services](/service-mesh/v1.23/docs/canonical-service)\n- [Learn about best practices in Canonical Services](/service-mesh/v1.23/docs/canonical-service-best-practices)"]]