3

Just wondering, let's say I have X Kubernetes deployment.yaml, pod.yaml, persistedvolumecliam.yaml and service.yaml files inside a directory.

The tutorials would tell us to do the following:

kubectl apply -f frontend-service.yaml,redis-master-service.yaml,redis-slave-service.yaml,frontend-deployment.yaml,redis-master-deployment.yaml,redis-slave-deployment.yaml

Is there a way just to do something like:

kubectl apply all

or

kubectl apply -f *

or some variation thereof to spin all of the kube stuffs within on directory?

Micheal J. Roberts
  • 3,735
  • 4
  • 37
  • 76
  • 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-all-the-files-in-a-directory) – Witt Jan 20 '22 at 18:27

3 Answers3

7

You can apply everything inside a directory with kubectl apply -f /path/to/dir. To include subdirectories use the paramter -R, like kubectl apply -R -f /path/to/dir

Chris
  • 5,109
  • 3
  • 19
  • 40
4
# Apply resources from a directory
kubectl apply -f dir/

# Process the directory used in -f recursively
kubectl apply -R -f dir/

For more details check the reference documentation.

webwurst
  • 4,830
  • 3
  • 23
  • 32
0

You can apply a YAML file using kubectl apply recursively in all folders by using the --recursive flag.

Here is the basic syntax once you are in the root folder:

kubectl apply --recursive -f .
Jason
  • 47
  • 4