Answers: <p>Labels lets you as user query for particular objects; from the <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#motivation" rel="nofollow noreferrer">docs</a>:</p>
  
  <blockquote>
    <p>Labels enable users to map their own organizational structures onto system objects in a loosely coupled fashion, without requiring clients to store these mappings.</p>
  </blockquote>
  
  <p>For example if you use some kind of deployment tool like Spinnaker; the tool labels every single object that it touched so it knows about it - can manage it.</p>
  
  <p>When you query for a label you can use <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#equality-based-requirement" rel="nofollow noreferrer">equality-based operators (<code>=</code>, <code>==</code> and <code>!=</code>)</a>. K8s doc should be good starting point, alternatively check out <a href="https://medium.com/mayadata/kubernetes-label-selector-and-field-selector-81d6967bb2f" rel="nofollow noreferrer">this article</a> on labels.</p>
  
Answers: CC BY-SA 4.0
Answers: 2019-04-16T21:02:21.207Z
Answers: 2019-04-16T21:02:21.207Z
Answers: Kyslik
Body: <p>In the below deployment yml, the deployment itself has a label "app: hello". What would happen if I delete that line (line 6)?</p>
  
  <p>I understand the functional need for <em>pods</em> to be labeled, because then the deployment can reference those pods by labels. In the below example, that means that I understand why lines 11-12 and 16-17 exist. But that doesn't answer why the <em>deployment</em> should be labeled.</p>
  
  <pre><code>apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: helloweb
    labels:
      app: hello
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: hello
        tier: web
    template:
      metadata:
        labels:
          app: hello
          tier: web
      spec:
        containers:
          - name: hello-app
            image: registry.gitlab.com/itential/cloud-team/applications/hello-app
            ports:
              - containerPort: 8080
        imagePullSecrets:
          - name: gitlab-reg
  </code></pre>
  
Tags: <kubernetes><deployment>
Title: Why label k8s deployment?
UserDisplayName: Alexander Bird
ThreadText: # Why label k8s deployment?
  
  (Asked by: username_0 on 2019-04-16)
  
  In the below deployment yml, the deployment itself has a label "app: hello". What would happen if I delete that line (line 6)?
  
  I understand the functional need for *pods* to be labeled, because then the deployment can reference those pods by labels. In the below example, that means that I understand why lines 11-12 and 16-17 exist. But that doesn't answer why the *deployment* should be labeled.
  
  ```
  apiVersion: apps/v1
  kind: Deployment
  metadata:
    name: helloweb
    labels:
      app: hello
  spec:
    replicas: 1
    selector:
      matchLabels:
        app: hello
        tier: web
    template:
      metadata:
        labels:
          app: hello
          tier: web
      spec:
        containers:
          - name: hello-app
            image: registry.gitlab.com/itential/cloud-team/applications/hello-app
            ports:
              - containerPort: 8080
        imagePullSecrets:
          - name: gitlab-reg
  
  ```
  
  **Tags:** kubernetes, deployment
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2019-04-16. Score: 1 | Accepted answer
  
  Labels lets you as user query for particular objects; from the [docs](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#motivation):
  
  > Labels enable users to map their own organizational structures onto system objects in a loosely coupled fashion, without requiring clients to store these mappings.
  
  For example if you use some kind of deployment tool like Spinnaker; the tool labels every single object that it touched so it knows about it - can manage it.
  
  When you query for a label you can use [equality-based operators (`=`, `==` and `!=`)](https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#equality-based-requirement). K8s doc should be good starting point, alternatively check out [this article](https://medium.com/mayadata/kubernetes-label-selector-and-field-selector-81d6967bb2f) on labels.
  
  
  ---
  
  