This is a pretty simple lab, we are going to explore labels. You can use labels to organize, group, or select API objects.

For example, pods are "tagged" with labels, and then services use label selectors to identify the pods they proxy to. This makes it possible for services to reference groups of pods, even treating pods with potentially different docker containers as related entities.

Labels on a pod

In a previous lab we added our web app using a S2I template. When we did that, OpenShift labeled our objects for us. Let's look at the labels on our running pod.

You can see the Labels automatically added contain the app, deployment, and deploymentconfig. Let's add a new label to this pod.

  1. Add a label
    $ oc label pod/<POD NAME> testyear=2021 testedby=me
    
  2. Look at the labels
    $ oc describe pod/<POD NAME> | grep Labels: --context=4
    Namespace:    demo-0
    Priority:     0
    Node:         ip-10-0-186-15.us-east-2.compute.internal/10.0.186.15
    Start Time:   Thu, 29 Jul 2021 19:33:13 +0000
    Labels:       app=dc-metro-map
                deployment=dc-metro-map-4
                deploymentconfig=dc-metro-map
                testedby=me
                testyear=2021
    

Labels on a pod

In a previous lab we added our web app using a S2I template. When we did that, OpenShift labeled our objects for us. Let's look at the labels on our running pod.

  1. Click "Workloads", click on "Pods", then click on the three vertical dots next to the "Running" pod. Consider filtering for Status "Running".image
  2. Click "Edit Labels"image
  3. Here, at the top, you can see the labels on this pod
  4. Add ‘testedby=me' and click "Save"image
  5. Your updated label will show up in the running pods.
  6. Select Workloads -> Pods -> dc-metro-map (Running POD), then scroll down to "Labels"image

That's it for this lab. Now you know that all the objects in OpenShift can be labeled. This is important because those labels can be used as part of your CI/CD process. An upcoming lab will cover using labels for Blue/Green deployments. Labels can also be used for running your apps on specific nodes (e.g. just on SSD nodes or just on east coast nodes).