Bootstrap FreeKB - OpenShift - Label a deployment using the oc label command
OpenShift - Label a deployment using the oc label command

Updated:   |  OpenShift articles

A deployment is used to manage the pods that are created to run an application. The deployment ensures that the desired number of pod replicas are running and can handle updates to the application by rolling out new versions of the pods. The deployment creates and manages a replica set, which in turn manages the pods.

flowchart TB subgraph Project["OpenShift Project/Namespace"] Deployment[Deployment] Replica_Set[Replica Set] subgraph Pods["Pod Replicas"] Pod1[Pod 1
Container] Pod2[Pod 2
Container] Pod3[Pod 3
Container] end end Deployment -->|Creates/Manages| Replica_Set Replica_Set -->|Manages| Pod1 Replica_Set -->|Manages| Pod2 Replica_Set -->|Manages| Pod3 style Deployment fill:#90CAF9 style Replica_Set fill:#FFE082 style Pods fill:#FFCCBC

It is also noteworthy that a route provides a URL that can be used to access the application from outside the OpenShift cluster. For example, if the route is configured to use the hostname myapp.mydomain.com, then users can access the application by navigating to http://myapp.mydomain.com. The route will forward the request to the service, which will then forward the request to one of the pods that are running the application.

flowchart LR subgraph Project["OpenShift Project/Namespace"] subgraph Pods["Pod Replicas"] Pod1[Pod 1
Container] Pod2[Pod 2
Container] Pod3[Pod 3
Container] end SVC[Service] Route[Route] end USER[External User] --> Route --> SVC SVC --> Pod1 SVC --> Pod2 SVC --> Pod3 style SVC fill:#A5D6A7 style Pods fill:#FFCCBC style USER fill:#CE93D8

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
NAME            READY   STATUS     RESTARTS  AGE
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



Comments


Add a Comment


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