0

If I'm trying to do a command like kubectl apply -f dir1/subdir1/deployment.yml, and I have subdir1, subdir2, etc, how can I run that command for all of them at once?

I tried kubectl apply -f dir1/*/deployment.yml and that passes all the deployment.yml to the single -f flag, making it invalid as that flag accepts a single argument.

I've also tried kubectl apply -f dir1/{subdir1,subdir2}/deployment.yml with no luck.

PS: I'm using zsh for my shell with oh-my-zsh+p10k if that matters.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
cclloyd
  • 8,171
  • 16
  • 57
  • 104
  • Does this answer your question? [Is there a way to kubectl apply all the files in a directory?](https://stackoverflow.com/questions/59491324/is-there-a-way-to-kubectl-apply-every-files-in-a-directory) – John Kugelman Nov 12 '21 at 20:32

2 Answers2

0

A command-agnostic solution in zsh:

for d (dir1/*/deployment.yml) kubectl apply -f "$d"

This uses a zsh-specific alternate form of the for loop, more commonly written as

for d in dir1/*/deployment.yml; do kubectl apply -f "$d"; done

(Though this is admittedly different from running kubectl precisely once and letting it iterate over the configurations itself.)

chepner
  • 497,756
  • 71
  • 530
  • 681
0

To include subdirectories use the parameter -R, like

kubectl apply -R -f /path/to/dir

Where -R is the parameter used for Processing the directory used in -f recursively

Refer this documentation for more information on kubectl apply command.

Goli Nikitha
  • 858
  • 3
  • 9