Kubernetes入口Json补丁失败

时间:2020-08-28 10:32:00

标签: kubernetes yaml kustomize

我正在尝试用Kustomize修补Json的入口,但失败了

入口补丁:

- op: replace
  path: /spec/rules/http/paths/path/backend/serviceName
  value: varnish
- op: replace
  path: /spec/rules/http/paths/path/backend/servicePort
  value: 6091

以下是我的ingress.yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: magento-web
  namespace: magento
  annotations:
    kubernetes.io/ingress.class: alb
    alb.ingress.kubernetes.io/certificate-arn: arn:aws:acm:eu-west-2:AccountID:certificate/aaccxsdssa-bbb-434f-b2f9dss-05xxxx51f30
    alb.ingress.kubernetes.io/listen-ports: '[{"HTTP": 80}, {"HTTPS":443}]'
    alb.ingress.kubernetes.io/actions.ssl-redirect: '{"Type": "redirect", "RedirectConfig": {"Protocol": "HTTPS", "Port": "443", "StatusCode": "HTTP_301"}}'
    alb.ingress.kubernetes.io/scheme: internet-facing
  labels:
    app: magento-web
spec:
  rules:
    - host: training-example.cloud
    - http:
        paths:
          - path: /*
            backend:
              serviceName: magento-web
              servicePort: 80

我试图过滤 spec 中的项目,但是我的补丁仍然失败。我认为在这里 / spec / rules / http / paths / path / backend / serviceName

kustomize.yaml

bases:
  - ../step-3
  - ../bases/varnish

patchesJson6902:
- path: patch/ingress.yaml
  target:
    group: networking.k8s.io
    version: v1beta1
    kind: Ingress
    name: main
    namespace: magento

configMapGenerator:
- name: aux
  namespace: magento
  behavior: merge
  env: config/aux.env

1 个答案:

答案 0 :(得分:1)

规则和路径是JSON数组。所以你需要电话号码。我可以推荐您一个像https://jsonpathfinder.com/这样的网站,您可以在其中粘贴json并向下钻取到您的字段。

这应该有效:

- op: replace
  path: /spec/rules/1/http/paths/0/backend/serviceName
  value: varnish
- op: replace
  path: /spec/rules/1/http/paths/0/backend/servicePort
  value: 6091