I'm trying to patch ingress when I specify json like below, I'm able to (all below commands have --dry-run enabled, I know):
kubectl patch ing ing-routing '--type=json' '--patch=[{"op": "add","path": "/spec/rules/0/http/paths/-","value": {"path": "/path/to/patch/service", "backend": {"serviceName": "patch-svc-cip","servicePort": 8443}}}]' --dry-run -o yaml -n namespace
But if I try to do it like:
value="$(</tmp/ingress-route-patch.json)"
kubectl patch ing ing-routing '--type=json' '--patch=$value' --dry-run -o yaml -n namespace
I get this error: error: json: cannot unmarshal string into Go value of type jsonpatch.Patch
I have also tried
ingressRoute=$(cat /tmp/ingress-routing-patch.json)
kubectl patch ing ing-routing '--type=json' '--patch=$ingressRoute' --dry-run -o yaml -n namespace
&
kubectl patch ing ing-routing '--type=json' '--patch=$(cat /tmp/ingress-routing-patch.json)' --dry-run -o yaml -n namespace
&
kubectl patch ing ing-routing --type='json' -p='$(cat /tmp/ingress-routing-patch.json)' --dry-run -o yaml -n namespace
but same error came everytime. I need to patch it from a file since we need to add endpoints dynamically.
You should use "
in -p
flag instead of '
.
Following works for me
kubectl patch ing ing-routine --type='json' -p="$(cat /tmp/ingress-routing-patch.json)" --dry-run -o yaml