k8ssandra / k8ssandra-terraform

Apache License 2.0
17 stars 16 forks source link

K8ssandra Terraform

This repo contains a Terraform modules for creating Kubernetes clusters on Google Cloud Platform (GCP), Amazon Web Services(AWS), Microsoft Azure, Tanzu.

What's in this repo

What is Kubernetes?

Kubernetes is an open source container management system for deploying, scaling, and managing containerized applications. Kubernetes is built by Google based on their internal proprietary container management systems (Borg and Omega). Kubernetes provides a cloud agnostic platform to deploy your containerized applications with built in support for common operational tasks such as replication, autoscaling, self-healing, and rolling deployments.

What is Managed Kubernetes services?

Managed Kubernetes is when third-party providers take over responsibility for some or all of the work necessary for the successful set-up and operation of K8s. Depending on the vendor, “managed” can refer to anything from dedicated support, to hosting with pre-configured environments, to full hosting and operation. We will be using GKE, AKS, EKS, Tanzu.

What is Terraform?

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions. We will be using terraform version 0.14 to provision out infrastructure.

What is a Terraform module?

A Terraform Module is a canonical, reusable, best-practices definition for how to run a single piece of infrastructure, such as a database or server cluster. Each Module is written using a combination of Terraform and scripts (mostly bash) and include automated tests, documentation, and examples. It is maintained both by the open source community and companies that provide commercial support.

Instead of figuring out the details of how to run a piece of infrastructure from scratch, you can reuse existing code that has been proven in production. And instead of maintaining all that infrastructure code yourself, you can leverage the work of the Module to pick up infrastructure improvements through a version number bump.

Prerequisites

At a minimum 61 GiB of memory, 8 vCPUs virtual machines are needed to run k8ssandra. Minimum recommendation for volumes is 1.5 - 2 TB, but that's all set up through the persistent volume requests.

Resource Naming Conventions

Project directory Structure

k8ssandra-terraform/
|   aws/
|   gcp/
|    ├──modules/
|    |  ├──gcs
|    |     ├── main.tf 
|    |     └── variables.tf 
|    |     └── outputs.tf 
|    |     └── README.md 
|    |  ├──vpc
|    |     ├── main.tf 
|    |     └── variables.tf 
|    |     └── outputs.tf 
|    |     └── README.md 
|    |  ├──iam
|    |     ├── main.tf 
|    |     └── variables.tf 
|    |     └── outputs.tf 
|    |     └── README.md
|    |  ├──gke
|    |     ├── main.tf 
|    |     └── variables.tf 
|    |     └── outputs.tf 
|    |     └── README.md
|    └──README.md
|    └──gitignore
|    ├──env
|       ├── dev.tf
|         ../modules/vpc
|         ../modules/iam
|         ../modules/gke_cluster
|       ├── version.tf 
|       └── backend.tf 
|       └── variables.tf 
|       └── outputs.tf
|       └── README.md
|    ├──scripts
|  azure/
|  tanzu/
|  test/
|  LICENSE
|  Makefile
|  README.md

How to use Makefile

Create GKE resources


export TF_VAR_environment=<ENVIRONMENT_REPLACEME>
ex:- export TF_VAR_environment=dev

export TF_VAR_name=<CLUSTERNAME_REPLACEME>
ex:- export TF_VAR_name=k8ssandra

export TF_VAR_project_id=<PROJECTID_REPLACEME>
ex:- export TF_VAR_project_id=k8ssandra-testing

export TF_VAR_region=<REGION_REPLACEME>
ex:- export TF_VAR_region=us-central-1
#To list out the available options to use.
make help

important: Before running the following command, we need to Export the environment variables as show above.

# Initialize and configure Backend.
make init "provider=gcp"
# Plan all GCP resources.
make plan "provider=gcp"

This command will create a Kubernetes cluster and deploy k8ssandra on the cluster.

# Create or update GCP resources
# This command takes some time to execute. 
make apply "provider=gcp"
# Destroy all GCP resources

make destroy "provider=gcp"

Create EKS resources


# Environment name, eg. "dev"
# bash, zsh
export TF_VAR_environment=dev

#fish
set -x TF_VAR_environment dev

# Kubernetes cluster name, eg. "k8ssandra"
# bash, zsh
export TF_VAR_name=k8ssandra

# Resource Owner name, eg. "k8ssandra"
# bash, zsh
export TF_VAR_resource_owner=k8ssandra

#fish
set -x TF_VAR_resource_owner k8ssandra

#fish
set -x TF_VAR_name k8ssandra

# AWS region name, eg. "us-east-1" 
# bash, zsh
export TF_VAR_region=us-east-1

#fish
set -x TF_VAR_region us-east-1
#To list out the available options to use.
make help

important: Before running the following command, we need to Export the environment variables as show above.

# Initialize and configure Backend.
make init "provider=aws"
# Plan all GCP resources.
make plan "provider=aws"

This command will create a Kubernetes cluster and deploy k8ssandra on the cluster.

# Create or update AWS resources
# This command takes some time to execute. 
make apply "provider=aws"
# Destroy all AWS resources created 

make destroy "provider=aws"

Create AKS resources


export TF_VAR_environment=<ENVIRONMENT_REPLACEME>
ex:- export TF_VAR_environment=dev

export TF_VAR_name=<CLUSTERNAME_REPLACEME>
ex:- export TF_VAR_name=k8ssandra

export TF_VAR_region=<REGION_REPLACEME>
ex:- export TF_VAR_region=eastus
#To list out the available options to use.
make help

important: Before running the following command, we need to Export the environment variables as show above.

# Initialize and configure Backend.
make init "provider=azure"
# Plan all Azure resources.
make plan "provider=azure"

This command will create a Kubernetes cluster and deploy k8ssandra on the cluster.

# Create or update Azure resources
# This command will take some time to execute. 
make apply "provider=azure"
# Destroy all Azure resources created with terraform.

make destroy "provider=azure"

Troubleshooting

Relevant Material