Find manual changes in ConfigMap when working with "kubectl apply"

Viewed 142

I have a Kubernetes cluster and do all my deployments in a declarative manner, by executing the "apply" command in CI/CD pipeline.

"Apply" works in such a way that it merges the state of an object with the manifest that came with the command. As the result, you may make manual changes - for example, add a new key-value to a ConfigMap and "apply" will leave it intact, even though this key doesn't exist in source code.

So I wonder, how can I detect such issues? Doing "delete" and "create" is not an option since it disrupts the availability. I don't want to change deployment from "apply" since it's production. I just to find manual modifications in a namespace.

2 Answers

kubediff is what you are looking for.

You can run it as a command-line tool e.g.:

$ ./kubediff k8s
Checking ReplicationController 'kubediff'
 *** .spec.template.spec.containers[0].args[0]: '-repo=https://github.com/weaveworks/kubediff' != '-repo=https://github.com/<your github repo>'
Checking Secret 'kubediff-secret'
Checking Service 'kubediff'

or as a service inside K8s cluster. This mode also gives you a simple UI showing the output.

kubectl patch or kubectl replace are suitable for your use case. Take a look to this blog which better explain the difference between them.

If you always want to update configmap to whatever is in your manifest, then go for replace.

Related