0

A pod needs to update its labels dynamically by making a call to the internal Kubernetes API. In order to do so, the pod will send an authenticated PATCH request to: https://kubernetes.default.svc.cluster.local/api/v1/namespaces/<namespace>/pods/<pod> with the following body:

[{"op": "replace", "path": "/metadata/labels/<label>", "value": "<value>"}]

According to the Kubernetes guidelines (https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/#syntax-and-character-set ), s should contain a DNS-like prefix followed by a slash (/) and the label name, such as example.domain.com/name=value.

Unfortunately, when sending something similar to the aforementioned example, the Kubernetes API server will respond with an error 422 (Unprocessable Content), since the '/' in the label name is misinterpreted as resource sub-path rather than the actual label name.

Different escaping mechanisms (quoting, URL safe characters, …) don’t seem to work. How is it possible to update the label value as requested?

CowKeyMan
  • 133
  • 1
  • 8
  • The solution was to use "~1" as per this answer: https://stackoverflow.com/questions/65887327/patch-kubernetes-label-with-character/65889892#65889892 – CowKeyMan Aug 04 '23 at 12:05

0 Answers0