如示例所示,https://kubectl.docs.kubernetes.io/references/kustomize/kustomization/replacements/
可以针对特定的数组项,如spec.template.spec.containers.[name=hello].env.[name=SECRET_TOKEN].value。
但是我们如何针对每个数组项呢?
尝试了如下所示的-,但它只替换了最后一个事件。
fieldPaths:
- spec.http.-.route.0.destination.host这是我的kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: ef
images:
- name: gateway-image
resources:
- configmap.yaml
- virtual-services.yaml
replacements:
- source:
kind: ConfigMap
fieldPath: data.HOST
targets:
- select:
kind: VirtualService
fieldPaths:
- spec.http.-.route.0.destination.host
options:
create: true这里是我的目标yaml服务-entries.yaml-我希望主机在两个地方都会被替换。
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: v-rules-1
spec:
hosts:
- EXTERNAL-HOST
gateways:
- istio-system/default-gateway
- mesh
http: # note these are ordered - first rule matching wins
- match:
- uri:
prefix: /foo
route:
- destination:
host: PLACEHOLDER1
- match:
- uri:
prefix: /bar
route:
- destination:
host: PLACEHOLDER2但正如您在下面看到的,结果只有最后一个值:-
kustomize build .产生这个。如您所见,example.com仅在最后一个条目中正确显示- PLACEHOLDE1未受影响:-
apiVersion: v1
data:
HOST: example.com
kind: ConfigMap
metadata:
name: gateway-configmap
namespace: ef
---
apiVersion: networking.istio.io/v1beta1
kind: VirtualService
metadata:
name: v-rules-1
namespace: ef
spec:
gateways:
- istio-system/default-gateway
- mesh
hosts:
- EXTERNAL-HOST
http:
- match:
- uri:
prefix: /foo
route:
- destination:
host: PLACEHOLDER1
- match:
- uri:
prefix: /bar
route:
- destination:
host: example.com因此,问题是我们如何替换每个数组元素?fieldPath的语法是什么?
编辑版为4.2.0
发布于 2021-11-03 00:38:11
答案是你做不到,然而,作者似乎已经打开了一个特性请求,以便能够这样做。
https://stackoverflow.com/questions/68322864
复制相似问题