kubectl label - How to label "spec : template : metadata : labels"

12/4/2018

Ho do you set the following label in an already applied deployment?

kubectl label deployments my-deployment-v1 app=my-deployment

Is setting:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-deployment-v1
  labels:
    app: my-deployment

And I need, the following for a service to find it:

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: my-deployment-v1
spec:
  template:
    metadata:
      labels:
        app: my-deployment
-- Chris G.
kubernetes

1 Answer

12/4/2018

You need to patch your resource like this:

kubectl patch deployments/my-deployment-v1 \
-p '{"spec":{"template":{"metadata":{"labels":{"app":"my-deployment"}}}}}'
-- gonzalesraul
Source: StackOverflow