Lab 8.1 - Labeling Nodes

1. Login as the developer user

oc login -u developer -p rahasia https://api.openshift.podX.io:6443

2. Create a new project named schedule-pods

oc new-project schedule-pods

3. Create a new application named hello using the container located at quay.io/redhattraining/hello-world-nginx:v1.0.

oc create deployment hello --image quay.io/redhattraining/hello-world-nginx:v1.0

4. Create a service for the application

oc expose deployment/hello --port 80 --target-port 8080

5. Make the service accessible by creating a route to it

oc get svc
oc expose svc/hello
oc get route

6. Manually scale the application so there are four running pods

oc scale --replicas 4 deployment/hello

7. Verify that the four running pods are distributed between the two worker nodes

oc get pods -o wide

8. Log in to the OKD cluster as the admin user

oc login -u admin -p rahasia https://api.openshift.podX.io:6443

9. Switch to the default project

oc project default
oc project -q

10. Verify nodes

oc get nodes -o wide
oc get nodes -L env -l node-role.kubernetes.io/worker

11. Add the env=prod label to the first worker node to indicate that it is a production node

oc label node \
 worker1.openshift.podX.io \
 env=prod

12. Add the env=dev label to the second worker node to indicate that it is a development node

oc label node \
 worker2.openshift.podX.io \
 env=dev

13. Verify that the worker nodes have the correct env label set

oc get nodes -L env -l node-role.kubernetes.io/worker

14. Login as the developer user

oc login -u developer -p rahasia https://api.openshift.podX.io:6443

15. Switch to the schedule-pods project

oc project schedule-pods
oc project -q

16. Modify the deployment resource for the hello application to select a development node

oc edit deployment/hello
...
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      nodeSelector:
         env: dev
      restartPolicy: Always
      schedulerName: default-scheduler
...

17. Verify that the application pods are deployed to the node with the env=dev label

oc get pods -o wide

18. Review pods detail

oc describe pods hello-5bbdfb776-fdpmj

19. Show the cluster events to verify

oc get events

20. Log in to your OpenShift cluster as the admin user

oc login -u admin -p rahasia https://api.openshift.podX.io:6443

21. Remove the env label from all worker nodes

oc label node -l node-role.kubernetes.io/worker env-

22. Verify the nodes

oc get nodes -o wide
oc get nodes -L env -l node-role.kubernetes.io/worker

Daftar Materi