当前位置:网站首页>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: {
}
边栏推荐
- com. alibaba. nacos. api. exception. NacosException
- Another company raised the price of SAIC Roewe new energy products from March 1
- What is Gibson's law?
- selenium IDE插件下载安装使用教程
- Selenium ide plug-in download, installation and use tutorial
- 金盾视频播放器拦截的软件关键词和进程信息
- leetcode825. Age appropriate friends
- Mysql 45讲学习笔记(七)行锁
- tars源码分析之6
- How to input single quotation marks and double quotation marks in latex?
猜你喜欢
Selenium ide plug-in download, installation and use tutorial
Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
Industrial computer anti-virus
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
CMS source code of multi wechat management system developed based on thinkphp6, with one click curd and other functions
【问题记录】03 连接MySQL数据库提示:1040 Too many connections
校园网络问题
centos8安装mysql.7 无法开机启动
Introduction to spark core components
Deep understanding of redis -- a new type of bitmap / hyperloglgo / Geo
随机推荐
C # symmetric encryption (AES encryption) ciphertext results generated each time, different ideas, code sharing
regular expression
[FPGA tutorial case 8] design and implementation of frequency divider based on Verilog
Wechat applet scroll view component scrollable view area
Campus network problems
tars源码分析之8
Crawler (III) crawling house prices in Tianjin
Download kicad on Alibaba cloud image station
Selection (022) - what is the output of the following code?
在已經知道錶格列勾選一個顯示一列
移动适配:vw/vh
What is tweeman's law?
Latex中的单引号,双引号如何输入?
JS common time processing functions
云Redis 有什么用? 云redis怎么用?
MySQL 45 lecture learning notes (VI) global lock
Cervical vertebra, beriberi
Redis面试题集
[FPGA tutorial case 7] design and implementation of counter based on Verilog
The sorting in C language realizes the number sorting method from small to large