title: Kubernetes API : add label to pod
body: <p>With command, I can add label as below</p>
  
  <pre><code>kubectl label pod POD_NAME KEY1=VALUE1
  </code></pre>
  
  <p>How could I do that from kubernetes API?</p>
  
  <p>I guess it can be done by <code>PATCH /api/v1/namespaces/{namespace}/pods/{name}</code></p>
  
  <p>Here is pod.json</p>
  
  <pre><code>{
      "apiVersion": "v1",
      "kind": "Pod",
      "metadata": {
          "labels": {
              "key1": "value1"
          }
      }
  }
  </code></pre>
  
  <p>I tried with following command</p>
  
  <pre><code>KUBE_TOKEN=$(&lt;/var/run/secrets/kubernetes.io/serviceaccount/token)
  curl --request PATCH --insecure \
        --header "Authorization: Bearer $KUBE_TOKEN"  \
        --data "$(cat pod.json)" \
        https://$KUBERNETES_SERVICE_HOST:$KUBERNETES_PORT_443_TCP_PORT/api/v1/namespaces/$POD_NAMESPACE/pods/$POD_NAME
  </code></pre>
  
  <p>And it returns </p>
  
  <pre><code>{
    "kind": "Status",
    "apiVersion": "v1",
    "metadata": {},
    "status": "Failure",
    "message": "the server responded with the status code 415 but did not return more information",
    "details": {},
    "code": 415
  }
  </code></pre>