Cyber Deals - Get up to 65% off on CKA, CKAD, CKS, KCNA, KCSA exams and courses!

How to Label a Namespace in Openshift or Kubernetes

How to Label a Namespace in Openshift or Kubernetes
Image : joc.com
Labeling an object in OpenShift or Kubernetes is an awesome method to organize, group, or select API objects. Labels can be used to group arbitrarily-related objects; for example, all of the object like pods, services, replication controllers, routes and deployment configurations of a particular application can be grouped with a single or multiple labels.

Here see the quick way add label to a namespace or project. We have below awesomeproject with no labels set.

[root@ocp-master01 home]# oc describe project awesomeproject
 Name:           awesomeproject
 Created:        3 months ago
 
Labels:         
 Annotations:    openshift.io/description=
                 openshift.io/display-name=
                 openshift.io/node-selector=project=production
                 openshift.io/requester=system:admin
                 openshift.io/sa.scc.mcs=s0:c18,c12
                 openshift.io/sa.scc.supplemental-groups=1000330000/10000
                 openshift.io/sa.scc.uid-range=1000330000/10000
 Display Name:   
 Description:    
 Status:         Active
 Node Selector:  project=production
 Quota:
                         Name:           compute-resources
                         Resource        Used    Hard
                         --------        ----    ----
                         limits.cpu      0       4
                         limits.memory   0       8Gi
                         requests.cpu    0       2
                         requests.memory 0       4Gi
 Resource limits:

Now we will add a label using oc label command as show below.

[root@ocp-master01 home]# oc label namespace awesomeproject router2=intra-router2
 namespace/awesomeproject labeled

DO NOT use oc label project , please see Red Hat thread here .

Now check the project details, you can see a label added already.

[root@ocp-master01 home]# oc describe project awesomeproject
 Name:           awesomeproject
 Created:        3 months ago
 Labels:         router2=intra-router2
 Annotations:    openshift.io/description=
                 openshift.io/display-name=
                 openshift.io/node-selector=project=production
                 openshift.io/requester=system:admin
                 openshift.io/sa.scc.mcs=s0:c18,c12
                 openshift.io/sa.scc.supplemental-groups=1000330000/10000
                 openshift.io/sa.scc.uid-range=1000330000/10000
 Display Name:   
 Description:    
 Status:         Active
 Node Selector:  project=production
<truncated output...>

To test again, we will add another label.

root@ocp-master01 home]# oc label namespace awesomeproject router3=intra-router3
 namespace/awesomeproject labeled

And check details.

[root@ocp-master01 home]# oc describe project awesomeproject
 Name:           awesomeproject
 Created:        3 months ago
 Labels:         router2=intra-router2
                 router3=intra-router3
 Annotations:    openshift.io/description=
                 openshift.io/display-name=
                 openshift.io/node-selector=project=production
                 openshift.io/requester=system:admin
                 openshift.io/sa.scc.mcs=s0:c18,c12
                 openshift.io/sa.scc.supplemental-groups=1000330000/10000
                 openshift.io/sa.scc.uid-range=1000330000/10000
 Display Name:   
 Description:    
 Status:         Active
 Node Selector:  project=production
 <truncated output...>

That’s all.

Aneesh Mohan

Aneesh Mohan

System Engineer- Paas(Openshift) at T-Systems Malaysia |RHCE|Ansible|Openshift


Disclaimer: Views expressed in articles are those of the respective authors and do not necessarily reflect the views of their employers or this site. While we aim for accuracy, please verify information before relying on it, and let us know if you spot an error.
Share:

Related Posts

Ansible

Ansible Nested Loop with List and Dictionary

Ansible loops are simple and powerful with mixed data. You will sure say “awesome” when you realize the easiness with loops. During our technical …

OpenShift Cluster – How to Drain or Evacuate a Node for Maintenance

OpenShift Cluster – How to Drain or Evacuate a Node for Maintenance

As we know OpenShift clusters are bundled with multiple compute nodes, master nodes, infra nodes etc, it’s not a big deal to manage node …

Ansible - Questions and References

Ansible - Questions and References

Note: These are questions I have received via chat groups and communities. This is a living document and I will update the page whenever there is a …

How to Create, Increase or Decrease Project Quota in OpenShift

How to Create, Increase or Decrease Project Quota in OpenShift

Usually application owner or project owner will specify the quota settings (Memory and CPU) during project creation. But sometimes, they realize that …

AWS Transformation Day Kuala Lumpur

AWS Transformation Day Kuala Lumpur

AWS is arranging the AWS Transformation Day Kuala Lumpur 2018 to discover first-hand the transformative opportunities of the cloud for your …

How to set number of pods per node in OpenShift ?

How to set number of pods per node in OpenShift ?

## get the machineconfigpool $ oc get machineconfigpool ## see details $ oc describe machineconfigpool worker ## add label to the machineconfigpool if …