Welcome to your Animal Pods Warmup Challenge! Your mission, should you choose to accept it, is to:
- Download and execute a script that creates pods with animal-related labels.
- Use
kubectlto filter the pods based on their labels.
Run the following command to download the script that will create the animal-named pods with various labels, and execute it immediately:
student@bchd~$ wget https://raw.githubusercontent.com/csfeeser/k8s/refs/heads/master/resources/animallabelpods.sh -O animallabelpods.sh && bash animallabelpods.sh
This script will create 20 pods named after different animals, each with a mix of labels such as species, habitat, and diet. They will be created in the namespace critters. Confirm you're good to go:
student@bchd~$ kubectl get pods -n critters --show-labels
Run the appropriate kubectl command to find all pods with the label species: mammal in the critters namespace.
Click here for the full solution!
kubectl get pods -n critters --selector="species=mammal"OR
kubectl get pods -n critters -l species=mammalNow, filter the pods down even further. Find the pods that have both species: mammal and habitat: land in the critters namespace.
Click here for the full solution!
kubectl get pods -n critters --selector="species=mammal,habitat=land"OR
kubectl get pods -n critters -l species=mammal,habitat=landYour final task is to find the pods that have either diet: herbivore or diet: carnivore in the critters namespace.
Click here for the full solution!
kubectl get pods -n critters --selector="diet in (herbivore,carnivore)"OR
kubectl get pods -n critters -l 'diet in (herbivore,carnivore)'We don't need that namespace or the pods anymore. Wipe 'em out!
student@bchd:~$ kubectl delete ns critters
You can press
ctrl cif it hangs, it'll continue deleting even if you do so.
