1

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
1

Labels lets you as user query for particular objects; from the docs:

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 !=). K8s doc should be good starting point, alternatively check out this article on labels.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.