0

I want to create custom K3S clusters using rancher but without using the UI. My goal is to only call the rancher API to create the cluster on the tool and get the command to run on my nodes. I basically found all required endpoints, but the one used by the UI to create a new K3S custom cluster (/v1/provisioning.cattle.io.clusters) does not work as intended. When I query with the POST method, the API return me a 422 error with the following body :

{
    "type": "error",
    "links": {},
    "code": "InvalidBodyContent",
    "message": "Failed to parse body: unexpected EOF",
    "status": 422
}

I double check that my JSON has no error on it and is computable, so I run out of idea for what is blocking.

If someone has already created a custom K3S cluster from the Rancher API, I'm open to have advice on the best method

Thanks in advance !

PS : Here is my json body of my POST request

{
    "type": "provisioning.cattle.io.cluster",
    "metadata": {
        "namespace": "fleet-default",
        "name": "foo"
    },
    "spec": {
        "rkeConfig": {
            "chartValues": {},
            "upgradeStrategy": {
                "controlPlaneConcurrency": "1",
                "controlPlaneDrainOptions": {
                    "deleteEmptyDirData": true,
                    "disableEviction": false,
                    "enabled": false,
                    "force": false,
                    "gracePeriod": -1,
                    "ignoreDaemonSets": true,
                    "skipWaitForDeleteTimeoutSeconds": 0,
                    "timeout": 120
                },
                "workerConcurrency": "1",
                "workerDrainOptions": {
                    "deleteEmptyDirData": true,
                    "disableEviction": false,
                    "enabled": false,
                    "force": false,
                    "gracePeriod": -1,
                    "ignoreDaemonSets": true,
                    "skipWaitForDeleteTimeoutSeconds": 0,
                    "timeout": 120
                }
            },
            "dataDirectories": {
                "systemAgent": "",
                "provisioning": "",
                "k8sDistro": ""
            },
            "machineGlobalConfig": {
                "disable-cloud-controller": false,
                "disable-kube-proxy": false,
                "disable-scheduler": false,
                "etcd-expose-metrics": false,
                "disable-apiserver": false,
                "disable-controller-manager": false,
                "disable-etcd": false,
                "disable-network-policy": false,
                "secrets-encryption": false
            },
            "machineSelectorConfig": [
                {
                    "config": {
                        "protect-kernel-defaults": false,
                        "selinux": false,
                        "docker": false
                    }
                }
            ],
            "etcd": {
                "disableSnapshots": false,
                "s3": null,
                "snapshotRetention": 5,
                "snapshotScheduleCron": "0 */5 * * *"
            },
            "registries": {
                "configs": {},
                "mirrors": {}
            },
            "machinePools": []
        },
        "machineSelectorConfig": [
            {
                "config": {}
            }
        ],
        "kubernetesVersion": "v1.31.7+k3s1",
        "defaultPodSecurityAdmissionConfigurationTemplateName": "",
        "localClusterAuthEndpoint": {
            "enabled": false,
            "caCerts": "",
            "fqdn": ""
        }
    }
}

0 Answers0