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.
Disclaimer:
The views expressed and the content shared in all published articles on this website are solely those of the respective authors, and they do not necessarily reflect the views of the author’s employer or the techbeatly platform. We strive to ensure the accuracy and validity of the content published on our website. However, we cannot guarantee the absolute correctness or completeness of the information provided. It is the responsibility of the readers and users of this website to verify the accuracy and appropriateness of any information or opinions expressed within the articles. If you come across any content that you believe to be incorrect or invalid, please contact us immediately so that we can address the issue promptly.
Aneesh Mohan
Systems Engineer | LinkedIn
This site uses Akismet to reduce spam. Learn how your comment data is processed.
Leave a Reply