实战生产环境:最新K8s Lables详解
本篇文章,所使用的任何镜像我都会发一个网盘链接,供大家下载学习!
yaml 请到我的github上下载学习!
github:https://github.com/heyangguang
有任何问题可以直接联系我的Email:[email protected]
Labels官网
https://kubernetes.io/docs/co...
Labels介绍
字面意思就是标签,也就是给我们不同的Pod或者Controller等打上不同的标签,从而实现以下功能:
- 标示元信息
- Controller 和 Service 可通过 label selector 控制 Pod 生命周期
- 对调度产生影响
Lables查看
[root@master01 ~]# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS master01 Ready master 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/master= node01 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,node-role.kubernetes.io/work= node02 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,node-role.kubernetes.io/work=
Lables创建
请记住,标签的格式是<Key: Value>格式,Key对于给定的值必须是唯一的。
1、使用yaml给Pod创建标签
[root@master01 ~]# cat pod-labels.yaml apiVersion: v1 kind: Pod metadata: name: label-demo labels: environment: production app: nginx spec: containers: - name: nginx image: nginx:1.7.9 ports: - containerPort: 80 [root@master01 ~]# kubectl apply -f pod-labels.yaml pod/label-demo created [root@master01 ~]# kubectl get pods --show-labels NAME READY STATUS RESTARTS AGE LABELS label-demo 1/1 Running 0 65s app=nginx,environment=production
2、使用命令行创建标签
[root@master01 ~]# kubectl get nodes --show-labels NAME STATUS ROLES AGE VERSION LABELS master01 Ready master 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master01,kubernetes.io/os=linux,node-role.kubernetes.io/master= node01 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,node-role.kubernetes.io/work= node02 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node02,kubernetes.io/os=linux,node-role.kubernetes.io/work= [root@master01 ~]# kubectl label nodes node01 disktype=ssd node/node01 labeled [root@master01 ~]# kubectl get nodes node01 --show-labels NAME STATUS ROLES AGE VERSION LABELS node01 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,disktype=ssd,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,node-role.kubernetes.io/work=
Lables删除
[root@master01 ~]# kubectl label nodes node01 disktype- node/node01 labeled [root@master01 ~]# kubectl get nodes node01 --show-labels NAME STATUS ROLES AGE VERSION LABELS node01 Ready work 11h v1.15.2 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=node01,kubernetes.io/os=linux,node-role.kubernetes.io/work=
相关推荐
kunyus 2020-10-28
hubanbei00的家园 2020-10-25
btqszl 2020-10-21
shurenyun 2020-08-19
CurrentJ 2020-08-18
远远的山 2020-11-09
kaidiphp 2020-10-13
JustHaveTry 2020-09-29
cloudvtech 2020-09-18
BigDataMining 2020-08-21
朱培知浅ZLH 2020-11-16
cdbdqn00 2020-11-12
达观数据 2020-11-11
JustinChia 2020-11-11
jingtao 2020-11-08
大叔比较胖 2020-10-30
gracecxj 2020-10-30
onepiecedn 2020-10-29
JustHaveTry 2020-10-27