K3s AWS Terraform Cluster

Deploy an high available K3s cluster on Amazon AWS

Blockchain & Cloud ComputingHCLGPL-3.0

Abstract

K3s AWS Terraform Cluster is an open-source Blockchain & Cloud Computing project. Deploy an high available K3s cluster on Amazon AWS. In this tutorial the High Availability of the K3s cluster is provided using the Embedded DB. More details here. It is built using HCL, Terraform, AWS, Kubernetes. The complete source code is publicly available on GitHub under the GNU General Public License v3.0, making it a useful reference for students building a Blockchain & Cloud Computing mini project or final-year project.

1. Introduction

In this tutorial the High Availability of the K3s cluster is provided using the Embedded DB. More details here

Deploy in a few minutes an high available K3s cluster on Amazon AWS using mixed on-demand and spot instances

2. Objective

Deploy an high available K3s cluster on Amazon AWS

This project demonstrates how HCL, Terraform, AWS can be applied to a real-world Blockchain & Cloud Computing problem.

4. Technology Stack

HCLTerraformAWSKubernetes

5. System Requirements

General requirements for this technology stack — check the README for exact versions.

  • Terraform CLI
  • Cloud provider account (e.g. AWS) with CLI configured
  • Git (to clone the repository)

6. Installation & Setup

git clone https://github.com/garutilorenzo/k3s-aws-terraform-cluster.git
cd k3s-aws-terraform-cluster
  1. resource "random_password" "k3s_token" {
  2. bcrypt_hash = (sensitive value)
  3. id = (known after apply)
  4. length = 55
  5. lower = true
  6. min_lower = 0
  7. min_numeric = 0
  8. min_special = 0
terraform plan
...skip

  # module.k3s_cluster.random_password.k3s_token will be created
  + resource "random_password" "k3s_token" {
      + bcrypt_hash = (sensitive value)
      + id          = (known after apply)
      + length      = 55
      + lower       = true
      + min_lower   = 0
      + min_numeric = 0
      + min_special = 0
      + min_upper   = 0
      + number      = true
      + numeric     = true
      + result      = (sensitive value)
      + special     = false
      + upper       = true
    }

Plan: 61 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + elb_dns_name           = [
      + (known after apply),
    ]
  + k3s_server_public_ips  = [
      + (known after apply),
    ]
  + k3s_workers_public_ips = [
      + (known after apply),
    ]

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Note: You didn't use the -out option to save this plan, so Terraform can't guarantee to take exactly these actions if you run "terraform apply" now.
aws ec2 describe-instances --filters Name=tag-value,Values=k3s-server Name=instance-state-name,Values=running --query "Reservations[*].Instances[*].[PublicIpAddress, Tags[?Key=='k3s-instance-type'].Value|[0]]"
ssh X.X.X.X -lubuntu

ubuntu@i-09a42419e18e4dd0a:~$ sudo su -
root@i-09a42419e18e4dd0a:~# kubectl get nodes

NAME                  STATUS   ROLES                       AGE   VERSION
i-015f4e5b0c790ec07   Ready    <none>                      53s   v1.22.6+k3s1
i-0447b6b00c6f6422e   Ready    <none>                      42s   v1.22.6+k3s1
i-06a8449d1ea425e42   Ready    control-plane,etcd,master   96s   v1.22.6+k3s1
i-09a42419e18e4dd0a   Ready    control-plane,etcd,master   55s   v1.22.6+k3s1
i-0a01b7c89c958bc4b   Ready    control-plane,etcd,master   38s   v1.22.6+k3s1
i-0c4c81a33568df947   Ready    <none>                      47s   v1.22.6+k3s1
root@i-09a42419e18e4dd0a:~#

Full setup instructions are in the project README.

7. Future Enhancements

Suggested extensions you can add to make this your own project.

  • Add a CI/CD pipeline with GitHub Actions
  • Deploy to a public test network or cloud free tier
  • Add monitoring and cost alerts

8. Viva / Review Questions

Common questions examiners ask for projects in this domain.

  1. Why does this problem need a blockchain or cloud-native design?
  2. Explain the smart contract / infrastructure components and how they interact.
  3. How are gas costs or cloud costs kept under control?
  4. How is the system secured (keys, IAM, access control)?
  5. How would the solution scale to many more users?

9. Source Code & License

This project is developed by garutilorenzo and published on GitHub under the GNU General Public License v3.0. Please follow the license terms and credit the original author when you use or modify this code.

Want to build this as your internship project?

Work on a Blockchain & Cloud Computing project like this with mentor guidance, weekly reviews and an internship certificate from Training Trains, Erode — online or offline.

Apply for Blockchain & Cloud Computing Internship