kube/labels,selectors

This commit is contained in:
Marc Beninca 2023-07-10 18:27:40 +00:00
parent f048e2e665
commit c420721e09

View file

@ -536,3 +536,85 @@ Write
secretKeyRef:
name: username
key: username
Labels & Selectors
==================
Labels
------
* Key/Value pairs
* attached to objects
Reserved key prefixes:
* kubernetes.io
* k8s.io
Selectors
---------
* use labels
* filter/select objects
Types:
* matchLabels: =, ==, !=
* matchExpressions: exists, in, notin
Commands
--------
.. code:: shell
kubectl \
get pod \
--show-labels \
-n my-namespace
.. code:: shell
kubectl \
get pod \
-l app=my-app,version=1.0 \
-n my-namespace
.. code:: shell
kubectl \
get pod \
-l app=my-app,version in (1.0,1.1,1.2) \
-n my-namespace
.. code:: yaml
apiVersion: v1
kind: Pod
metadata:
name: my-pod
labels:
app: my-app
version: 1.0
spec:
containers:
- name: my-container
image: my-image
.. code:: yaml
apiVersion: v1
kind: Deployment
metadata:
name: my-deployment
labels:
app: my-app
spec:
containers:
- name: my-container
image: my-image
selector:
matchLabels:
app: my-app
matchExpressions:
- {key: version, operator: In, values: ["1.0","1.1","1.2"]}