<p>I am trying to update a label using kubectl.</p>

<p>When I use <code>apply</code> it works but it doesn't when doing a <code>patch</code>.</p>

<p>I tried <code>kubectl patch deployment nginx-deployment --patch "$(cat nginx.yaml)"</code>; it returns back <code>no change</code> where I would expect to get back a label change.</p>

<p>These are the only changes on my yaml.</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: testLab
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.8
        ports:
        - containerPort: 80
</code></pre>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: helloWorld
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.8
        ports:
        - containerPort: 80
</code></pre>

<p>Is there a restriction on what patch updates or it am I doing something wrong? </p>

<p>I also tried specifying <code>--type strategic</code> and other types but none seem to work.</p>

e.f.a.
<p>After executing command  <strong>kubectl patch</strong> on your second file (where you changed label) you should see following error:</p>

<pre><code>Error from server: cannot restore map from string
</code></pre>

<p>After executing command <strong>kubectl apply</strong> on this file you should get following error :</p>

<pre><code>error: error validating "nginx.yaml": error validating data: ValidationError(Deployment.metadata): unknown field "label" in io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta; if you choose to ignore these errors, turn validation off with --validate=false
</code></pre>

<p>Your deployment file should looks like this:</p>

<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-deployment
  labels:
    app: helloWorld
spec:
  replicas: 3
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.8
        ports:
        - containerPort: 8
</code></pre>

<p>You missed to add space after app label.</p>

<p>Add space and then execute command <code>kubectl patch deployment nginx-deployment --patch "$(cat nginx.yaml)"</code> once again. </p>

<p>Here are useful documentations: <a href="https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/" rel="nofollow noreferrer">labels-selectors</a>, <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">kubernetes-deployments</a>, <a href="https://kubernetes.io/docs/tasks/run-application/update-api-object-kubectl-patch/" rel="nofollow noreferrer">kubernetes-patch</a>.</p>
