当前位置:网站首页>Detailed explanation of kubernetes (XI) -- label and label selector
Detailed explanation of kubernetes (XI) -- label and label selector
2022-04-23 15:12:00 【Always a teenager】
Today I will continue to introduce Linux Operation and maintenance related knowledge , The main content of this paper is Kubernetes Tags and tag selectors in .
One 、 Overview of labels and label selectors
( One ) label
stay Kubernetes In the cluster , The tag itself is a key value pair type of data , And can be attached to any resource object , You can specify... When the resource object is created , Or add after the resource object is created . stay Kubernetes In the cluster , A resource object can have multiple tags , Multiple resource objects can also have the same label .
Kubernetes Tags in clusters have strict formats , Its Key The definition of can use letters 、 Numbers and underscores , Hyphens and periods , But it can only start with a character or a number .Value Can be null , You can also use letters 、 Numbers 、 Hyphens and dots , But you must use numbers or letters at the beginning and end .
( Two ) tag chooser
stay Kubernetes In the cluster , The standard selection criteria for tags are .Kubernetes At present, two kinds of label selectors are supported , namely Based on equivalence and Based on set relation The label selector .
Label selector based on equivalence relation There are three kinds of :
“==”、“=” and “!=”, The first two are equal to , The last expression is not equal to
Label selector based on set relation There are four kinds of :
key in (VALUE1,VALUE2,VALUE3……), Indicates that the specified key value exists in the following collection .
key notin (VALUE1,VALUE2,VALUE3……), Indicates that the specified key value does not exist in the following collection .
key, A label indicating the existence of this key name .
!key, A label indicating that this key name does not exist .
The use of tag selectors follows the following logic :
1、 When specifying multiple label selectors at the same time , The logical relationship of these multiple tag selectors is “ And ”.
2、 Using a null tag selector means selecting each resource object .
3、 An empty tag selector cannot select any resources .
Be careful , ad locum , An empty tag selector and a null tag selector have different meanings . An empty label selector means that there is no label selector , A null tag selector means that although there is a tag selector , However, the value of this tag selector is null .
Two 、 Label and label selector related commands
Next , Let me introduce the related commands of tags and tag selectors :
( One ) see Pod The label of the object
We're looking at Pod On the basis of objects , add –show-labels Parameters , You can see Pod The label of the object , for example , Carry out orders :
kubectl get pods --show-labels
You can view the currently running Pod Its label , The execution result of this command is as follows :
besides ,-L Parameters can show Pod The specified label of the object , Carry out orders :
kubectl get pods -L 【 key A】
Can show all of Pod object , Pair containing keys A Labeled Pod Its value will be displayed , Yes, no keys A Labeled Pod Will display as empty .
for example , Carry out orders :
kubectl get pods -L label1,label2
Can display the current Pod Object and its label1 and label2 label , The execution result of this command is as follows :
( Two ) The tag selector filters tags
stay kubectl In command ,-l Parameters can be used as filters for tags , for example , Carry out orders :
kubectl get pods -l label1,label2
The filter can contain both lable1 and label2 Labeled Pod, The execution result of this command is as follows :
( 3、 ... and )Pod Add labels after object creation
We can do it in Pod Object is labeled when it is created , We can also use label Command in Pod Add labels after object creation , The command format is as follows :
kubectl label pods/【Pod name 】 【 Label key 】=【 Label value 】
for example , Carry out orders :
kubectl label pods/pod-demo-test label3=label3
You can give pod-demo-test Of Pod Object to add label3=label3 The label of . The execution result of this command is as follows :
( Four ) modify Pod The label of the object
Except for the already running Pod In addition to adding labels to objects , We can also modify Pod The label of the object . This operation also requires the use of label command , And add... At the end –overwrite The order of . for example , Carry out orders :
kubectl label pods/pod-demo-test label3=modify --overwrite
You can put the Pod The original label3=label3 It is amended as follows label3=modify, The execution result of this command is as follows :
Originality is not easy. , Reprint please explain the source :https://blog.csdn.net/weixin_40228200
版权声明
本文为[Always a teenager]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231507194506.html
边栏推荐
- Difference between like and regexp
- X509 certificate cer format to PEM format
- Analysis of common storage types and FTP active and passive modes
- JS - implémenter la fonction de copie par clic
- How to design a good API interface?
- Kubernetes详解(十一)——标签与标签选择器
- 如何设计一个良好的API接口?
- Leetcode exercise - 396 Rotation function
- adobe illustrator 菜單中英文對照
- Baidu written test 2022.4.12 + programming topic: simple integer problem
猜你喜欢
让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了
Set onedrive or Google drive as a drawing bed in upic for free
分享 20 个不容错过的 ES6 的技巧
1n5408-asemi rectifier diode
8.5 concise implementation of cyclic neural network
My raspberry PI zero 2W tossing notes record some problems encountered and solutions
Role of asemi rectifier module mdq100-16 in intelligent switching power supply
How to use OCR in 5 minutes
Five data types of redis
Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]
随机推荐
UML学习_day2
博睿数据携手F5共同构建金融科技从代码到用户的全数据链DNA
[thymeleaf] handle null values and use safe operators
C language super complete learning route (collection allows you to avoid detours)
Sword finger offer (1) -- for Huawei
Leetcode153 - find the minimum value in the rotation sort array - array - binary search
Error: unable to find remote key "17f718f726"“
Redis master-slave synchronization
For 22 years, you didn't know the file contained vulnerabilities?
JS -- realize click Copy function
When splicing HQL, the new field does not appear in the construction method
PSYNC synchronization of redis source code analysis
Little red book timestamp2 (2022 / 04 / 22)
Five data types of redis
X509 certificate cer format to PEM format
redis-shake 使用中遇到的错误整理
async关键字
Introduction to dirty reading, unrepeatable reading and phantom reading
My raspberry PI zero 2W tossing notes record some problems encountered and solutions
分享3个使用工具,在家剪辑5个作品挣了400多