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:

NameVersion
Terraform>= 1.0
Kosmos= 0.8.1

Getting started

Prerequisites

Before running the module, ensure the following:

  1. Kosmos provider

  2. 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.
  3. Fleet availability

    • Verify that you already have a Fleet in Kosmos. If you don’t, please contact the Kosmos Operator.
  4. Kubernetes cluster

    • Have an existing Kubernetes cluster that you want to register with Kosmos.

Running the module

Follow these steps to register your cluster:

  1. Download the reference script.

  2. Create a terraform.tfvars file in your working directory.

    • Use terraform.tfvars.example as a reference for required variables.
    • If you are using Kosmos dev or stg, set the variable kosmos_tier to dev or stg in your terraform.tfvars.
  3. Initialize Terraform:

    terraform init
    
  4. Apply the configuration:

    terraform apply --var-file=terraform.tfvars
    
    • Review the plan carefully.

    • Type yes to proceed.

    💡 Alternatively, you can run terraform apply without arguments. Terraform will automatically use terraform.tfvars.

  5. 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:

  1. Install required CLIs:

  2. Authenticate with Kosmos:

    kosmos login --access-key $KOSMOS_ACCESS_KEY https://console.kosmos.spcplatform.com
    
  3. Connect 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:

VariableRequiredDescriptionTypeExample
cluster_nameName of the generic cluster entry in Kosmosstring"my-cluster"
fleet_nameFleet where the cluster entry will be createdstring"production-fleet"
kosmos_userKosmos account username to add as cluster owner/adminstring"admin-user"
kosmos_access_keyKosmos access keystring""
admin_usersList of additional admin usernameslist(string)["user1", "user2"]
descriptionDescription for the cluster entrystring"Sample description"
kosmos_tierEnvironment 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:

Edit this page on GitHub