1. Listing Pods and Filtering by Environment
Begin by listing all the pods to review what is currently deployed:--no-headers option and pipe the output to the word count command:
2. Counting Pods in the Finance Business Unit
To determine the number of pods belonging to the finance business unit (assumed labelbu=finance), execute:
3. Counting All Objects in the Production Environment
First, list only the pods in the production environment (assumed labelenv=prod):
wc -l, you determine that there are 7 objects in total in the production environment.
4. Identifying a Specific Pod with Multiple Labels
To find the pod that meets all three criteria—being in the production environment, belonging to the finance business unit, and operating in the front-end tier—follow these steps:-
List the pods in the production environment:
Example output:
-
Combine selectors for environment, business unit, and tier:
The command returns:
5. Fixing a ReplicaSet Definition
The final task involves resolving a label mismatch error in a ReplicaSet YAML definition file. Below is the original ReplicaSet configuration:The error occurs because the label in the selector (
tier: front-end) does not match the label in the pod template (tier: nginx). These values must be identical.tier: front-end:
Ensure that selector labels and template labels always match to avoid deployment errors and ensure that your ReplicaSet manages the correct pods.
This concludes the lesson on using labels and selectors in Kubernetes. For more information on Kubernetes object management, consider checking out the following resources: