banner



How To Rename Namespace In Kubernetes

Kubernetes Namespace

Introduction to Kubernetes Namespace

Kubernetes Namespace is reasonable when y'all have different teams, projects or customers which share a same Kubernetes Cluster.

This works past providing:

  • A scope of names.
  • A mode to attach authorizations and policies to a subsection of a cluster.

In Kubernetes, when you create a service, a corresponding DNS entry is created which is of the form as follows:

"<service_name>.<namespace_name>.svc.cluster.local"

If a container only uses <service_name>, then it volition be resolved to the service which is local to current namespace.

If you demand to reach a service in other namespaces, then y'all demand to use the FQDN (fully qualified domain name) like "<service_name>.

<namespace_name>.svc-1.cluster-ane.local"

We need to note that not all object in Kubernetes need to be in namespace, like nodes and persistentVolumes demand not to be in namespace as those are low-level resources.

To get the list of resources which are in a namespace and which are not, use below commands:

kubectl api-resources --namespaced=truthful

kubectl api-resource --namespaced=imitation

Point to annotation that, if you lot accept only few users like with in tens, you lot don't need Namespaces. Merely if you need whatsoever bones features which Namespace provides similar having resource's uniqueness in a Namespace in a cluster, and then get-go using Namespaces. Likewise notation that one Namespaces tin can't be nested in another Namespace and a Kubernetes resources can simply be in one unmarried Namespace.

How to use Kubernetes Namespace?

To use Kubernetes Namespace, you must have below at least, even for a testing lab.

  • Kubernetes Cluster
  • Kubectl control line tool configured
  • Basic agreement of Kubernetes Pods, containers, Services and Deployments.

Start, nosotros see the default namespace. Which is provided past Kubernetes systems to all object which doesn't have whatsoever other Namespace similar default set of Pods, Deployments and Services used by Cluster. Creating multiple Namespaces and utilise them efficiently for your services to manage your objects collections.

Too, note that Kubernetes starts with iii namespaces initially at least. These can be more every bit per your environment.

  • default: For objects with no other namespaces.
  • kube-system: For those objects which are created by system.
  • kube-public: This is usable past all users and created automatically. This Namespace is mostly reserved for Cluster usage.

Namespaces accept below functionalities and on basis of same we utilise can use them.

  • Within aforementioned Namespace, Pod to Pod communication.
  • Namespaces are virtual cluster sitting on superlative of physical cluster.
  • Namespaces provides logical separation between the environments.
  • Namespaces are just subconscious from each other but are non fully isolated from each other.
  • I service in a Namespace can talk to another service in another Namespace, if the target and sources are used with full name which includes service/object proper noun followed past Namespace.

Withal, if we apply the only service name and DNS internally identifies information technology, resolves it with in same Namespace.

Examples of Kubernetes Namespace

Given beneath are the examples:

There are few operations, which can be used for controlling the Namespaces.

Example #1: Create

You lot tin can create as much Namespaces as you desire. As at that place is no performance penalisation due to this. But sometimes really improves your performance and efficiency, when y'all have limited API objects within a Namespace. To create a namespace, you can use control like below. Here namespace.yaml is a sample file which contains your Namespace specifications .

kubernetes namespace op 1

You tin use the beneath control to deploy the file.

kubectl create -f namespace.yml

Output:

kubernetes namespace 2

You tin can meet details similar below:

kubectl describe namespace test

Output:

describe namespace test

Cosmos of Namespace tin also be washed through a single control. Here y'all only must give the name of Namespace.

kubectl create namespace test1

Output:

kubernetes namespace 4

Example #2 Become

To get the current list of Namespaces. You tin can run below command. Also note that in the output you will get all user created and organisation created Namespaces.

kubectl get namespace

Above command volition output similar beneath, here yous see all bachelor Namespaces.

kubectl become namespaces

Output:

get

To listing a Namespace or a set of Namespaces you lot have to specify them similar below.

kubectl go namespaces test test1

Output:

kubernetes namespace 6

Example #3: Draw

To get the details virtually a Namespace. You must run beneath command.

kubectl describe namespaces kube-system

Yous tin also do same past running like beneath:

kubectl go namespaces test

Output:

kubernetes namespace 8

If you demand more than detailed output. Run like below:

kubectl become namespaces test -o yaml

Output:

kubectl get

Example #4: Delete

To delete a Namespace. Here example of Namespace is "test"

kubectl delete namespaces exam

Output:

delete

If you want to delete more than one Namespace, then specify same as beneath:

kubectl delete namespaces test1 test3

Output:

kubernetes namespace 11

Example #5: Creating and Viewing resources under a Namespace

When y'all create an object, without specifying the namespace, it volition exist created in electric current Namespace which, if not changed manually to a custom Namespace, is default Namespace.

You can specify a namespace for an object in two ways by either using namespace field in specification YAML file for object or Using namespace flag in command line. In below example, you can encounter that scenario.

Accept a sample task like creating a pod using a simple specification similar below:

true cat pod-create.yaml

Output:

cat pod-create.yaml

Deploy this file like below:

kubectl apply -f pod-create.yaml

Output:

kubernetes namespace 13

Now when you check the description of this pod, you will find that this pod was created in default namespace.

kubectl depict pod mypod | grep Namespace

Output:

kubernetes namespace 14

Now if create another object by specifying namespace in YAML file, similar below:

cat pod-create-ane.yaml

Output:

ubernetes namespace 15

But annotation that you should have the specified namespace existing, otherwise the command volition fail.

Bank check this like below:

kubectl become namespaces test

Output:

kubernetes namespace 16

Now utilize the file.

kubectl utilise -f pod-create-1.yaml

Output:

apply -f pod-create-1.yaml

At present when you check similar beneath, yous will run across you accept your pod created in specified namespace.

kubectl get pod mypod-i –namespace=exam

Output:

kubernetes namespace 18JPG

Also, notation that you lot can create objects with same proper name in different namespaces similar below where pod with aforementioned name is existing in default as well every bit user-made Namespace.

kubectl get pod mypod –namespace=exam

Output:

kubectl get pod mypod

Likewise, if y'all create an object like pod using a specification file and don't mention namespace field in it. But while deploying this file utilize namespace flag similar below, your object will be created in that namespace.

kubectl employ -f pod-create.yaml –namespace=exam-two

Output:

kubectl apply -f pod-create.yaml

Check this similar beneath again.

kubectl get pod mypod –namespace=examination-2

Output:

kubernetes namespace 21JPG

Conclusion

In Kubernetes environments, where y'all take a lot of users, resources and objects. Y'all can use multiple Namespaces in your physical cluster. Which so can be treated as virtual clusters every bit those are logically isolated from one another. This segregation makes your squad efficient, aid in operation improvement and somehow ease of managing them all.

Recommended Manufactures

This is a guide to Kubernetes Namespace. Here nosotros discuss the introduction to kubernetes namespace along with how to use namespace with examples. Yous may also have a look at the post-obit manufactures to learn more –

  1. Kubernetes Architecture
  2. Kubernetes Operators
  3. Kubernetes Autoscaling

Source: https://www.educba.com/kubernetes-namespace/

0 Response to "How To Rename Namespace In Kubernetes"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel