我想在k8s yaml文件中VirtualService的spec部分中引用标签的值。我使用$ {metadata.labels [component]}表示以下位置。有没有办法实现我的想法?
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
最佳答案
这不是Kubernetes本身的功能,但是存在其他工具可以帮助您解决这种情况。
其中主要的一种是Helm。它允许您创建可以在几个不同的YAML文件之间共享的变量,从而可以共享值,甚至可以完全参数化部署。