You are on page 1of 1

8.4.

LABS 1

Exercise 8.3: Use Labels to Manage Resources

1. Try to delete all Pods with the app=nginx label, in all namespaces. You should receive an error as this function must be
narrowed to a particular namespace. Then delete using the appropriate namespace.
student@lfs458-node-1a0a:~$ kubectl delete pods -l app=nginx \
--all-namespaces
Error: unknown flag: --all-namespaces
<output_omitted>

student@lfs458-node-1a0a:~$ kubectl -n accounting delete pods -l app=nginx


pod "nginx-one-74dd9d578d-fcpmv" deleted
pod "nginx-one-74dd9d578d-sts5l" deleted

2. View the Pods again. New versions of the Pods should be running as the controller responsible for them continues.
student@lfs458-node-1a0a:~$ kubectl -n accounting get pods
NAME READY STATUS RESTARTS AGE
nginx-one-74dd9d578d-ddt5r 1/1 Running 0 1m
nginx-one-74dd9d578d-hfzml 1/1 Running 0 1m

3. We also gave a label to the deployment. View the deployment in the accounting namespace.
student@lfs458-node-1a0a:~$ kubectl -n accounting get deploy --show-labels
NAME DESIRED CURRENT UP-TO-DATE AVAILABLE AGE LABELS
nginx-one 2 2 2 2 27m system=secondary

4. Delete the deployment using its label.


student@lfs458-node-1a0a:~$ kubectl -n accounting delete deploy \
-l system=secondary
deployment.extensions/nginx-one deleted

5. Remove the label from the secondary node. Note that the syntax is a minus sign directly after the key you want to
remove, or system in this case.
student@lfs458-node-1a0a:~$ kubectl label node lfs458-worker system-
node/lfs458-worker labeled

LFS258: V 2019-08-12 © Copyright the Linux Foundation 2019. All rights reserved.

You might also like