OpenShift - Label a deployment using the oc label command

An image contains the code used to create a deployment. Then, a deployment can be created from an image, which should then create a replica set (which is the number of pods that should be created), and then the pods should be created.

If you are not familiar with the oc command, refer to OpenShift - Getting Started with the oc command.

The oc label deployment command can be used to apply one or more labels to a deployment. In this example, label region=east is applied to the deployment named my-app.

~]$ oc label deployment my-app region=east
deployment.apps/my-app labeled


And the oc describe deployment command can be used to see the labels that have been applied to the deployment.

~]$ oc describe deployment my-app
Name:                   my-app
Namespace:              default
CreationTimestamp:      Tue, 31 May 2022 20:31:51 -0500
Labels:                 region=east


The oc get pods command can be used to see that new pod(s) should immediately be created after the label has been applied to the deployment.

~]# oc get pods
my-app-9mzm2    1/1     Running    0         52s


And here is how you can remove a label. In this example, the region label will be removed.

~]$ oc label deployment my-app region-
deployment.apps/my-app labeled


Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee

Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter e2422 in the box below so that we can be sure you are a human.