Skip to main content
Version: latest

Example Usage

This workflow demonstrates how to use Spectro Cloud API. You can use the API to automate the provisioning of Kubernetes clusters and applications on Spectro Cloud.

The API is a RESTful API that uses JSON for serialization and supports HTTP Basic Authentication and token authentication. The API is available at https://api.spectrocloud.com.

Use the following examples to familiarize yourself with the API.

warning

The following samples are for demonstration purposes only and may lack all the required payload values. They are not intended for production use. We recommend exploring the API using a tool such as Postman and our available Postman collection. Check out the Palette Postman collection resource to learn more about the Postman collection.

Prerequisites

  • You must have a Spectro Cloud account. If you do not have an account, you can create one at https://console.spectrocloud.com.

  • An Authentication header with a token value or an API key. Learn more about authentication credentials by reviewing the authentication methods resource.

  • The respective language runtime and package manager installed on your machine.

  • jq - A command-line JSON processor.

Configure Scope and Authentication

Variables shown in the following examples are used to interact with the Palette API. The values for these variables are specific to your environment. The project ID is the Unique Identifier (UID) of the project in which you want to create the cluster. You can find the project ID at top right in the Palette dashboard.


export API_value="Your API Key"

export PROJECT_ID="Your Project UID"

Some of the endpoints require a cluster ID.

info

If you do not provide the projectUid header, then the assumed scope is of the tenant.

Deploy a Cluster

You can use the following endpoint to deploy a cluster. The provider value represents the cloud provider on which you want to deploy the cluster, such as public cloud or on-prem.

Endpoint: https://api.spectrocloud.com/v1/spectroclusters/{provider}

Set the provider as an environment variable.

export PROVIDER="Your Provider"

export PAYLOAD='{
"metadata": {
"annotations": {},
"name": "my-cluster",
"labels": {}
},
"spec": {....}
}'
curl --location 'https://api.spectrocloud.com/v1/spectroclusters/$PROVIDER?projectUid=$PROJECT_ID"' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "apiKey: $API_KEY"
--data "$PAYLOAD"

Monitor Cluster Creation Progress

You can use the following endpoint to monitor the progress of cluster creation.

Endpoint: https://api.spectrocloud.com/v1/spectroclusters/{uid}

Ensure you specify the cluster ID. You can set the cluster ID as an environment variable.

export CLUSTER_ID="Your Cluster ID"

curl -s --location "https://api.spectrocloud.com/v1/spectroclusters/$CLUSTER_ID?projectUid=$PROJECT_ID" \
--header 'Accept: application/json' \
--header "apiKey: $API_KEY" \
| jq -r '.status'

Cluster Nodes and Node Status

You can use the following endpoint to retrieve the list of nodes in a cluster and their status.

Endpoint: https://api.spectrocloud.com/v1/spectroclusters/{uid}

Ensure you specify the cluster ID. You can set the cluster ID as an environment variable.

export CLUSTER_ID="Your Cluster ID"

All Cluster Node Data


curl --location "https://api.spectrocloud.com/v1/spectroclusters/$CLUSTER_ID?projectUid=$PROJECT_ID" \
--header 'Accept: application/json' \
--header "apiKey: $API_KEY"

Retrieve the Cluster Cloud Config Identifier

The cloud config identifier is a unique identifier for the cloud config that is used to provision the cluster. The values are found in the spec.cloudConfigRef field of the cluster object. You can use the following code snippet to retrieve the cluster cloud config identifier uid and kind.


curl -s --location "https://api.spectrocloud.com/v1/spectroclusters/$CLUSTER_ID?projectUid=$PROJECT_ID" \
--header 'Accept: application/json' \
--header "apiKey: $API_KEY" \
| jq -r '.spec.cloudConfigRef | "\(.kind) \(.uid)"'

Cluster Workloads

You can retrieve information about the active workloads on a cluster, such as the number of pods, nodes, and containers. Use the namespace filter to retrieve information about workloads in specific namespaces.

Endpoint: https://api.spectrocloud.com/v1/dashboard/spectroclusters/{uid}/workloads/pod

Ensure you specify the cluster ID. You can set the cluster ID as an environment variable.

export CLUSTER_ID="Your Cluster ID"

 curl --location "https://api.spectrocloud.com/v1/dashboard/spectroclusters/$CLUSTER_ID/workloads" \
--header "Content-Type: application/json" \
--header "Accept: application/json" \
--header "projectUid: $PROJECT_ID" \
--header "apiKey: $API_KEY" \
--data '{
"filter": {
"namespaces": ["default", "myOtherNamespace"]
}
}'

Filter Clusters

You can filter host clusters by specifying the tags you want to filter on.

Endpoint: https://api.spectrocloud.com/v1/dashboard/spectroclusters/search

Ensure you specify the cluster ID. You can set the cluster ID as an environment variable.

export CLUSTER_ID="Your Cluster ID"

In the following example, a filter for the tags dev and team:bravo-2 is specified. You can learn more about filters and how to


 curl --location 'https://api.spectrocloud.com/v1/dashboard/spectroclusters/search?limit=20' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header "projectUid: $PROJECT_ID" \
--header "apiKey: $API_KEY" \
--data '{
"filter": {
"conjunction": "and",
"filterGroups": [
{
"conjunction": "and",
"filters": [
{
"property": "tag",
"type": "string",
"condition": {
"string": {
"operator": "eq",
"negation": false,
"match": {
"conjunction": "or",
"values": [
"dev",
"team:bravo-2"
]
},
"ignoreCase": false
}
}
}
]
}
]
},
"sort": []
}'

Download Cluster Kubeconfig

You can download the kubeconfig file of a host cluster. To download the kubeconfig file, you need to provide the cluster UID.

Endpoint: https://api.spectrocloud.com/v1/spectroclusters/{uid}/assets/kubeconfig


export CLUSTER_ID="Your Cluster ID"

 curl --location 'https://api.spectrocloud.com/v1/spectroclusters/$CLUSTER_ID/assets/kubeconfig' \
--header 'Accept: application/octet-stream' \
--header 'projectUid: $PROJECT_ID' \
--header 'apiKey: $API_KEY'