diff --git a/rtfd/public/kubernetes/index.rst b/rtfd/public/kubernetes/index.rst index da737a3..0f74652 100644 --- a/rtfd/public/kubernetes/index.rst +++ b/rtfd/public/kubernetes/index.rst @@ -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"]} +