Skip to content

whyvez/k3s-ec2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

k3s on EC2

Deploy a single-node k3s Kubernetes cluster on AWS EC2 using OpenTofu and Ansible.

Prerequisites

Quick Start

# Initialize (creates AWS key pair, terraform.tfvars, and downloads providers)
make init

# Deploy the infrastructure and install k3s
make apply

# SSH into the instance
make ssh

# Fetch kubeconfig to use kubectl locally
make kubeconfig
export KUBECONFIG=./kubeconfig.yaml
kubectl get nodes

Make Targets

Target Description
make init Create key pair, copy tfvars, initialize OpenTofu
make plan Preview infrastructure changes
make apply Deploy infrastructure and install k3s
make destroy Tear down all infrastructure
make ssh SSH into the EC2 instance
make kubeconfig Fetch kubeconfig and configure for remote access
make ansible Re-run Ansible playbook manually
make keypair Create AWS key pair only
make clean Remove generated files (keeps key pair)
make clean-all Remove everything including AWS key pair

Configuration

Edit terraform.tfvars after running make init:

aws_region       = "us-east-1"
instance_type    = "t3.medium"
key_name         = "k3s-cluster-key"
private_key_path = "./k3s-cluster-key.pem"
allowed_ssh_cidr = "0.0.0.0/0"  # Restrict to your IP for security
project_name     = "k3s-cluster"

Custom Key Name

make init KEY_NAME=my-custom-key

What Gets Created

  • VPC with public subnet and internet gateway
  • Security group (ports: 22, 80, 443, 6443)
  • EC2 instance (Ubuntu 22.04, 30GB gp3 volume)
  • k3s installed via Ansible

Cleanup

# Destroy infrastructure but keep key pair for reuse
make destroy
make clean

# Full cleanup including AWS key pair
make destroy
make clean-all

About

Provisions k3s Kubernetes cluster on EC2 instance

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages