Tasks
-
Create a namespace called
exercise-01Solution
kubectl create namespace exercise-01Creates the namespace. All subsequent commands target this namespace with
-n exercise-01. Reference lesson. -
Create pod
○webin namespaceexercise-01with imagenginx:1.28, labelsapp=web,tier=frontend, requestscpu=100m,memory=64Mi, limitscpu=250m,memory=128MiSolution
Generate a base manifest quickly:
kubectl run web -n exercise-01 --image=nginx:1.28 --labels=app=web,tier=frontend --dry-run=client -o yaml > pod.yamlThen edit
pod.yamlso it matches this final manifest:apiVersion: v1 kind: Pod metadata: labels: app: web tier: frontend name: web namespace: exercise-01 spec: containers: - image: nginx:1.28 name: web resources: limits: cpu: 250m memory: 128Mi requests: cpu: 100m memory: 64Mikubectl apply -f pod.yamlThis step creates the pod with the expected metadata and resource constraints. Reference lesson.
-
Add label
○version=v1and remove labeltierfrom podwebSolution
kubectl label pod web -n exercise-01 version=v1 kubectl label pod web -n exercise-01 tier-Labels are mutable metadata, no pod restart is required. Reference lesson.
-
Optional clean up, delete the namespace
Solution
kubectl delete namespace exercise-01Deletes the namespace and everything inside it in one command.