当前位置:网站首页>〖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 」即可。
边栏推荐
- Analysis report on business model innovation path and operation status of China's app store industry from 2022 to 2028
- Lua conditional statement
- Market trend report, technical innovation and market forecast of Chinese stump crusher
- 【LeetCode】102. 二叉树的层序遍历
- [890. find and replace mode]
- 启牛帮开通的股票账户是安全可信的吗?
- 【LeetCode】69. Square root of X
- 深度学习-神经网络:卷积的实现方法【直接法(精度没损失)、GEMM(矩阵乘法,精度没损失)、FFT(傅里叶变换,精度有损失)、Winograd(精度有损失)】
- C语言:如何给全局变量起一个别名?
- Global and Chinese Melamine Industry Development Research and prospect trend report 2022-2028
猜你喜欢

设计消息队列存储消息数据的 MySQL 表格

应用最广泛的动态路由协议:OSPF

The annual salary of 500000 is one line, and the annual salary of 1million is another line

Use js to listen for Keydown event

Design a MySQL table for message queue to store message data

Embedded pipeline out of the box

Heilongjiang Branch and Liaoning Branch of PostgreSQL Chinese community have been established!

Huawei officially entered the "front loading" stage, and the millimeter wave radar track entered the "localization +4d" cycle

Opencv source code compilation

Colab tutorial (super detailed version) and colab pro/colab pro+ usage evaluation
随机推荐
ShardingSphere-proxy-5.0.0部署之分表实现(一)
Dix points de défense clés dans les exercices d'attaque et de défense détaillés
web3 原则和去中心化
【LeetCode】209. Minimum length subarray
Theory + practice will help you master the dynamic programming method
项目里面的traceID的设计
Use js to listen for Keydown event
【LeetCode】33. Search rotation sort array
China Aquatic Fitness equipment market trend report, technical innovation and market forecast
MOOG servo valve d634-341c/r40ko2m0nss2
证券开户有风险吗?怎么开户安全呢?
Gb28181 protocol -- alarm
【LeetCode】69. x 的平方根
The annual salary of 500000 is one line, and the annual salary of 1million is another line
Research Report on market supply and demand and strategy of China's digital camera lens industry
应用最广泛的动态路由协议:OSPF
A 42 year old senior executive of a large factory reminds people aged 30-39 that these six habits that make you stronger should be developed as soon as possible
Mysql concat_ws、concat函数使用
Mysql concat_ WS, concat function use
Lua date time