TIL Kubernetes lets me use JSON Patch to edit obje...
# dev
a
TIL Kubernetes lets me use JSON Patch to edit objects. For instance, I can add a backend service to an ingress named "my-ingress" by saying
Copy code
kubectl patch ingress myingress --type json --patch-file=/tmp/patch.json
where
/tmp/patch.json
is:
Copy code
[
  {
    "op": "add",
    "path": "/spec/rules/-",
    "value": {
      "host": "<http://another.example.com|another.example.com>",
      "http": {
	"paths": [
          {
          "backend": {
            "service": {
              "name": "another-svc",
              "port": {
                "number": 5678
              }
            }
          },
          "path": "/another",
	  "pathType": "Prefix"
        }]
      }
    }
  }
]
A (more) readable introduction to JSON Patch is http://jsonpatch.com/; there's also https://datatracker.ietf.org/doc/html/rfc6902 of course.
👍 1
🆒 3
o
wow didn't know JSON patch was a thing
a
I hope it goes without saying that one must never confuse JSON Patch with JSON Merge Patch https://datatracker.ietf.org/doc/html/rfc7386. K8s supports both.