Dynamically adding/removing named hosts from k8s ingress

前端 未结 2 983
春和景丽
春和景丽 2021-01-21 01:07

I\'m setting up a k8s cluster on GKE. A wildcard DNS *.server.com will point to a Ingress controller. Internally to the cluster, there will be webserver pods, eac

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-21 01:49

    I found a solution to add a rule to an ingress by executing the following patch:

    [
      {
        "op": "add",
        "path": "/spec/rules/-",
        "value": {
          "host": "",
          "http": {
            "paths": [
              {
                "path": "/*",
                "backend": {
                  "serviceName": "",
                  "servicePort": 
                }
              }
            ]
          }
        }
      }
    ]
    
    kubectl patch ingress ${INGRESS_NAME} --type json -p "$(cat patch.json)"
    

    But I cant find the solution to remove it. What I tried is the follwoing patch;

    [
      {
        "op": "remove",
        "path": '{.spec.rules[?(@.host=="")]}'
      }
    ]
    
    

    But I just get the error 'The "" is invalid' back from kubectl

    Whats wrong with it? I followed the jsonPath syntax from https://kubernetes.io/docs/reference/kubectl/jsonpath/

提交回复
热议问题