当前位置:网站首页>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
边栏推荐
- PSYNC synchronization of redis source code analysis
- Llvm - generate if else and pH
- Example of time complexity calculation
- asp. Net method of sending mail using mailmessage
- 1990年1月1日是星期一,定义函数date_to_week(year,month,day),实现功能输入年月日后返回星期几,例如date_to_week(2020,11,1),返回:星期日。 提示:
- Explain TCP's three handshakes in detail
- Little red book timestamp2 (2022 / 04 / 22)
- Mds55-16-asemi rectifier module mds55-16
- Basic operation of sequential stack
- Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
猜你喜欢
Detailed explanation of C language knowledge points -- data types and variables [1] - carry counting system
LeetCode167-两数之和II-双指针-二分-数组-查找
[stc8g2k64s4] introduction of comparator and sample program of comparator power down detection
How to upload large files quickly?
如何设计一个良好的API接口?
Explanation and example application of the principle of logistic regression in machine learning
LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
8.2 text preprocessing
Leetcode167 - sum of two numbers II - double pointer - bisection - array - Search
Mysql连接查询详解
随机推荐
C language super complete learning route (collection allows you to avoid detours)
Practice of unified storage technology of oppo data Lake
Llvm - generate for loop
TLS / SSL protocol details (30) RSA, DHE, ecdhe and ecdh processes and differences in SSL
The difference between having and where in SQL
LeetCode162-寻找峰值-二分-数组
What is the role of the full connection layer?
Introduction to dirty reading, unrepeatable reading and phantom reading
Explanation and example application of the principle of logistic regression in machine learning
Detailed comparison between asemi three-phase rectifier bridge and single-phase rectifier bridge
Reptile exercises (1)
win10 任务栏通知区图标不见了
Redis cluster principle
Async void caused the program to crash
Comparaison du menu de l'illustrateur Adobe en chinois et en anglais
填充每个节点的下一个右侧节点指针 II [经典层次遍历 | 视为链表 ]
LeetCode153-寻找旋转排序数组中的最小值-数组-二分查找
eolink 如何助力远程办公
Tencent has written a few words, Ali has written them all for a month
Application of skiplist in leveldb