How to set load restrictor when using kustomize from kubectl?

Viewed 1537

I am trying to use kustomize from within kubectl. Specifically, I want to know the equivalent kubectl command for:

kustomize build --load_restrictor LoadRestrictionsNone config/overlays/dev_mutation | kubectl apply -f -

(kustomize properly runs this command and does what I expect)

I've tried this command:

$ kubectl apply -k config/overlays/dev_mutation --load_restrictor="LoadRestrictionsNone"

which complains that load_restrictor is deprecated and I should use load-restrictor instead.

W0712 07:58:16.811301 2407909 flags.go:39] load_restrictor is DEPRECATED and will be removed in a future version. Use load-restrictor instead.
Error: unknown flag: --load_restrictor

So, I tried replacing with the non-deprecated flag:

kubectl apply -k config/overlays/dev_mutation --load-restrictor="LoadRestrictionsNone"

If I do this, kubectl complains that --load-restrictor is unknown:

Error: unknown flag: --load-restrictor

How do I properly pass the load_restrictor/load-restrictor flag to kubectl apply -k?

Output of kubectl version:

gatekeeper$ kubectl version
Client Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.2", GitCommit:"092fbfbf53427de67cac1e9fa54aaa09a28371d7", GitTreeState:"clean", BuildDate:"2021-06-16T12:59:11Z", GoVersion:"go1.16.5", Compiler:"gc", Platform:"linux/amd64"}
1 Answers

I suggest installing the kustomize binary directly, instead of relying on the bundled version in kubectl which would be outdated. More info here: Install Kustomize

I do not think you can pass the --load-restrictor option to kubectl apply -k command. Instead, I can confirm that this works

kubectl kustomize --load-restrictor LoadRestrictionsNone <path_to_kustomization_dir>

You can use kustomize binary to achieve the same using

kustomize build --load-restrictor LoadRestrictionsNone <path_to_kustomization_dir>

Applying generated yaml

If you want to apply the generated output using kubectl, you can pipe this output like so

kubectl kustomize --load-restrictor LoadRestrictionsNone <path_to_kustomization_dir> | kubectl apply -f -

or

kustomize build --load-restrictor LoadRestrictionsNone <path_to_kustomization_dir> | kubectl apply -f -
Related