当前位置:网站首页>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: {
}
边栏推荐
猜你喜欢
Deep profile data leakage prevention scheme
[network data transmission] FPGA based development of 100M / Gigabit UDP packet sending and receiving system, PC to FPGA
Uniapp custom environment variables
Another company raised the price of SAIC Roewe new energy products from March 1
List of top ten professional skills required for data science work
selenium IDE插件下载安装使用教程
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
Selenium driver ie common problem solving message: currently focused window has been closed
Variables d'environnement personnalisées uniapp
[Valentine's day] - you can change your love and write down your lover's name
随机推荐
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
【问题记录】03 连接MySQL数据库提示:1040 Too many connections
Summary of leetcode BFS question brushing
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
Data analysis notes 09
Selection (023) - what are the three stages of event propagation?
C # symmetric encryption (AES encryption) ciphertext results generated each time, different ideas, code sharing
移动适配:vw/vh
[backpack DP] backpack problem
Tar source code analysis 9
tars源码分析之6
Fundamentals of SQL database operation
Download kicad on Alibaba cloud image station
How does the inner roll break?
[FPGA tutorial case 8] design and implementation of frequency divider based on Verilog
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
Common usage of time library
Set JTAG fuc invalid to normal IO port
高薪程序员&面试题精讲系列119之Redis如何实现分布式锁?
由于dms升级为了新版,我之前的sql在老版本的dms中,这种情况下,如何找回我之前的sql呢?