Skip to content

Latest commit

 

History

History
175 lines (116 loc) · 5.16 KB

README.md

File metadata and controls

175 lines (116 loc) · 5.16 KB

Hextris on Kind Deployment Using Terraform

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.

Table of Contents

  1. Repository Structure
  2. Prerequisites
  3. Setup Instructions
  4. Terraform Configuration
  5. Helm Deployment
  6. Accessing the Application
  7. Cleaning Up
  8. Additional Resources

Repository Structure

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

Prerequisites

Before starting, ensure the following tools are installed:

  1. Docker - Required for running the Kind cluster.
  2. Kind - To create and manage a local Kubernetes cluster in Docker.
  3. Kubectl - Kubernetes CLI for interacting with the cluster.
  4. Helm - For managing Kubernetes applications using Helm charts.
  5. Terraform - To provision and configure the Kind cluster and Helm deployment.
  6. Optional: Pre-commit

Setup Instructions

Step 1: Clone the Repository

git clone <repository-url>
cd hextris-kind

Step 2: (Optional) Build the Hextris Docker Image

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 .

Terraform Configuration

Step 3: Initialize Terraform

Navigate to the terraform directory and initialize the Terraform configuration:

cd terraform
terraform init

This downloads necessary plugins and prepares the Terraform environment.

Step 4: Apply the Terraform Configuration

Run the following command to create the Kind cluster and deploy Hextris:

terraform apply

Terraform will:

  • Create a Kind cluster.
  • Generate kubeconfig file

Export 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

Step 5: Verify the Kind Cluster

After the Terraform apply completes, verify that the Kind cluster and nodes are running:

kubectl get nodes

Helm Deployment

Step 6: Deploy Hextris with Helm

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.

Accessing the Application

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.

  1. 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}")
  2. Port-forward to Access Hextris:

    kubectl port-forward $POD_NAME 8080:8080
  3. Access the Application:

    Open your browser and go to http://127.0.0.1:8080 to play Hextris.

Cleaning Up

To remove the Kind cluster and all related resources:

  1. Destroy Terraform-managed Resources:

    terraform destroy

    This will delete the Kind cluster and any infrastructure created by Terraform.

  2. Uninstall Helm Release:

    If you want to remove the Helm release only, you can use:

    helm uninstall hextris

Additional Resources