Through the REST API I am able to GET Node's details through:
http://127.0.0.1:8001/api/v1/nodes/{Node Name}
However, I want to add a new label and delete an old one. Say add label app=service
, and remove backend=database
, What type of request am I supposed invoke and what's the JSON format am I required to send?
You can set a new label with the only one request.
JSON is:
{
"metadata": {
"labels": {
"app": "service"
}
}
}
You should send PATCH
request to:
http://127.0.0.1:8001/api/v1/nodes/<node_name>
So, finally we have:
curl -k -v -H "Accept: application/json" -XPATCH -d '{"metadata":{"labels":{"app":"service"}}}' -H "Content-Type: application/merge-patch+json" http://127.0.0.1:8001/api/v1/nodes/<node_name>
curl -X PATCH \ <cluster end point>/api/v1/nodes/<node name> \ -H 'Authorization: Bearer <your token>' \ -H 'Content-Type: application/merge-patch+json' \ -H 'cache-control: no-cache' \ -d '{
"metadata": {
"labels": {
"name": "vaibhav"
}
}
}
'
This works for me on eks, If your end cluster endpoint is insecure just add "--insecure" in your curl command.
Bearer token is: eks-admin-token(k8s secret)in your kube-system namespace or you can create one with restricted access.
Important thing to note: Content-Type: application/merge-patch+json