本篇文章,所使用的任何镜像我都会发一个网盘链接,供大家下载学习!
yaml 请到我的github上下载学习!
github:https://github.com/heyangguang
有任何问题可以直接联系我的Email:heyangev@cn.ibm.com
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=
有疑问加站长微信联系(非本文作者)