Racher API to import existing k8s cluster

Hi Team

I want to import existing cluster in rancher using api. I didnt find any valid documentation.

can someone help with api endpoint to import existing cluster to rancher. I am able to achieve this using GUI. But I want to do same with API.

When investigating the Rancher API, I couldn’t find an action to add a Cluster.

However, I was monitoring the API requests, when creating a Cluster through the UI and voíla, there is the API call in the Network log of the browser.

curl 'https://url.to-cluster.tld/v3/cluster?_replace=true' \
  -X POST -H 'Accept: application/json' \
  -H 'Accept-Language: en,en-US;q=0.5' \
  -H 'Accept-Encoding: gzip, deflate, br' \
  -H 'content-type: application/json' \
  --data-raw '{"dockerRootDir":"/var/lib/docker","enableClusterAlerting":false,"enableClusterMonitoring":false,"enableNetworkPolicy":false,"windowsPreferedCluster":false,"type":"cluster","name":"dummy-1","agentEnvVars":[],"labels":{},"annotations":{}}'

Now, add a Bearer token, modify the payload and you are done.


   "agentEnvVars": [],
   "annotations": {},
   "dockerRootDir": "/var/lib/docker",
   "enableClusterAlerting": false,
   "enableClusterMonitoring": false,
   "enableNetworkPolicy": false,
   "labels": {},
   "name": "dummy-1",
   "type": "cluster",
   "windowsPreferedCluster": false
1 Like