当前位置:网站首页>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: {
}
边栏推荐
- 【网络数据传输】基于FPGA的百兆网/兆网千UDP数据包收发系统开发,PC到FPGA
- GoogleChromePortable 谷歌chrome浏览器便携版官网下载方式
- Lottery system test report
- Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
- Shopping malls, storerooms, flat display, user-defined maps can also be played like this!
- Data analysis notes 09
- Selection (022) - what is the output of the following code?
- tars源码分析之6
- what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
- C # symmetric encryption (AES encryption) ciphertext results generated each time, different ideas, code sharing
猜你喜欢
The important role of host reinforcement concept in medical industry
Common usage of time library
Responsive mobile web test questions
centos8安装mysql.7 无法开机启动
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
Industrial computer anti-virus
Crawler (III) crawling house prices in Tianjin
Deep profile data leakage prevention scheme
The final week, I split
[Valentine's day] - you can change your love and write down your lover's name
随机推荐
How to share the source code anti disclosure scheme
What is the "relative dilemma" in cognitive fallacy?
Since DMS is upgraded to a new version, my previous SQL is in the old version of DMS. In this case, how can I retrieve my previous SQL?
ABCD four sequential execution methods, extended application
Software keywords and process information intercepted by Golden Shield video player
Tar source code analysis Part 7
2022, peut - être la meilleure année économique de la prochaine décennie, avez - vous obtenu votre diplôme en 2022? Comment est - ce prévu après la remise des diplômes?
Knowledge payment applet dream vending machine V2
Mobile adaptation: vw/vh
Uniapp custom environment variables
Latex中的单引号,双引号如何输入?
selenium驱动IE常见问题解决Message: Currently focused window has been closed.
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
notepad++如何统计单词数量
leetcode825. 适龄的朋友
Cochez une colonne d'affichage dans une colonne de tableau connue
MySQL 45 lecture learning notes (12) MySQL will "shake" for a while
Bottom problem of figure
js 常用时间处理函数