You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create 3 pods with names nginx1,nginx2,nginx3. All of them should have the label app=v1
kubectl run nginx1 --image=nginx --restart=Never --labels=app=v1
kubectl run nginx2 --image=nginx --restart=Never --labels=app=v1
kubectl run nginx3 --image=nginx --restart=Never --labels=app=v1
#Example above uses command line to generate pods with labels, try defining them using YAML all in one file
Show all labels of the pods
kubectl get po --show-labels
Change the labels of pod 'nginx2' to be app=v2
kubectl label po nginx2 app=v2 --overwrite
Get the label 'app' for the pods
kubectl get po -L app
Get only the 'app=v2' pods
kubectl get po -l app=v2
# or
kubectl get po -l 'app in (v2)'
Remove the 'app' label from the pods we created before
kubectl label po nginx1 nginx2 nginx3 app-
# or
kubectl label po -l app app-
# or if on linux
kubectl label po nginx{1..3} app-
Annotate pods nginx1, nginx2, ngingx3 with "description='my description'" value
kubectl annotate po nginx1 nginx2 nginx3 description="my description"
Check the annotations for pod nginx1
kubectl describe po nginx1
# or if on linux, take advantage of grep
kubectl describe po nginx1 | grep -i "annotations"
Remove the annotations for these three pods
kubectl annotate po nginx1 nginx2 nginx3 description-
# or if on linux
kubectl annotate po nginx{1..3} description-
Remove these pods to have a clean state in your cluster
kubectl delete po nginx1 nginx2 nginx3
# or if on linux
kubectl delete po nginx{1..3}
Services
Create a pod with image nginx called nginx and expose its port 80
kubectl run nginx --image=nginx --restart=Never --port=80 --expose
# observe that a pod as well as a service are created
Confirm that ClusterIP has been created. Also check endpoints
kubectl get svc nginx # services
kubectl get ep # endpoints
Get pod's ClusterIP, create a temp busybox pod and 'hit' that IP with wget
kubectl get svc nginx # get the IP (something like 10.108.93.130)
kubectl run busybox --rm --image=busybox -it --restart=Never -- sh
wget -O- IP:80
exit
Convert the ClusterIP to NodePort and find the NodePort port.
kubectl edit svc nginx
kubectl get svc
Convert the NodePort to LoadBalancer and find the Public IP