Terramate is a tool for managing Terraform, Tofu, Kubernetes or any other kind of IaC (Infrastructure as Code). It's agnostic to the underlying infrastructure and can be used to manage resources or clusters on any cloud provider or on-premises.
This repository is an example of how to manage Kubernetes clusters with Terramate. It showcases a configurable approach to managing environments in separate Kubernetes clusters or namespaces by just switching an option in the global.tm file.
To get started, you need to have Terramate installed on your machine. Please head over to the Terramate installation guide to install Terramate.
Once you have Terramate installed, you can clone this repository and run the following commands:
cd terramate-kubernetes
terramate list --tags environments
This will list all the environments that are available in this repository. Output:
environments/dev
environments/prod
environments/staging
By default, each environment is a separate Kubernetes cluster. That's controlled by the global.environments.kind option. If set to cluster
, each environment is a separate Kubernetes cluster. If set to namespace
, each environment is a separate namespace in the same Kubernetes cluster.
If you change the kind
option to namespace
then you have to also set the global.environments.cluster_name
option to the name of the Kubernetes cluster where you want to create the namespaces. After changing it, run the terramate generate
again to apply the filesystem changes.
There are Terramate scripts to create and destroy environments. To create all environments, run:
terramate script run --tags environment -- k8s create environments
To destroy all environments, run:
terramate script run --tags environment -- k8s delete environments
To create a specific environment, run:
terramate -C environments/<name> script run --tags environment -- k8s create environments
To delete a specific environment, run:
terramate -C environments/<name> script run --tags environment -- k8s delete environments