Add label to metadata

10/14/2019

I've started to use kustomize to update the yaml files. I'm trying to add labels to Deployment object. commonLabels seems pretty good but it applies the label to selector as well (which I don't want)

Is there a way to add new label only to metadata.labels or spec.template.metadata.labels?

here's a sample deployment object :

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    service: servieName
    owner: ownerName
  name: myName
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
         app: servieName
         owner: ownerName
         <newLableHere>: <newValueHere>
 ...
-- Mahyar
kubernetes
kustomize

1 Answer

10/14/2019

You would need to define a patch for that object specifically.

-- coderanger
Source: StackOverflow