diff between whats active on cluster versus kustomize

2/4/2020

kustomize's docs provides a nice one-liner that compares two different overlays...

diff \
  <(kustomize build $OVERLAYS/staging) \
  <(kustomize build $OVERLAYS/production)

is there a way to do the same but against what is running within a specific kubernetes namespace and that of a defined overlay on disk?

more specifically, knowing what an kubectl apply -k . would do without actually doing it? using --dry-run just says spits out a list of the objects rather than a real diff.

-- yee379
diff
kubernetes
kustomize
yaml

2 Answers

2/28/2020

Try this kustomize command, currently in alpha:

KUSTOMIZE_ENABLE_ALPHA_COMMANDS=true kustomize resources diff -k your/kustomize/overlay

via https://kubernetes.slack.com/archives/C9A5ALABG/p1582738327027200?thread_ts=1582695987.023600&cid=C9A5ALABG

-- Julian V. Modesto
Source: StackOverflow

2/4/2020

I'm not sure if this is what you are looking for, but in Kubernetes you have kubectl diff.

It's nicely explained on APIServer dry-run and kubectl diff.

You can use option -k, --kustomize which does:

Process the kustomization directory. This flag can't be used together with -f or -R.

Or maybe something similar to one-liner to set context for specific namespace:

$ kubectl config set-context staging --user=cluster-admin --namespace=staging
$ kubectl config set-context prod --user=cluster-admin --namespace=prod

Once you have context setup you could use them maybe in a following way:

kubectl config use-context staging; cat patched_k8s.yaml | kubectl config use-context prod; kubectl diff -f -

This is just an example which I did not tested.

-- Crou
Source: StackOverflow