Creating a New Namespace

In this lesson, we will create a new Namespace and switch the kubectl context to it.

Understanding the Scenrio

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 just made a new release. They ran unit tests and built the binary. They produced a new Docker image and tagged 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 the 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 that is to be tested. That would create the necessary separation and maintain the freedom we strive for. However, that is slow. Creating a cluster takes time. Even though it might not look like much, wasting ten minutes (if not more) only on that is too much time. Even if you disagree and you 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 you start creating new Kubernetes clusters, we’ll explore how we might accomplish the same goals with a single cluster and with the help of 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.