# How To Create K8S Cluster Using Qbert API And Private Docker Registry

## Problem

* How to use the Qbert API to create new K8S cluster?
* How to create a k8s cluster using Qbert API and Private Docker Registry

## Environment

* Platform9 Managed Kubernetes - all version

## Procedure

{% hint style="warning" %}
**Warning**

Before creating cluster you need to setup a docker repository with all required docker images
{% endhint %}

* Generate a Keystone authentication token with project scope by following [Keystone Identity API](https://platform9.com/docs/kubernetes/keystone-identity-api).
* Use below API to create a new cluster with private docker repository

```bash
curl -i -X POST \
   -H "Content-Type: application/json" \
   -H "X-Auth-Token: $TOKEN" \
   -d \
'{
    "nodePoolUuid" : "<node_pool_uuid>",
    "allowWorkloadsOnMaster" : true,
	  "name": "<cluster_name>",
	  "containersCidr": "<container_cidr>",
	  "networkPlugin": "calico",
	  "servicesCidr": "<service_cidr>",
	  "kubeRoleVersion": "<kube_role_version>",
	  "containerRuntime": "<container_runtime>",
	  "dockerPrivateRegistry": "<private_docker_registry_url>",
	  "k8sPrivateRegistry": "<private_docker_registry_url>",
	  "gcrPrivateRegistry": "<private_docker_registry_url>",
	  "quayPrivateRegistry": "<private_docker_registry_url>",
    "privileged" : true
}' \
 'https://<FQDN>/qbert/v4/<project_uuid>/clusters'
```

* Once the cluster is created attach a node as master using below API call

{% tabs %}
{% tab title="Bash" %}

```bash
curl -i -X POST \
   -H "Content-Type: application/json" \
   -H "X-Auth-Token: $TOKEN" \
   -d \
'[
  {
    "uuid": "<node_uuid>",
    "isMaster": true
  }
]' \
 'https://<FQDN>/qbert/v4/<project_uuid>/clusters/<new_cluster_uuid>/attach'
```

{% endtab %}
{% endtabs %}

* Once master node is attached to the cluster and becomes ready, you can attach worker node using same API call to add the node changing 'isMaster' parameter to false

## Additional Information

* For additional detail on the Qbert API please refer [Platform9 PMK Architecture](https://platform9.com/docs/v5.5/qbert/ref#postcreates-a-cluster-using-auto-deploy-or-manual-mode)
* Required Docker images

|          | Docker Images |
| -------- | ------------- |
| **Name** | **Version**   |
|          |               |
|          |               |
