一, 创建 POD 时指定相应标签
二, 通过标签查看 POD
- [[email protected] ~]# kubectl get pod --show-labels -n test #查看所有 pod 的标签
- NAME READY STATUS RESTARTS AGE LABELS
- kubia-manual 1/1 Running 0 47h App=web_test,env=prod
- nginx-dp-856666d759-bfrgj 1/1 Running 0 3d9h App=nginx-proxy,env=test,pod-template-hash=856666d759
- nginx-dp-856666d759-c5p4l 1/1 Running 0 3d9h App=nginx-proxy,env=test,pod-template-hash=856666d759
- [[email protected] ~]# kubectl get pod -l env=prod -n test #查看 env=prod 的标签
- NAME READY STATUS RESTARTS AGE
- kubia-manual 1/1 Running 0 47h
三, 修改 POD 标签的属性
- [[email protected] ~]# kubectl get pod -l env=prod -n test
- NAME READY STATUS RESTARTS AGE
- kubia-manual 1/1 Running 0 47h
- [[email protected] ~]# kubectl label pod kubia-manual env=debug --overwrite -n test
- pod/kubia-manual labeled
- [[email protected] ~]# kubectl get pod --show-labels -n test | grep env=debug
- kubia-manual 1/1 Running 0 47h App=web_test,env=debug
四, 为现有 POD 添加一个标签
- [[email protected] ~]# kubectl label pod kubia-manual mingkang_test=test -n test
- pod/kubia-manual labeled
- [[email protected] ~]# kubectl get pod --show-labels -n test | grep kubia-manual
- kubia-manual 1/1 Running 0 47h App=web_test,env=debug,mingkang_test=test
五, 通过 POD 标签, 固定到某个 NODE 上
- apiVersion: v1
- kind: Pod
- metadata:
- name: kubia-manual
- namespace: test
- labels:
- App: web_html
- env: prod
- spec:
- nodeSelector: #节点标签选择器
- gpu: true #gpu 为 true 的节点
- containers:
- - name: kubia
- image: luksa/kubia
- ports:
- - containerPort: 8080
- protocol: TCP
来源: http://www.bubuko.com/infodetail-3486491.html