This repository automates the deployment of Hextris, a game application, on a local Kubernetes cluster using Kind and Helm. The infrastructure provisioning and configuration are managed by Terraform.
- Repository Structure
- Prerequisites
- Setup Instructions
- Terraform Configuration
- Helm Deployment
- Accessing the Application
- Cleaning Up
- Additional Resources
The repository is organized as follows:
hextris-kind/
├── charts/
│ └── hextris/ # Helm chart for deploying Hextris on Kubernetes
├── terraform/ # Terraform files for managing the infrastructure
│ ├── init.tf
│ ├── main.tf
│ ├── outputs.tf
│ └── version.tf
├── .gitignore # Git ignore file
├── .pre-commit-config.yaml # Pre-commit hooks configuration
├── Dockerfile # Dockerfile for building the Hextris application image
└── README.md # Project documentation
Before starting, ensure the following tools are installed:
- Docker - Required for running the Kind cluster.
- Kind - To create and manage a local Kubernetes cluster in Docker.
- Kubectl - Kubernetes CLI for interacting with the cluster.
- Helm - For managing Kubernetes applications using Helm charts.
- Terraform - To provision and configure the Kind cluster and Helm deployment.
- Optional: Pre-commit
git clone <repository-url>
cd hextris-kind
While this repository includes a Dockerfile
to build the Hextris image locally, Kind cannot directly access images from the local Docker registry. Therefore, we use a pre-built image hosted on Docker Hub in the Helm chart deployment. If you need to modify the image, you can build it locally and push it to kind.
This project uses Chainguard images for deploying Hextris due to their focus on security, minimalism, and performance. Chainguard images follow a "distroless" approach, meaning they include only the essential components needed to run the application, which minimizes potential vulnerabilities and reduces the attack surface.
Build the Docker image:
docker build -t hextris-nginx:latest .
Navigate to the terraform
directory and initialize the Terraform configuration:
cd terraform
terraform init
This downloads necessary plugins and prepares the Terraform environment.
Run the following command to create the Kind cluster and deploy Hextris:
terraform apply
Terraform will:
- Create a Kind cluster.
- Generate kubeconfig file
Export the KUBECONFIG
file so kubectl
can access the Kind cluster created by Terraform:
export KUBECONFIG=~/kind-config # Replace with the actual path if different
After the Terraform apply completes, verify that the Kind cluster and nodes are running:
kubectl get nodes
Navigate to the charts/hextris
directory:
cd ../charts/hextris
Deploy the Helm chart:
helm install hextris .
This command deploys the Hextris application using the Helm chart included in this repository.
By default, the application is deployed as a ClusterIP
service, which is accessible only within the cluster. To access the application locally, use kubectl port-forward
.
-
Get the Pod Name:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=hextris,app.kubernetes.io/instance=hextris" -o jsonpath="{.items[0].metadata.name}")
-
Port-forward to Access Hextris:
kubectl port-forward $POD_NAME 8080:8080
-
Access the Application:
Open your browser and go to
http://127.0.0.1:8080
to play Hextris.
To remove the Kind cluster and all related resources:
-
Destroy Terraform-managed Resources:
terraform destroy
This will delete the Kind cluster and any infrastructure created by Terraform.
-
Uninstall Helm Release:
If you want to remove the Helm release only, you can use:
helm uninstall hextris