当前位置:网站首页>kubernetes集群之Label管理
kubernetes集群之Label管理
2022-07-04 06:56:00 【江湖有缘】
kubernetes集群之Label管理
一、Label介绍
1.标签是k8s特色的管理方式,便于分类管理资源对象。
2.一个标签可以对应多个资源,一个资源也可以有多个标签,它们是多对多的关系。
3.一种特殊的资源对象,必须附件在具体的资源对象之上,用于标识资源对象的用途。
4. 一个资源拥有多个标签,可以实现不同维度的管理。
二、检查本地k8s集群状态
[[email protected]-master ~]# kubectl get nodes -owide
NAME STATUS ROLES AGE VERSION INTERNAL-IP EXTERNAL-IP OS-IMAGE KERNEL-VERSION CONTAINER-RUNTIME
k8s-master Ready control-plane,master 18h v1.23.1 192.168.3.201 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node01 Ready <none> 18h v1.23.1 192.168.3.202 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
k8s-node02 Ready <none> 18h v1.23.1 192.168.3.203 <none> CentOS Linux 7 (Core) 3.10.0-957.el7.x86_64 containerd://1.6.6
三、Label的创建
1.给工作节点新增标签
[[email protected]-master ~]# kubectl label nodes k8s-node02 fun=work02
node/k8s-node02 labeled
2.给pod打上标签
[[email protected]-master ~]# kubectl label pod cirror-28253 fun=ittest
pod/cirror-28253 labeled
[[email protected]-master ~]# kubectl label pod cirror-28253 env=proc
pod/cirror-28253 labeled
3.给工作节点打上角色标签
[[email protected]-master ~]# kubectl label nodes k8s-node01 node-role.kubernetes.io/worker=
node/k8s-node01 labeled
四、Label的修改
修改标签
[[email protected]-master ~]# kubectl label nodes k8s-node02 fun=node02 --overwrite
node/k8s-node02 labeled
五、Label的查询
1.列出节点的所有标签
[[email protected]-master ~]# kubectl get nodes --show-labels
NAME STATUS ROLES AGE VERSION LABELS
k8s-master Ready control-plane,master 18h v1.23.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node-role.kubernetes.io/master=,node.kubernetes.io/exclude-from-external-load-balancers=
k8s-node01 Ready worker 18h v1.23.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node01,kubernetes.io/os=linux,node-role.kubernetes.io/worker=
k8s-node02 Ready <none> 18h v1.23.1 beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,fun=node02,kubernetes.io/arch=amd64,kubernetes.io/hostname=k8s-node02,kubernetes.io/os=linux,type=dell730
2.查询带有worker角色的节点
[[email protected]-master ~]# kubectl get nodes -l node-role.kubernetes.io/worker
NAME STATUS ROLES AGE VERSION
k8s-node01 Ready worker 18h v1.23.1
3.查询带有type标签的节点
[[email protected]-master ~]# kubectl get nodes -l type
NAME STATUS ROLES AGE VERSION
k8s-node02 Ready <none> 18h v1.23.1
六、Label的删除
[[email protected]-master ~]# kubectl label nodes k8s-node02 fun-
node/k8s-node02 unlabeled
[[email protected]-master ~]# kubectl get node -l fun
No resources found
七、kubernetes注解使用
1.给工作节点添加注解
[[email protected]-master ~]# kubectl annotate nodes k8s-node01 test="this is a work node"
node/k8s-node01 annotated
2.查看注解
[[email protected]-master ~]# kubectl describe nodes k8s-node01 |grep test
test: this is a work node
3.修改注解
kubectl annotate nodes k8s-node01 test=11 --overwrite
4.删除注解
kubectl annotate nodes k8s-node01 test-
八、在yaml脚本的标签使用
[[email protected]-master ~]# kubectl run web01 --image=nginx:1.21 -n k8s-test -o yaml --dry-run=client
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: null
labels:
run: web01
name: web01
namespace: k8s-test
spec:
containers:
- image: nginx:1.21
name: web01
resources: {
}
dnsPolicy: ClusterFirst
restartPolicy: Always
status: {
}
边栏推荐
- How notepad++ counts words
- What is industrial computer encryption and how to do it
- Redis interview question set
- The sorting in C language realizes the number sorting method from small to large
- tars源码分析之1
- 图的底部问题
- What is the "relative dilemma" in cognitive fallacy?
- What is a spotlight effect?
- Knowledge payment applet dream vending machine V2
- leetcode825. Age appropriate friends
猜你喜欢
[backpack DP] backpack problem
移动适配:vw/vh
响应式移动Web测试题
Industrial computer anti-virus
selenium驱动IE常见问题解决Message: Currently focused window has been closed.
Mysql 45讲学习笔记(七)行锁
selenium IDE插件下载安装使用教程
Selenium driver ie common problem solving message: currently focused window has been closed
Responsive - media query
Uniapp applet subcontracting
随机推荐
If there are two sources in the same job, it will be reported that one of the databases cannot be found. Is there a boss to answer
Selenium ide plug-in download, installation and use tutorial
[MySQL] introduction, function, creation, view, deletion and modification of database view (with exercises)
P26-P34 third_ template
tars源码分析之4
Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
The sorting in C language realizes the number sorting method from small to large
Lottery system test report
How notepad++ counts words
Summary of leetcode BFS question brushing
[Valentine's day] - you can change your love and write down your lover's name
抽奖系统测试报告
【FPGA教程案例8】基于verilog的分频器设计与实现
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
What is the use of cloud redis? How to use cloud redis?
Can the out of sequence message complete TCP three handshakes
regular expression
[network data transmission] FPGA based development of 100M / Gigabit UDP packet sending and receiving system, PC to FPGA
selenium IDE插件下载安装使用教程
同一个job有两个source就报其中一个数据库找不到,有大佬回答下吗