labels 查看路径
[root@k8smaster4 ns]# kubectl explain pod.metadata.labels
查看Pod标签
[root@k8smaster4 ns]# kubectl get pods --show-labels
创建labels的Yaml
[root@k8smaster4 ns]# vi pod-first.yaml
apiVersion: v1
kind: Pod
metadata:
labels:
app: tomcat
app2: tomcat2
name: tomcat-test
namespace: default
spec:
containers:
- name: tomcat-java
images: docker.io/xianchao/tomcat-8.5-jre8
imagePullPolicy: IfNotPresent
ports:
- containerPort: 8080
查看pod的labels
[root@k8smaster4 ns]# kubectl get pods --show-labels
NAME READY STATUS RESTARTS AGE LABELS
tomcat-test 1/1 Running 0 63s app2=tomcat2,app=tomcat
运行的Pod添加标签
[root@k8smaster4 ns]# kubectl label pods tomcat-test release=v1
查看某个Pod的标签
[root@k8smaster4 ns]# kubectl get pods tomcat-test --show-labels
NAME READY STATUS RESTARTS AGE LABELS
tomcat-test 1/1 Running 0 5m43s app2=tomcat2,app=tomcat,release=v1
查看Pod的某个label的key
[root@k8smaster4 ns]# kubectl get pods tomcat-test -L release
NAME READY STATUS RESTARTS AGE RELEASE
tomcat-test 1/1 Running 0 6m40s v1
查看所有命名空间Pod
[root@k8smaster4 ns]# kubectl get pods --all-namespaces --show-labels标签:kubectl,ns,tomcat,labels,k8smaster4,test,k8s,root From: https://blog.51cto.com/u_11726705/5986780