Creating a New Namespace

Learn how to create a new namespace and switch the kubectl context to it.

Understanding the scenario

Currently, we’re running the release 1.0 of the go-demo-2 application. We can consider it the production release. Now, let’s say that the team in charge of the application makes new release. They run unit tests and build the binary. They produce a new Docker image and tag it as vfarcic/go-demo-2:2.0.

What they didn’t do is run functional, performance, and other types of tests that require a running application. The new release is still not ready to be deployed to production, so we cannot yet execute a rolling update and replace the production release with the new one. We need to finish running the tests, and for that we need the new release running in parallel with the old one.

Exploring our options

We could, for example, create a new cluster that would be used only for testing purposes. While that is indeed a good option in some situations, in others it might be a waste of resources. Moreover, we’d face the same challenge in the testing cluster. There might be multiple new releases that need to be deployed and tested in parallel.

Another option could be to create a new cluster for each release to be tested. That would create the necessary separation and maintain the freedom we strive for. However, that would be very slow. Creating a cluster takes time. Although it might not look like much, wasting ten minutes (if not more) only on that is a lot of valuable time. Even if you disagree and think that ten minutes is not that much, such an approach would be too expensive.

Every cluster has a resource overhead that needs to be paid. While the overall size of a cluster affects the resource overhead, the number of clusters affects it even more. It’s more expensive to have many smaller clusters than a big one. On top of all that, there is the operational cost. While it is often not proportional to the number of clusters, it still increases.

Having a separate cluster for all our testing needs is not a bad idea. We shouldn’t discard it, just as we should consider creating (and destroying) a new cluster for each new release. However, before we start creating new Kubernetes clusters, let’s explore how we might accomplish the same goals with a single cluster and namespaces.

Creating a namespace

First things first. We need to create a new namespace before we can use it:

Get hands-on with 1200+ tech skills courses.