Is there a way to patch a yaml file with kubectl patch?
So I mean not to patch a already deployed e.g. deployment with a json array but a file:
kubectl patch -f deployment.yaml -p '{"spec":{"containers":[{"name":"test","image":"test"}]}}'
(Code snippet not working)
Or if this is not possible how to best practice manipulate a kubernetes yaml based on a json array?
If you look at the help documents for kubectl
you can see that it is not a supported feature:
$> kubectl patch -h
Update field(s) of a resource using strategic merge patch, a JSON merge patch, or a JSON patch.
Since files on your filesystem are not API resources. I personally believe the method method for manipulating Kubernetes manifests with JSON patches would be Kustomize.
Kustomize is an Overlay Engine. Similar to Helm, it is designed in a way that automates the deployment of software to Kubernetes. They differ, however, in how they do so. Where Helm would manage a list of variable files that are then injected into a template at runtime, Kustomize would instead perform a merge of a patch over a generic example file.
These patches can be defined in a couple ways. One of which is patchesJSON6902
. Here is an example of how one would do so.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With