Project Kube-DB: Scalable State with HCL Architect: Gavin Dobbs | Branch: kubernetes-docker Focus: Kubernetes Orchestration, Terraform (HCL), StatefulSets, and Service Discovery.
-
Project Overview This project demonstrates the deployment of a production-grade MySQL 8.0 instance into a Kubernetes environment using Terraform (HCL). It moves beyond simple containerization by addressing the most difficult part of DevOps: Stateful Workloads.
-
The Architecture Logic A. The StatefulSet (The "Identity" Anchor) Unlike a standard Deployment, which treats Pods as "cattle" (disposable and interchangeable), this project utilizes a StatefulSet.
Purpose: Ensures that the MySQL pod maintains a persistent identity (mysql-0).
Persistence: Integrates a Persistent Volume Claim (PVC) template. Even if the pod is destroyed or rescheduled, the data volume automatically reattaches to the new pod, preventing data loss.
B. The Headless Service (Internal DNS) To provide a predictable endpoint for other applications (like a web frontend) to talk to the database, I implemented a Headless Service.
The "Linux DNS" Move: By setting cluster_ip = "None", Kubernetes creates a direct A-record in CoreDNS for the pod.
Resolution: Other pods in the namespace can reach the database using: mysql-0.mysql-svc.ops-core-lab.svc.cluster.local.
C. Infrastructure-as-Code (HCL) The entire environment is managed via Terraform.
Providers: Utilizes the kubernetes provider to talk directly to the K8s API.
Security: Demonstrates Secret Management by injecting root credentials through kubernetes_secret objects rather than hardcoding them in the manifest.
- Technical Stack Orchestration: Kubernetes (Local Cluster via Docker Desktop)
Configuration: Terraform (HCL)
Database: MySQL 8.0
Networking: K8s Internal DNS (CoreDNS)
- How to Deploy Ensure your Kube-context is set to docker-desktop.
Navigate to the /kubernetes-docker directory.
Initialize the provider: terraform init
Deploy the architecture: terraform apply -var="root_password=YOUR_SECURE_PASS" -var="db_password=YOUR_APP_PASS"
- Forward-Thinking SRE Application This blueprint is designed to be "Environment Agnostic." The same HCL logic can be ported from a local Docker Desktop environment to Azure Kubernetes Service (AKS) or Amazon EKS with minimal provider changes. It represents a commitment to Reliability Engineering and Zero-Touch Provisioning.