Skip to content

Commit 60a4446

Browse files
committed
Tweak line wrappings in labels.md
1 parent e9b4412 commit 60a4446

File tree

1 file changed

+106
-48
lines changed
  • content/en/docs/concepts/overview/working-with-objects

1 file changed

+106
-48
lines changed

content/en/docs/concepts/overview/working-with-objects/labels.md

Lines changed: 106 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ weight: 40
99
<!-- overview -->
1010

1111
_Labels_ are key/value pairs that are attached to objects, such as pods.
12-
Labels are intended to be used to specify identifying attributes of objects that are meaningful and relevant to users, but do not directly imply semantics to the core system.
13-
Labels can be used to organize and to select subsets of objects. Labels can be attached to objects at creation time and subsequently added and modified at any time.
14-
Each object can have a set of key/value labels defined. Each Key must be unique for a given object.
12+
Labels are intended to be used to specify identifying attributes of objects
13+
that are meaningful and relevant to users, but do not directly imply semantics
14+
to the core system. Labels can be used to organize and to select subsets of
15+
objects. Labels can be attached to objects at creation time and subsequently
16+
added and modified at any time. Each object can have a set of key/value labels
17+
defined. Each Key must be unique for a given object.
1518

1619
```json
1720
"metadata": {
@@ -30,37 +33,56 @@ and CLIs. Non-identifying information should be recorded using
3033

3134
## Motivation
3235

33-
Labels enable users to map their own organizational structures onto system objects in a loosely coupled fashion, without requiring clients to store these mappings.
36+
Labels enable users to map their own organizational structures onto system objects
37+
in a loosely coupled fashion, without requiring clients to store these mappings.
3438

35-
Service deployments and batch processing pipelines are often multi-dimensional entities (e.g., multiple partitions or deployments, multiple release tracks, multiple tiers, multiple micro-services per tier). Management often requires cross-cutting operations, which breaks encapsulation of strictly hierarchical representations, especially rigid hierarchies determined by the infrastructure rather than by users.
39+
Service deployments and batch processing pipelines are often multi-dimensional entities
40+
(e.g., multiple partitions or deployments, multiple release tracks, multiple tiers,
41+
multiple micro-services per tier). Management often requires cross-cutting operations,
42+
which breaks encapsulation of strictly hierarchical representations, especially rigid
43+
hierarchies determined by the infrastructure rather than by users.
3644

3745
Example labels:
3846

39-
* `"release" : "stable"`, `"release" : "canary"`
40-
* `"environment" : "dev"`, `"environment" : "qa"`, `"environment" : "production"`
41-
* `"tier" : "frontend"`, `"tier" : "backend"`, `"tier" : "cache"`
42-
* `"partition" : "customerA"`, `"partition" : "customerB"`
43-
* `"track" : "daily"`, `"track" : "weekly"`
47+
* `"release" : "stable"`, `"release" : "canary"`
48+
* `"environment" : "dev"`, `"environment" : "qa"`, `"environment" : "production"`
49+
* `"tier" : "frontend"`, `"tier" : "backend"`, `"tier" : "cache"`
50+
* `"partition" : "customerA"`, `"partition" : "customerB"`
51+
* `"track" : "daily"`, `"track" : "weekly"`
4452

45-
These are examples of [commonly used labels](/docs/concepts/overview/working-with-objects/common-labels/); you are free to develop your own conventions. Keep in mind that label Key must be unique for a given object.
53+
These are examples of
54+
[commonly used labels](/docs/concepts/overview/working-with-objects/common-labels/);
55+
you are free to develop your own conventions.
56+
Keep in mind that label Key must be unique for a given object.
4657

4758
## Syntax and character set
4859

49-
_Labels_ are key/value pairs. Valid label keys have two segments: an optional prefix and name, separated by a slash (`/`). The name segment is required and must be 63 characters or less, beginning and ending with an alphanumeric character (`[a-z0-9A-Z]`) with dashes (`-`), underscores (`_`), dots (`.`), and alphanumerics between. The prefix is optional. If specified, the prefix must be a DNS subdomain: a series of DNS labels separated by dots (`.`), not longer than 253 characters in total, followed by a slash (`/`).
60+
_Labels_ are key/value pairs. Valid label keys have two segments: an optional
61+
prefix and name, separated by a slash (`/`). The name segment is required and
62+
must be 63 characters or less, beginning and ending with an alphanumeric
63+
character (`[a-z0-9A-Z]`) with dashes (`-`), underscores (`_`), dots (`.`),
64+
and alphanumerics between. The prefix is optional. If specified, the prefix
65+
must be a DNS subdomain: a series of DNS labels separated by dots (`.`),
66+
not longer than 253 characters in total, followed by a slash (`/`).
5067

51-
If the prefix is omitted, the label Key is presumed to be private to the user. Automated system components (e.g. `kube-scheduler`, `kube-controller-manager`, `kube-apiserver`, `kubectl`, or other third-party automation) which add labels to end-user objects must specify a prefix.
68+
If the prefix is omitted, the label Key is presumed to be private to the user.
69+
Automated system components (e.g. `kube-scheduler`, `kube-controller-manager`,
70+
`kube-apiserver`, `kubectl`, or other third-party automation) which add labels
71+
to end-user objects must specify a prefix.
5272

53-
The `kubernetes.io/` and `k8s.io/` prefixes are [reserved](/docs/reference/labels-annotations-taints/) for Kubernetes core components.
73+
The `kubernetes.io/` and `k8s.io/` prefixes are
74+
[reserved](/docs/reference/labels-annotations-taints/) for Kubernetes core components.
5475

5576
Valid label value:
77+
5678
* must be 63 characters or less (can be empty),
5779
* unless empty, must begin and end with an alphanumeric character (`[a-z0-9A-Z]`),
5880
* could contain dashes (`-`), underscores (`_`), dots (`.`), and alphanumerics between.
5981

60-
For example, here's the configuration file for a Pod that has two labels `environment: production` and `app: nginx` :
82+
For example, here's the configuration file for a Pod that has two labels
83+
`environment: production` and `app: nginx`:
6184

6285
```yaml
63-
6486
apiVersion: v1
6587
kind: Pod
6688
metadata:
@@ -74,43 +96,53 @@ spec:
7496
image: nginx:1.14.2
7597
ports:
7698
- containerPort: 80
77-
7899
```
79100
80101
## Label selectors
81102
82-
Unlike [names and UIDs](/docs/concepts/overview/working-with-objects/names/), labels do not provide uniqueness. In general, we expect many objects to carry the same label(s).
103+
Unlike [names and UIDs](/docs/concepts/overview/working-with-objects/names/), labels
104+
do not provide uniqueness. In general, we expect many objects to carry the same label(s).
83105
84-
Via a _label selector_, the client/user can identify a set of objects. The label selector is the core grouping primitive in Kubernetes.
106+
Via a _label selector_, the client/user can identify a set of objects.
107+
The label selector is the core grouping primitive in Kubernetes.
85108
86109
The API currently supports two types of selectors: _equality-based_ and _set-based_.
87-
A label selector can be made of multiple _requirements_ which are comma-separated. In the case of multiple requirements, all must be satisfied so the comma separator acts as a logical _AND_ (`&&`) operator.
110+
A label selector can be made of multiple _requirements_ which are comma-separated.
111+
In the case of multiple requirements, all must be satisfied so the comma separator
112+
acts as a logical _AND_ (`&&`) operator.
88113

89114
The semantics of empty or non-specified selectors are dependent on the context,
90115
and API types that use selectors should document the validity and meaning of
91116
them.
92117

93118
{{< note >}}
94-
For some API types, such as ReplicaSets, the label selectors of two instances must not overlap within a namespace, or the controller can see that as conflicting instructions and fail to determine how many replicas should be present.
119+
For some API types, such as ReplicaSets, the label selectors of two instances must
120+
not overlap within a namespace, or the controller can see that as conflicting
121+
instructions and fail to determine how many replicas should be present.
95122
{{< /note >}}
96123

97124
{{< caution >}}
98-
For both equality-based and set-based conditions there is no logical _OR_ (`||`) operator. Ensure your filter statements are structured accordingly.
125+
For both equality-based and set-based conditions there is no logical _OR_ (`||`) operator.
126+
Ensure your filter statements are structured accordingly.
99127
{{< /caution >}}
100128

101129
### _Equality-based_ requirement
102130

103-
_Equality-_ or _inequality-based_ requirements allow filtering by label keys and values. Matching objects must satisfy all of the specified label constraints, though they may have additional labels as well.
104-
Three kinds of operators are admitted `=`,`==`,`!=`. The first two represent _equality_ (and are synonyms), while the latter represents _inequality_. For example:
131+
_Equality-_ or _inequality-based_ requirements allow filtering by label keys and values.
132+
Matching objects must satisfy all of the specified label constraints, though they may
133+
have additional labels as well. Three kinds of operators are admitted `=`,`==`,`!=`.
134+
The first two represent _equality_ (and are synonyms), while the latter represents _inequality_.
135+
For example:
105136

106137
```
107138
environment = production
108139
tier != frontend
109140
```
110141

111142
The former selects all resources with key equal to `environment` and value equal to `production`.
112-
The latter selects all resources with key equal to `tier` and value distinct from `frontend`, and all resources with no labels with the `tier` key.
113-
One could filter for resources in `production` excluding `frontend` using the comma operator: `environment=production,tier!=frontend`
143+
The latter selects all resources with key equal to `tier` and value distinct from `frontend`,
144+
and all resources with no labels with the `tier` key. One could filter for resources in `production`
145+
excluding `frontend` using the comma operator: `environment=production,tier!=frontend`
114146

115147
One usage scenario for equality-based label requirement is for Pods to specify
116148
node selection criteria. For example, the sample Pod below selects nodes with
@@ -134,7 +166,9 @@ spec:
134166

135167
### _Set-based_ requirement
136168

137-
_Set-based_ label requirements allow filtering keys according to a set of values. Three kinds of operators are supported: `in`,`notin` and `exists` (only the key identifier). For example:
169+
_Set-based_ label requirements allow filtering keys according to a set of values.
170+
Three kinds of operators are supported: `in`,`notin` and `exists` (only the key identifier).
171+
For example:
138172

139173
```
140174
environment in (production, qa)
@@ -143,27 +177,38 @@ partition
143177
!partition
144178
```
145179

146-
* The first example selects all resources with key equal to `environment` and value equal to `production` or `qa`.
147-
* The second example selects all resources with key equal to `tier` and values other than `frontend` and `backend`, and all resources with no labels with the `tier` key.
148-
* The third example selects all resources including a label with key `partition`; no values are checked.
149-
* The fourth example selects all resources without a label with key `partition`; no values are checked.
150-
151-
Similarly the comma separator acts as an _AND_ operator. So filtering resources with a `partition` key (no matter the value) and with `environment` different than  `qa` can be achieved using `partition,environment notin (qa)`.
152-
The _set-based_ label selector is a general form of equality since `environment=production` is equivalent to `environment in (production)`; similarly for `!=` and `notin`.
153-
154-
_Set-based_ requirements can be mixed with _equality-based_ requirements. For example: `partition in (customerA, customerB),environment!=qa`.
155-
180+
- The first example selects all resources with key equal to `environment` and value
181+
equal to `production` or `qa`.
182+
- The second example selects all resources with key equal to `tier` and values other
183+
than `frontend` and `backend`, and all resources with no labels with the `tier` key.
184+
- The third example selects all resources including a label with key `partition`;
185+
no values are checked.
186+
- The fourth example selects all resources without a label with key `partition`;
187+
no values are checked.
188+
189+
Similarly the comma separator acts as an _AND_ operator. So filtering resources
190+
with a `partition` key (no matter the value) and with `environment` different
191+
than `qa` can be achieved using `partition,environment notin (qa)`.
192+
The _set-based_ label selector is a general form of equality since
193+
`environment=production` is equivalent to `environment in (production)`;
194+
similarly for `!=` and `notin`.
195+
196+
_Set-based_ requirements can be mixed with _equality-based_ requirements.
197+
For example: `partition in (customerA, customerB),environment!=qa`.
156198

157199
## API
158200

159201
### LIST and WATCH filtering
160202

161-
LIST and WATCH operations may specify label selectors to filter the sets of objects returned using a query parameter. Both requirements are permitted (presented here as they would appear in a URL query string):
203+
LIST and WATCH operations may specify label selectors to filter the sets of objects
204+
returned using a query parameter. Both requirements are permitted
205+
(presented here as they would appear in a URL query string):
162206

163-
* _equality-based_ requirements: `?labelSelector=environment%3Dproduction,tier%3Dfrontend`
164-
* _set-based_ requirements: `?labelSelector=environment+in+%28production%2Cqa%29%2Ctier+in+%28frontend%29`
207+
* _equality-based_ requirements: `?labelSelector=environment%3Dproduction,tier%3Dfrontend`
208+
* _set-based_ requirements: `?labelSelector=environment+in+%28production%2Cqa%29%2Ctier+in+%28frontend%29`
165209

166-
Both label selector styles can be used to list or watch resources via a REST client. For example, targeting `apiserver` with `kubectl` and using _equality-based_ one may write:
210+
Both label selector styles can be used to list or watch resources via a REST client.
211+
For example, targeting `apiserver` with `kubectl` and using _equality-based_ one may write:
167212

168213
```shell
169214
kubectl get pods -l environment=production,tier=frontend
@@ -175,7 +220,8 @@ or using _set-based_ requirements:
175220
kubectl get pods -l 'environment in (production),tier in (frontend)'
176221
```
177222

178-
As already mentioned _set-based_ requirements are more expressive.  For instance, they can implement the _OR_ operator on values:
223+
As already mentioned _set-based_ requirements are more expressive.
224+
For instance, they can implement the _OR_ operator on values:
179225

180226
```shell
181227
kubectl get pods -l 'environment in (production, qa)'
@@ -196,23 +242,28 @@ also use label selectors to specify sets of other resources, such as
196242

197243
#### Service and ReplicationController
198244

199-
The set of pods that a `service` targets is defined with a label selector. Similarly, the population of pods that a `replicationcontroller` should manage is also defined with a label selector.
245+
The set of pods that a `service` targets is defined with a label selector.
246+
Similarly, the population of pods that a `replicationcontroller` should
247+
manage is also defined with a label selector.
200248

201-
Labels selectors for both objects are defined in `json` or `yaml` files using maps, and only _equality-based_ requirement selectors are supported:
249+
Labels selectors for both objects are defined in `json` or `yaml` files using maps,
250+
and only _equality-based_ requirement selectors are supported:
202251

203252
```json
204253
"selector": {
205254
"component" : "redis",
206255
}
207256
```
257+
208258
or
209259

210260
```yaml
211261
selector:
212262
component: redis
213263
```
214264

215-
this selector (respectively in `json` or `yaml` format) is equivalent to `component=redis` or `component in (redis)`.
265+
This selector (respectively in `json` or `yaml` format) is equivalent to
266+
`component=redis` or `component in (redis)`.
216267

217268
#### Resources that support set-based requirements
218269

@@ -231,12 +282,19 @@ selector:
231282
- {key: environment, operator: NotIn, values: [dev]}
232283
```
233284

234-
`matchLabels` is a map of `{key,value}` pairs. A single `{key,value}` in the `matchLabels` map is equivalent to an element of `matchExpressions`, whose `key` field is "key", the `operator` is "In", and the `values` array contains only "value". `matchExpressions` is a list of pod selector requirements. Valid operators include In, NotIn, Exists, and DoesNotExist. The values set must be non-empty in the case of In and NotIn. All of the requirements, from both `matchLabels` and `matchExpressions` are ANDed together -- they must all be satisfied in order to match.
285+
`matchLabels` is a map of `{key,value}` pairs. A single `{key,value}` in the
286+
`matchLabels` map is equivalent to an element of `matchExpressions`, whose `key`
287+
field is "key", the `operator` is "In", and the `values` array contains only "value".
288+
`matchExpressions` is a list of pod selector requirements. Valid operators include
289+
In, NotIn, Exists, and DoesNotExist. The values set must be non-empty in the case of
290+
In and NotIn. All of the requirements, from both `matchLabels` and `matchExpressions`
291+
are ANDed together -- they must all be satisfied in order to match.
235292

236293
#### Selecting sets of nodes
237294

238-
One use case for selecting over labels is to constrain the set of nodes onto which a pod can schedule.
239-
See the documentation on [node selection](/docs/concepts/scheduling-eviction/assign-pod-node/) for more information.
295+
One use case for selecting over labels is to constrain the set of nodes onto which
296+
a pod can schedule. See the documentation on
297+
[node selection](/docs/concepts/scheduling-eviction/assign-pod-node/) for more information.
240298

241299
## {{% heading "whatsnext" %}}
242300

0 commit comments

Comments
 (0)