Introduction
Hi, I am Akshay Rao, will be starting a exercise series on k8s.
In this blog there will not explanation only problems and solutions.if you want explanation have a look at this series:-
https://dev.to/aksrao1998/series/24887
Pre-requisite
have minikube or kind running in the local machine.
Note:- k is alias for kubectl.
Let's Start
Problem
- Create 3 pods with names nginx1,nginx2,nginx3. All of them should have the label app=v1.
- Show all labels of the pods.
- Change the labels of pod 'nginx2' to be app=v2.
- Get the label 'app' for the pods (show a column with APP labels).
- Get only the 'app=v2' pods
- Add a new label tier=web to all pods having 'app=v2' or 'app=v1' labels.
- Add an annotation 'owner: marketing' to all pods having 'app=v2' label.
- Remove the 'app' label from the pods we created before.
- Annotate pods nginx1, nginx2, nginx3 with "description='mydescription'" value.
- Check the annotations for pod nginx1.
- Remove the annotations for these three pods.
Solution
#1 Soln
[ ~ (⎈|minikube:mynamespace)]$ k run nginx1 --image=nginx -l app=v1
pod/nginx1 created
[~ (⎈|minikube:mynamespace)]$ k run nginx2 --image=nginx -l app=v1
pod/nginx2 created
[~ (⎈|minikube:mynamespace)]$ k run nginx3 --image=nginx -l app=v1
pod/nginx3 created
#2 Soln
[~ (⎈|minikube:mynamespace)]$ k get po -l app=v1
NAME READY STATUS RESTARTS AGE
nginx1 1/1 Running 0 2m11s
nginx2 1/1 Running 0 2m4s
nginx3 1/1 Running 0 115s
#3 Soln
[~ (⎈|minikube:mynamespace)]$ k label pod nginx2 app=v2 --overwrite
pod/nginx2 labeled
#4 Soln
[ ~ (⎈|minikube:mynamespace)]$ k get po -l app
NAME READY STATUS RESTARTS AGE
nginx1 1/1 Running 0 16m
nginx2 1/1 Running 0 16m
nginx3 1/1 Running 0 16m
#5 Soln
[ ~ (⎈|minikube:mynamespace)]$ k get po -l app=v2
NAME READY STATUS RESTARTS AGE
nginx2 1/1 Running 0 14m
#6 Soln
[~ (⎈|minikube:mynamespace)]$ k label po -l "app in (v1.v2)" teir=web
#7 Soln
[~ (⎈|minikube:mynamespace)]$ k annotate po -l "app=v2" owner=marketing
pod/nginx2 annotated
#8 Soln
[~ (⎈|minikube:mynamespace)]$ k label po nginx{1..3} app-
pod/nginx1 unlabeled
pod/nginx2 unlabeled
pod/nginx3 unlabeled
#9 Soln
[~ (⎈|minikube:mynamespace)]$ k annotate po nginx{1..3} description=mydescription
pod/nginx1 annotated
pod/nginx2 annotated
pod/nginx3 annotated
#10 Soln
[~ (⎈|minikube:mynamespace)]$ k annotate po nginx1 --list
description=mydescription
#11 Soln
[ts-akshay.rao@JP-FVFZ91DHL414 ~ (⎈|minikube:mynamespace)]$ k annotate po nginx{1..3} description-
pod/nginx1 annotated
pod/nginx2 annotated
pod/nginx3 annotated
Top comments (0)