Skip to content

Latest commit

 

History

History
89 lines (53 loc) · 2.45 KB

File metadata and controls

89 lines (53 loc) · 2.45 KB

Warmup: Labels!

image

Welcome to your Animal Pods Warmup Challenge! Your mission, should you choose to accept it, is to:

  1. Download and execute a script that creates pods with animal-related labels.
  2. Use kubectl to 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


image

Task 1: Find All Pods with species=mammal

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=mammal

Task 2: Find All Pods with Both species=mammal and habitat=land

Now, 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=land

Task 3: Find All Pods with diet=herbivore or diet=carnivore

Your 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)'

Finished?

We don't need that namespace or the pods anymore. Wipe 'em out!

student@bchd:~$ kubectl delete ns critters

You can press ctrl c if it hangs, it'll continue deleting even if you do so.