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.

[[email protected] 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.

[[email protected] 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.

[[email protected] 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.

[email protected] home]# oc label namespace awesomeproject router3=intra-router3
namespace/awesomeproject labeled

And check details.

[[email protected] 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

Systems Engineer | LinkedIn

You may also like...

Leave a Reply

avatar
  Subscribe  
Notify of
%d bloggers like this: