kubectl run nginx1 --image=nginx
pod/nginx1 created
#see Labels
kubectl describe pod nginx1
Name: nginx1
Namespace: default
Priority: 0
Node: minikube-m02/192.168.49.3
Start Time: Mon, 27 Jun 2022 17:35:39 -0700
Labels: run=nginx1
Annotations: <none>
Status: Running
IP: 172.17.0.5
IPs:
IP: 172.17.0.5
Containers:
nginx1:
Container ID: docker://876631db265761b3dbe3170433210257470606f776dff93ffd6 aca3a3ec8b8f9
Image: nginx
Image ID: docker-pullable://nginx@sha256:10f14ffa93f8dedf1057897b745e5 ac72ac5655c299dade0aa434c71557697ea
Port: <none>
Host Port: <none>
State: Running
Started: Mon, 27 Jun 2022 17:35:48 -0700
Ready: True
Restart Count: 0
Environment: <none>
Mounts:
/var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-8ddm2 (ro)
Conditions:
Type Status
Initialized True
Ready True
ContainersReady True
PodScheduled True
Volumes:
kube-api-access-8ddm2:
Type: Projected (a volume that contains injected data fro m multiple sources)
TokenExpirationSeconds: 3607
ConfigMapName: kube-root-ca.crt
ConfigMapOptional: <nil>
DownwardAPI: true
QoS Class: BestEffort
Node-Selectors: <none>
Tolerations: node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal Scheduled 17s default-scheduler Successfully assigned default/ngin x1 to minikube-m02
Normal Pulling 17s kubelet Pulling image "nginx"
Normal Pulled 8s kubelet Successfully pulled image "nginx" in 8.887080516s
Normal Created 8s kubelet Created container nginx1
Normal Started 8s kubelet Started container nginx1
#add label to a pod
kubectl label pod nginx1 envronment=development
pod/nginx1 labeled
kubectl describe pod nginx1 | grep Labels
Labels: envronment=development
kubectl run nginx2 --image=nginx
pod/nginx2 created
kubectl label pod nginx2 envronment=production
pod/nginx2 labeled
kubectl describe pod nginx2 | grep Labels
Labels: envronment=production
kubectl get pods
NAME READY STATUS RESTARTS AGE
nginx1 1/1 Running 0 5m50s
nginx2 1/1 Running 0 36s
kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx1 1/1 Running 0 6m11s envronment=development,run=nginx1
nginx2 1/1 Running 0 57s envronment=production,run=nginx2
kubectl label pod nginx2 projectcode=3344
pod/nginx2 labeled
kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx1 1/1 Running 0 7m envronment=development,run=nginx1
nginx2 1/1 Running 0 106s envronment=production,projectcode=3344,run=nginx2
#remove label
kubectl label pod nginx1 run-
pod/nginx1 unlabeled
kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx1 1/1 Running 0 7m39s envronment=development
nginx2 1/1 Running 0 2m25s envronment=production,projectcode=3344,run=nginx2
kubectl label pod nginx2 run-
pod/nginx2 unlabeled
kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx1 1/1 Running 0 8m3s envronment=development
nginx2 1/1 Running 0 2m49s envronment=production,projectcode=3344
kubectl get pods --show-labels | grep development
nginx1 1/1 Running 0 64m envronment=development
No comments:
Post a Comment