Lab 8.2 - Limiting Resource Usage

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-limit

oc new-project schedule-limit

3. Create a deployment resource file and save it to /root/hello-limit.yaml

oc create deployment hello-limit \
 --image quay.io/redhattraining/hello-world-nginx:v1.0 \
 --dry-run=client -o yaml > /root/hello-limit.yaml
cat /root/hello-limit.yaml

4. Edit /root/hello-limit.yaml to replace the resources: {} with:

vim /root/hello-limit.yaml
...
    spec:
      containers:
      - image: quay.io/redhattraining/hello-world-nginx:v1.0
        name: hello-world-nginx
        resources:
          requests:
            cpu: "3"
            memory: 20Mi
status: {}
...

5. Create the new application using your resource file

oc create --save-config \
 -f /root/hello-limit.yaml

6. Although a new deployment was created for the application, the application pod should have a status of pending.

oc get pods

7. The pod cannot be scheduled because none of the worker nodes have sufficient CPU resources.

oc get events --field-selector type=Warning

# This can be verified by viewing warning events.

8. Edit /root/hello-limit.yaml to request 2 CPUs for the container. Change the cpu: "3" line to match the highlighted line below.

vim /root/hello-limit.yaml
...
...output omitted...
        resources: 
          requests:
            cpu: "2"
            memory: 20Mi
...

9. Apply the changes to your application

oc apply -f /root/hello-limit.yaml

10. Verify that your application deploys successfully

oc get pods

11. Manually scale the hello-limit application up to 3 pods

oc scale --replicas 3 deployment/hello-limit

12. Verify the pods. You might need to run oc get pods multiple times until you see that two pods are running and one pod is pending.

oc get pods

13. Warning events indicate that one or more pods cannot be scheduled because none of the nodes has sufficient CPU resources.

oc get events --field-selector type=Warning

# Your warning messages might be slightly different.

14. Delete the deployment

oc delete deployment hello-limit

Daftar Materi