4

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"}
Will Beason
  • 3,417
  • 2
  • 28
  • 46
  • Does this answer your question? [Common config across multiple environments and applications with Kustomize](https://stackoverflow.com/questions/65150509/common-config-across-multiple-environments-and-applications-with-kustomize) – Pit Jul 13 '21 at 08:24
  • @Pit No, I am specifically looking for the kubectl command equivalent. – Will Beason Jul 13 '21 at 15:45
  • I am not aware of any other usage of it apart from ```kubectl kustomize DIR with load-restrictor``` flag as seen in the [kubectl's official documentation](https://kubernetes.io/docs/reference/generated/kubectl/kubectl-commands) – Pit Jul 20 '21 at 09:38

1 Answers1

1

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 -
Aditya Vikas Devarapalli
  • 3,186
  • 2
  • 36
  • 54