[SOLVED]How update image with rancher API

I try to change the “Docker Image” of a “workload” via rancher api v3

I did manage to find how to do it via kubectl

kubectl set image deployment documentservice documentservice=private.depot.net/services/document-service:latest -n services

But, can’t find a way to do the same with Rancher API without sending a bigpayload with extrat information not needed.

I seek some thingth that would look like that

curl -u “token:KEY” -X POST -H “Accept: application/json” -H “Content-Type: application/json”
“base_url_rancher/v3/project/c-b9wm7:p-pz5l8/workloads/deployment:services:documentservice?action=redeploy” -k

I did found some old post on this forum about this, but no good answer.

Link of old post

A simple solution existe outside hack or usage of kubectl ?

This doesn’t exist in the Rancher API but you can do it with the k8s one. /k8s/clusters/<cluster id> gets you to the k8s API for a cluster through Rancher. So something like:

curl -u ...
-X PATCH
-H 'Content-Type: application/json-patch+json'
https://<rancher server>/k8s/clusters/<cluster_id>/apis/apps/v1/namespaces/<namespace name>/deployments/<deployment name>
-d '[{"op": "replace", "path": "/spec/template/spec/containers/0/image", "value": "<new image>"}]'
1 Like

Thanks for the response.
It’s work exactly as expected.

Note:
The base url can be find in the “Kubeconfig File”
Don’t forget to had your token in the Header.