6

I am using k8s kustomize to set the image and create a secret file

$(cd ./k8s/overlays/prod && kustomize edit set image gcr.io/PROJECT_ID/image:1.0)

and this works!

Now I am trying to use the kubectl kustomize to do the same without doing the cd . ./k8s/overlays/prod

Is it possible with the Kustomize plugin build into kubectl?

also same for the kustomize edit add secret with kubectl without doing the cd into directory?

Arian
  • 465
  • 1
  • 7
  • 18

2 Answers2

4

Unfortunately this is not possible. The kubectl's built-in kustomize command only supports patching and applying kustomize files.

I recommend using the standalone version of the kustomize since kubectl uses kustomize version 2.0.4, while the newest is already 3.8.8. Using the older version will break some of the functionalities.

There are many requests to support newer version inside kubectl but there are some technical reasons which hold this from being done. You can track the progress here.

acid_fuji
  • 6,287
  • 7
  • 22
2

An newer kustomize shipped in kubectl v1.21, which finally unblocks newer kustomize which unblocks OP scenario (per @acid_fuji answer).

kubectl kustomize
v1.21 v4.0.5 bogus column to make versions easier to read
v1.20 v2.0.3
yzorg
  • 4,224
  • 3
  • 39
  • 57
  • 1
    If you're reading this please consider upvoting feature for kubectl to display what version of kustomize it has bundled: https://github.com/kubernetes-sigs/kustomize/issues/1424 . – yzorg Apr 26 '21 at 20:57
  • list of issues that blocked adoption of new versions before v1.21: https://github.com/kubernetes-sigs/kustomize/issues/1500#issuecomment-768454468 – yzorg Apr 26 '21 at 20:59
  • v1.22 has already been updated to kustomize 4.1.2 but it will be a while before 1.22 ships, 1.21 just shipped, so 5 months. kustomize could be updated again before 1.22 ships. – yzorg Apr 26 '21 at 21:00
  • Warning: kubectl readme in github still has outdated info on which version of kustomize is bundled. – yzorg Apr 26 '21 at 21:03
  • Warning: kubectl officially only supports 1 minor version back from your k8s api server. So if your cluster is running 1.18 or 1.19 beware you're out of support if using new v1.21 kubectl with it. – yzorg Apr 26 '21 at 21:08
  • This answer has the substance of a comment. Please revise it to answer the question. – Aleksandr Dubinsky Sep 04 '21 at 09:01
  • @AleksandrDubinsky I couldn't format it as a table. Would be hard to read multiple version numbers in a comment. The previous answer answered the why the OP was blocked, and I posted the version in which the OP scenario is unblocked. – yzorg Sep 08 '21 at 13:53
  • That's not how answers on SO work. You can't post additional information and assume that everyone's read the answer that you're replying to. Simply include the useful information from the other answer, so that your post is a stand-alone answer. – Aleksandr Dubinsky Sep 09 '21 at 07:12
  • 1
    @AleksandrDubinsky Thank you, but k8s is a complex system with a complex tool chain. Those of us trying to use it could use all the help we can get. This table shows a huge jump in kustomize version numbers from v1.21 point release of k8s, that would be very hard to convey in a comment. I'm not going to list or demo features of kustomize here added between v2 and v4. The other answer doesn't directly answer OP question either, it also points him to newer version of kustomize. Why aren't you complaining to him? – yzorg Sep 09 '21 at 13:45
  • 7
    The problem with this answer is that its factually wrong. Even with the latest kubectl the kustomize functionality within kubectl is still limited to applying and patching via a kustomization.yaml _not_ editing the kustomization.yaml itself. – Blackclaws Aug 25 '22 at 09:05
  • @Blackclaws The whole point of kustomize is to generate the correct values for each variation. You edit things in k8s, you don't edit outputs of kustomize via automation. We edit kustumization.yaml by hand or add overlays and regenrate. We have variations for things like during DST in US and non-DST in US to generate UTC schedules at different times of year. At least that's how my team uses it. kustomize in CI/CD pipelines, kubectl (direct k8s edits) for one-offs or production reconfiguration scenarios (or uat or dev, etc). Kustomize is wrong tool for live edits. – yzorg Sep 01 '22 at 16:25
  • @yzorg Well, the fact that kustomize itself has facilities to update for example the version of an image that is put into the final manifests makes it at least usable, if maybe not the best tool for the job of _editing_ its own files. Kustomize also doesn't discourage you from using it to edit kustomization.yml files. Especially in a CI/CD scenario this is the tool I would use to change the version of an image that is set into the manifests. That fact notwithstanding. Its still true that the answer this is a comment to is factually wrong. You can only do what the OP asked with pure kustomize – Blackclaws Sep 06 '22 at 15:31
  • I tried it out and it did not work. – Carlos Garcia Mar 30 '23 at 21:59