Deploying to Namespaces

Learn about a couple of ways to ways to deploy objects to Namespaces:

We'll cover the following

As previously mentioned, most objects are Namespaced, and Kubernetes deploys new objects to the default Namespace unless we specify otherwise.

How to deploy to Namespaces

There are two ways to deploy objects to specific Namespaces:

  • Imperatively

  • Declaratively

To do it imperatively, add the -n or --namespace flag to commands. To do it declaratively, we specify the Namespace in the objects YAML manifest.

Let’s deploy an app to the shield Namespace using the declarative method.

The application is defined in the app.yml file in the namespaces folder of the book’s GitHub repo. It defines three objects: a ServiceAccount, a Service, and a Pod. The following YAML extract shows all three objects targeted at the shield Namespace.

Don’t worry if you don’t understand everything in the YAML, you only need to know it defines three objects and targets each one at the shield Namespace.

Get hands-on with 1400+ tech skills courses.