Working with Namespaces

In a Kubernetes cluster, the name of a resource is a unique identifier within a Namespace. Using a Kubernetes Namespace could separate user spaces for different environments in the same cluster. It gives you the flexibility of creating an isolated environment and partitioning resources to different projects and teams. You may consider Namespace as a virtual cluster. Pods, Services, and Deployments are contained in a certain Namespace. Some low-level resources, such as nodes and persistentVolumes, do not belong to any Namespace.

Before we dig into the resource Namespace, let's understand kubeconfig and some keywords first:

The relationship of kubeconfig components

kubeconfig is used to call the file which configures the access permission of Kubernetes clusters. As the original configuration of the system, Kubernetes takes $HOME/.kube/config as a kubeconfig file. Some concepts that are illustrated by the preceding diagram are as follows:

  • kubeconfig defines user, cluster, and context: kubeconfig lists multiple users for defining authentication, and multiple clusters for indicating the Kubernetes API server. Also, the context in kubeconfig is the combination of a user and a cluster: accessing a certain Kubernetes cluster with what kind of authentication.
  • Users and clusters are sharable between contexts: In the previous diagram, both Context 1 and Context 3 take User 1 as their user content. However, each context can only have a single user and single cluster definition.
  • Namespace can be attached to context: Every context can be assigned to an existing Namespace. If there are none, like Context 3, it is along with the default Namespace, named default, as well.
  • The current context is the default environment for client: We may have several contexts in kubeconfig, but only one for the current context. The current context and the Namespace attached on it will construct the default computing environment for users.

Now you will get the idea that, as Namespace works with kubeconfig, users can easily switch default resources for usage by switching the current context in kubeconfig. Nevertheless, users can still start any resource in a different Namespace with a specified one. In this recipe, you will learn how to create your own Namespace and how to work with it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.119.138.202