You may have noticed in this book so far that we’ve been writing a lot of YAML configuration files. It is possible to interact with most Kubernetes objects without writing configuration files using imperative kubectl commands such as kubectl run, and these are arguably easier to learn. So why did I use the declarative configuration-based approach throughout? One reason is that as you take an app to production, you can start treating the configuration like code, with version control and code reviews.
Another reason is it allows you to easily spin up multiple environments with the same configuration. Let’s say you want a staging and a production environment that are as similar as possible for better testing. With your workloads defined in configuration files, it’s possible to replicate the environments easily. Kubernetes has a namespaces feature that makes this possible without needing to worry about name collisions.