Deploying a Turborepo Monorepo to K3s with Ansible and GitHub Actions
Context
I have a Turborepo monorepo with two Next.js 16 applications:
www- My personal portfolioskysculptor- An AI app with Three.js
The goal: automatically deploy these apps to a Hetzner VPS with K3s, automatic SSL via Let's Encrypt, and CI/CD via GitHub Actions. All provisioned with Ansible.
Tech Stack
| Component | Technology |
|---|---|
| Infrastructure as Code | Ansible |
| Container Orchestration | K3s (lightweight Kubernetes) |
| Ingress Controller | Traefik (built into K3s) |
| SSL/TLS | Cert-manager + Let's Encrypt |
| CI/CD | GitHub Actions |
| Container Registry | GitHub Container Registry (ghcr.io) |
| VPS | Hetzner Cloud |
Part 1: Infrastructure with Ansible
Ansible Roles Structure
ansible/
├── playbook.yaml
├── inventory.ini
├── vars/main.yaml
└── roles/
├── os_common/ # System config (locale, timezone, SSH, Fish)
├── firewall/ # Firewalld with K3s rules
├── docker_install/ # Docker installation
├── k3s_install/ # K3s installation
└── cert_manager/ # Cert-manager + ClusterIssuers
K3s Role: Automatic Installation
# roles/k3s_install/defaults/main.yaml
k3s_install_exec_options: "server --write-kubeconfig-mode=644"
k3s_install_force_reinstall: false
The --write-kubeconfig-mode=644 flag allows non-root users to read the kubeconfig.