Import Generic Cluster using Terraform
Introduction
This guide explains how to use the Terraform module to register an existing Kubernetes cluster with Kosmos. The module creates a cluster entry in Kosmos and configures access for the specified admin users.
Requirements
Before getting started, make sure the following tools are installed:
| Name | Version |
|---|---|
| Terraform | >= 1.0 |
| Kosmos | = 0.8.1 |
Getting started
Prerequisites
Before running the module, ensure the following:
Kosmos provider
- Install the Kosmos Terraform provider using
Terraform provider user guide
with the version specified in
provider.tf.
- Install the Kosmos Terraform provider using
Terraform provider user guide
with the version specified in
Kosmos access key
- Log in to the Kosmos Console .
- Click your username (top-right) → Access key.
- Select Create access key and copy the generated key.
Fleet availability
- Verify that you already have a Fleet in Kosmos. If you don’t, please contact the Kosmos Operator.
Kubernetes cluster
- Have an existing Kubernetes cluster that you want to register with Kosmos.
Running the module
Follow these steps to register your cluster:
Download the reference script.
Create a
terraform.tfvarsfile in your working directory.- Use
terraform.tfvars.exampleas a reference for required variables. - If you are using Kosmos dev or stg, set the variable
kosmos_tiertodevorstgin yourterraform.tfvars.
- Use
Initialize Terraform:
terraform initApply the configuration:
terraform apply --var-file=terraform.tfvarsReview the plan carefully.
Type
yesto proceed.
💡 Alternatively, you can run
terraform applywithout arguments. Terraform will automatically useterraform.tfvars.Destroy the cluster registration (if needed):
terraform destroy --var-file=terraform.tfvars
Connecting the cluster to Kosmos
After applying the Terraform configuration, connect your Kubernetes cluster:
Install required CLIs:
Authenticate with Kosmos:
kosmos login --access-key $KOSMOS_ACCESS_KEY https://console.kosmos.spcplatform.comConnect the cluster:
kosmos join cluster --fleet $FLEET_NAME $CLUSTER_NAME$FLEET_NAME: Name of the fleet where the cluster is registered.$CLUSTER_NAME: Name of the cluster you registered.
Variables
The following variables are supported by the module:
| Variable | Required | Description | Type | Example |
|---|---|---|---|---|
cluster_name | ✓ | Name of the generic cluster entry in Kosmos | string | "my-cluster" |
fleet_name | ✓ | Fleet where the cluster entry will be created | string | "production-fleet" |
kosmos_user | ✓ | Kosmos account username to add as cluster owner/admin | string | "admin-user" |
kosmos_access_key | ✓ | Kosmos access key | string | "" |
admin_users | ✗ | List of additional admin usernames | list(string) | ["user1", "user2"] |
description | ✗ | Description for the cluster entry | string | "Sample description" |
kosmos_tier | ✗ | Environment tier (dev, stg, or null for prod) | string | "dev" |
Usage examples
Basic usage
module "generic_cluster" {
source = "https://srin-s3-terraform-modules.s3.ap-southeast-1.amazonaws.com/terraform-kosmos-generic-import-v1.0.0.tar.gz"
cluster_name = "prod-cluster"
fleet_name = "production-fleet"
kosmos_user = "kosmosuser"
}
Created resources
When applied, this module creates the following Kosmos resources:
- Generic Cluster: A cluster entry for your existing Kubernetes cluster registered into Kosmos.
Download Resources
For complete examples and the latest updates, refer to: