GithubHelp home page GithubHelp logo

roib20 / terraform-ec2-kubeadm Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 67 KB

Single-node Kubeadm cluster on AWS EC2

License: Apache License 2.0

HCL 38.14% Shell 61.86%
aws kubernetes terraform

terraform-ec2-kubeadm's Introduction

terraform-ec2-kubeadm

License ShellCheck

This Terraform project provisions an EC2 instance, then using User data a shell script is deployed which creates a single node Kubernetes cluster with Kubeadm. Then a test application is deployed on the cluster: Microservices Demo by Weaveworks and Container Solutions.

Shell script

The task.sh User data shell script is written using POSIX Shell so that it can run on dash (instead of bash). The set -u option is set to ensure that variables are always set correctly. Furthermore, ShellCheck is used together with a GitHub Action, to ensure best practices for shell scripts.

Kubeadm Kubernetes cluster

Some cluster add-ons are installed. Canal is used as the cluster's CNI. Canal uses Calico for policy and Flannel for networking. The reason I decided to use Canal for this project is that I wanted a simple CNI like Flannel, but with support for Network Policies using Calico. For storage, local-path-provisioner and OpenEBS are installed.

The container runtime used in this project is CRI-O. I found CRI-O simpler to install than containerd, and I especially appreciated the consistent versioning which makes it easy to match CRI-O with an appropriate Kubernetes version.

Operating system

Ubuntu Minimal 22.04 LTS is recommended (and is used by default), however this project was also tested on Ubuntu 18.04 LTS and Ubuntu 20.04 LTS.

Instance type

It is recommended to use an instance with at least 2 vCPUs and 4 GiB of memory. The default instance used in this Terraform project is t3a.medium (which is a cost-effective option). For the root volume, dedicate at least 16 GiB of storage. If using your own VM, make sure to dedicate a similar amount of resources.

FAQ

How to deploy this on AWS?

  1. Create an SSH Key Pair for AWS.

  2. Install Terraform and ensure it can deploy AWS resources to your account.

  3. Clone this repository.

  4. Edit the terraform.tfvars.example file:

  • Use the command: cp "terraform.tfvars.example" "terraform.tfvars"
  • Edit terraform.tfvars using a text editor; add all necessary values (including your Key Pair name).
  1. Run terraform init && terraform apply from the project directory.

  2. When Terraform completes, wait a few minutes for the User data shell script to complete in the backgroud.

  3. SSH into your newly created Ubuntu EC2 instance using the following command:

ssh "$(terraform output --raw instance_elastic_ip)" -l "ubuntu"
  1. Run kubectl get pods -A to ensure everything deployed correctly (note: some pods could take several minutes to start).

  2. You can check the liveness of the app by running the task.sh shell script with the run_test flag:

curl -fsSL https://raw.githubusercontent.com/roib20/terraform-ec2-kubeadm/main/user_data/task.sh | /bin/sh -s -- run_test

How to destroy this on AWS?

Just run terraform destroy from the project directory.

How to deploy this on an Ubuntu VM?

  1. Install an Ubuntu 22.04 LTS VM using Proxmox VE or another hypervisor. Non-VM installs are not recommended because the script does a lot of changes to a system.

  2. SSH into your Ubuntu VM, run the task.sh script using this command:

curl -fsSL https://raw.githubusercontent.com/roib20/terraform-ec2-kubeadm/main/user_data/task.sh | /bin/sh -s --
  1. Once the script completes, check if kubectl is working. If not, try running these commands:
mkdir -p "${HOME}/.kube"
sudo cp -i "/etc/kubernetes/admin.conf" "${HOME}/.kube/config"
sudo chown "$(id -u):$(id -g)" "${HOME}/.kube/config"
  1. Run kubectl get pods -A to ensure everything deployed correctly (note: some pods could take several minutes to start).

  2. You can check the liveness of the app by running the task.sh shell script with the run_test flag:

curl -fsSL https://raw.githubusercontent.com/roib20/terraform-ec2-kubeadm/main/user_data/task.sh | /bin/sh -s -- run_test

terraform-ec2-kubeadm's People

Contributors

roib20 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.