当前位置:网站首页>〖Kubernetes指南⑤〗Label快速入门
〖Kubernetes指南⑤〗Label快速入门
2022-06-12 23:05:00 【步尔斯特】
Label
Label是kubernetes系统中的一个重要概念。它的作用就是在资源上添加标识,用来对它们进行区分和选择。
Label的特点:
- 一个Label会以key/value键值对的形式附加到各种对象上,如Node、Pod、Service等等
- 一个资源对象可以定义任意数量的Label ,同一个Label也可以被添加到任意数量的资源对象上去
- Label通常在资源对象定义时确定,当然也可以在对象创建后动态添加或者删除
可以通过Label实现资源的多维度分组,以便灵活、方便地进行资源分配、调度、配置、部署等管理工作。
一些常用的Label 示例如下:
- 版本标签:“version”:“release”, “version”:“stable”…
- 环境标签:“environment”:“dev”,“environment”:“test”,“environment”:“pro”
- 架构标签:“tier”:“frontend”,“tier”:“backend”
标签定义完毕之后,还要考虑到标签的选择,这就要使用到Label Selector,即:
Label用于给某个资源对象定义标识
Label Selector用于查询和筛选拥有某些标签的资源对象
当前有两种Label Selector:
基于等式的Label Selector
name = slave: 选择所有包含Label中key="name"且value="slave"的对象
env != production: 选择所有包括Label中的key="env"且value不等于"production"的对象
基于集合的Label Selector
name in (master, slave): 选择所有包含Label中的key="name"且value="master"或"slave"的对象
name not in (frontend): 选择所有包含Label中的key="name"且value不等于"frontend"的对象
标签的选择条件可以使用多个,此时将多个Label Selector进行组合,使用逗号","进行分隔即可。例如:
name=slave,env!=production
name not in (frontend),env!=production
命令方式
# 为pod资源打标签
[[email protected] ~]# kubectl label pod nginx-pod version=1.0 -n dev
pod/nginx-pod labeled
# 为pod资源更新标签
[[email protected] ~]# kubectl label pod nginx-pod version=2.0 -n dev --overwrite
pod/nginx-pod labeled
# 查看标签
[[email protected] ~]# kubectl get pod nginx-pod -n dev --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx-pod 1/1 Running 0 10m version=2.0
# 筛选标签
[[email protected] ~]# kubectl get pod -n dev -l version=2.0 --show-labels
NAME READY STATUS RESTARTS AGE LABELS
nginx-pod 1/1 Running 0 17m version=2.0
[[email protected] ~]# kubectl get pod -n dev -l version!=2.0 --show-labels
No resources found in dev namespace.
#删除标签
[[email protected] ~]# kubectl label pod nginx-pod version- -n dev
pod/nginx-pod labeled
配置方式
apiVersion: v1
kind: Pod
metadata:
name: nginx
namespace: dev
labels:
version: "3.0"
env: "test"
spec:
containers:
- image: nginx:latest
name: pod
ports:
- name: nginx-port
containerPort: 80
protocol: TCP
然后就可以执行对应的更新命令了:kubectl apply -f pod-nginx.yaml
《核心技术系列专栏汇总》
需要 大厂面试题、简历模版、电子书、学习资料 等关注【公众号】回复「 1024 」即可。
边栏推荐
- The most widely used dynamic routing protocol: OSPF
- Market trend report, technical innovation and market forecast of Chinese stump crusher
- Mysql case when then函数使用
- Introduction to Quaternion
- Research and Analysis on the development of China's Melamine Industry from 2022 to 2028 and market prospect forecast report
- MySQL基础篇视图的总结
- Module 8 operation
- [leetcode] the k-largest element in the array
- Is it safe to open an account for flush stock account
- Abstract methods and abstract classes
猜你喜欢

web3 原则和去中心化

Design a MySQL table for message queue to store message data

OpenCV源代码编译

iShot

ASP. Net core Middleware

Colab教程(超级详细版)及Colab Pro/Colab Pro+使用评测

The development trend of digital collections!

模型过拟合-解决方案(二):Dropout
![[Part VI] source code analysis and application details of countdownlatch [key]](/img/6e/085e257c938a8c7b88c12c36df83e1.jpg)
[Part VI] source code analysis and application details of countdownlatch [key]

Shardingsphere-proxy-5.0.0 deployment table implementation (I)
随机推荐
Embedded pipeline out of the box
Introduction to Quaternion
Design a MySQL table for message queue to store message data
【LeetCode】53.最大子数组和
Zabbix的功能介绍和常用术语
Gb28181 protocol -- alarm
Module 8 operation
China's new generation information technology industry "14th five year plan" special planning and innovation strategic direction report 2022 ~ 2028
【890. 查找和替换模式】
基于51单片机的酒精检测仪
PHP deletes data of the same item in a two-dimensional array
PHP删除二维数组中相同项的数据
Colab教程(超级详细版)及Colab Pro/Colab Pro+使用评测
Is there any risk in opening a securities account? How to open an account safely?
Deep learning neural network: implementation method of convolution [direct method (no loss of precision), GEMM (matrix multiplication, no loss of precision), FFT (Fourier transform, loss of precision)
Function introduction and common terms of ZABBIX
C language: how to give an alias to a global variable?
Shardingsphere-proxy-5.0.0 deployment table implementation (I)
Global and Chinese Melamine Industry Development Research and prospect trend report 2022-2028
InfoQ geek media's 15th anniversary solicitation | brief introduction to the four challenges of building a micro service architecture