Create a namespace called accounts all the following steps need to be done in this namespace
Deploy a deployment named redis-app using the image redis with 2 replicas
tier=prod and loc=northDeploy a deployment named redis-db using the image redis:alpine with 2 replicas
tier=prod and loc=southUse labels to query the pods
tier=prodloc=southAlter deployment redis-app
region=emeatier=prod to tier=dev# create the namespace
kubectl create ns accounts
# create the deployments (imperative for speed)
kubectl create deployment redis-app --image=redis --replicas=2 -n accounts
kubectl create deployment redis-db --image=redis:alpine --replicas=2 -n accounts
# expose redis-db
kubectl expose deployment redis-db --port=6379 -n accounts
# change the labels on the deployment
kubectl label deployment redis-app tier=prod loc=north -n accounts
kubectl label deployment redis-db tier=prod loc=south -n accounts
Are the deployments and there pods labelled the same? (ignore the pod-template-hash ) why?
Because the label changes were made on the deployments after the pods were created (with the original labels). You would need to label the pods as well to match or restart the deployments to have matching labels
# list pods with tier=prod
kubectl get pods -n accounts -l tier=prod
# list pods with loc=south
kubectl get pods -n accounts -l loc=south
# Add labels on deployment
kubectl label deployment redis-app region=emea-n accounts
# Modify labels. As the label exists we need the overwrite option
kubectl label deployment redis-app tier=dev --overwrite -n accounts