Skip to content

Terraform + Ansible for provisioning cloud and on-prem resources.

License

Notifications You must be signed in to change notification settings

Exploravis/exploravis-infra

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

105 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k3s-terraform-ansible-cluster

Spin up flexible, scalable, and compliant K3s clusters in Azure Cloud(for now) from a single configuration file.

Features

  • Modular azure cluster creation
  • remote terraform state support(Terraform Cloud)
  • Managed ssh keys through azure key vault
  • Ansible to fully setup and config kubernetes in the clusters
  • Modular ansible with playbooks and roles
  • Teleport with github SSO

Prerequisits

  • A working Azure subscription
  • Azure key-vault wasp-vault
  • Terraform cloud account for remote state managment

How to setup

1. create terraform.tfvars in terraform/ with your desired configs:

clusters = {
  france = {
    cluster_name   = "france-cluster-1"
    region         = "francecentral"
    admin_username = "azureuser"
    workers = [
      {
        name          = "worker-group-1"
        instance_size = "Standard_B1ms"
        disk_size     = 30
        count         = 13  
        tags          = { role = "ms1" }
      },
      {
        name          = "worker-group-2"
        instance_size = "Standard_B1ms"
        disk_size     = 50
        count         = 5
        tags          = { role = "dbs" }
      }
    ]
  }

  spain = {
    cluster_name   = "spain-cent-test"
    region         = "spaincentral"
    admin_username = "azureuser"
    workers = [
      {
        name          = "wkr-1"
        instance_size = "Standard_B1ms"
        disk_size     = 30
        count         = 13  
        tags          = { role = "dev" }
      },
      {
        name          = "wkr-2"
        instance_size = "Standard_B1ms"
        disk_size     = 50
        count         = 5
        tags          = { role = "test" }
      }
    ]
  }

}

2. Provision infrastructure with Terraform:

bash ./scripts/run_tf.sh

3. Generate Ansible inventory from Terraform state:

bash ./scripts/generate_ansible_inv.sh

4. Run Ansible playbooks to setup K3s and Teleport on master and worker nodes :

bash ./scripts/install_k3s.sh

to configure the master with Teleport:

bash ./scripts/setup_teleport.sh

Workflow Diagram

flowchart LR
    %% Subgraph: Configuration
    subgraph Config[Configuration]
        A[terraform.tfvars - cluster config]
    end

    %% Subgraph: Provisioning
    subgraph Provisioning[Provisioning]
        B[Terraform - provision VMs]
        B1[Terraform Cloud - remote state]
    end

    %% Subgraph: Secrets
    subgraph Secrets[Secrets Management]
        KV[Azure Key Vault - secrets and SSH keys]
    end

    %% Subgraph: Inventory & Setup
    subgraph Setup[Cluster Setup]
        C[Generate Ansible Inventory - from TF state]
        D[Ansible - setup K3s and roles/playbooks]
    end

    %% Subgraph: Running Cluster
    subgraph Running[Running Cluster]
        E[Running K3s Cluster - masters and workers]
    end

    %% Flow connections
    A --> B
    B --> B1
    B --> KV
    B1 --> C
    KV --> D
    C --> D
    D --> E
Loading

About

Terraform + Ansible for provisioning cloud and on-prem resources.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •