<p>I want to reference the label's value in VirtualService's spec section inside k8s yaml file. I use ${metadata.labels[component]} to indicate the positions below. Is there a way to implement my idea?</p>

<pre><code>apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: istio-ingress-version
  namespace: netops
  labels:
    component: version
spec:
  hosts:
  - "service.api.com" 
  gateways:
  - public-inbound-gateway 
  http:
  - match: 
    - uri:
        prefix: /${metadata.labels[component]}/
      headers: 
        referer:
          regex: ^https://[^\s/]*a.api.com[^\s]* 
    rewrite:
      uri: "/"
    route:
    - destination:
        host: ${metadata.labels[component]}.3da.svc.cluster.local  
  - match: 
    - uri:
        prefix: /${metadata.labels[component]}/
      headers: 
        referer:
          regex: ^https://[^\s/]*b.api.com[^\s]* 
    rewrite:
      uri: "/"
    route:
    - destination:
        host: ${metadata.labels[component]}.3db.svc.cluster.local  
  - match: 
    - uri:
        prefix: /${metadata.labels[component]}/
    rewrite:
      uri: "/"
    route:
    - destination:
        host: ${metadata.labels[component]}.3db.svc.cluster.local
</code></pre>

<p>This isn't a capability of Kubernetes itself, however other tools exist that can help you with this scenario.</p>

<p>The main one of these is <a href="https://docs.helm.sh" rel="nofollow noreferrer">Helm</a>. It allows you to create variables that can be shared across several different YAML files, allowing you to share values or even fully parameterise your deployment.</p>
