Production-ready Kubernetes GitOps template with automated local clusters, full observability stack, and security policies
Explore the docs Β»
View Demo
Β·
Report Bug
Β·
Request Feature
π Table of Contents
This project provides a complete, production-ready Kubernetes template designed for DevOps engineers who want to quickly set up a local Kubernetes environment with GitOps principles, comprehensive monitoring, and security best practices.
Key Highlights:
- ποΈ Automated Setup: Two k3d clusters (dev & prod) deployed with a single command
- π GitOps Workflow: ArgoCD-based continuous deployment with declarative configuration
- π Full Observability: Prometheus, Grafana, and Loki for complete monitoring and logging
- π Security First: Kyverno policies for automated security enforcement
- π Production-Ready: Separate dev and prod environments with proper isolation
- οΏ½ Easy to Extend: Well-structured platform components using Helm charts
This template is perfect for learning Kubernetes, testing applications locally, or as a starting point for your own GitOps infrastructure.
This project leverages the following major frameworks and tools:
Platform Components:
- k3d - Lightweight Kubernetes clusters in Docker
- ArgoCD - GitOps continuous delivery tool
- Ingress NGINX - Kubernetes Ingress controller
- Prometheus Stack (kube-prometheus-stack v55.5.0) - Monitoring and alerting
- Grafana - Metrics visualization and dashboards
- Loki (v2.9.0) - Log aggregation system
- Promtail - Log collector for Loki
- Kyverno (v1.11.0) - Kubernetes policy engine
Follow these steps to get your local Kubernetes clusters up and running with all platform components deployed.
Before you begin, ensure you have the following tools installed on your system:
-
Docker (20.10+)
# Verify installation docker --version
-
kubectl (1.28+)
# Verify installation kubectl version --client
-
k3d (5.6+)
# Verify installation k3d version
-
Helm (3.12+)
# Verify installation helm version
-
Clone the repository
git clone https://github.com/Kobeep/k8s-gitops-template.git cd k8s-gitops-template
-
Install prerequisites (if needed)
./scripts/install-prerequisites.sh
-
Bootstrap both clusters
./scripts/bootstrap.sh
This will:
- β Create k3d dev cluster (1 server + 2 agents)
- β Create k3d prod cluster (1 server + 3 agents)
- β Install ArgoCD on both clusters
- β Deploy root applications
- β Configure GitOps sync
-
Verify cluster status
./scripts/status.sh
-
Get ArgoCD credentials
The bootstrap script will output the ArgoCD admin passwords for both clusters. You can also retrieve them manually:
# DEV cluster kubectl config use-context k3d-k8s-dev kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d # PROD cluster kubectl config use-context k3d-k8s-prod kubectl -n argocd get secret argocd-initial-admin-secret -o jsonpath="{.data.password}" | base64 -d
Bootstrap Clusters:
# Bootstrap both dev and prod clusters
./scripts/bootstrap.sh
Switch Between Clusters:
# Switch to dev cluster
kubectl config use-context k3d-k8s-dev
# Switch to prod cluster
kubectl config use-context k3d-k8s-prod
Check Cluster Status:
./scripts/status.sh
Destroy Clusters:
./scripts/destroy.sh
ArgoCD:
# Dev cluster - http://localhost:8080
kubectl port-forward -n argocd svc/argocd-server 8080:443 --context k3d-k8s-dev
# Prod cluster - http://localhost:9080
kubectl port-forward -n argocd svc/argocd-server 9080:443 --context k3d-k8s-prod
Grafana:
# Access via Prometheus Stack service
kubectl port-forward -n monitoring svc/kube-prometheus-stack-grafana 3000:80
Prometheus:
# Access Prometheus UI
kubectl port-forward -n monitoring svc/kube-prometheus-stack-prometheus 9090:9090
ArgoCD automatically syncs applications from the clusters/{dev,prod}/argocd-apps/
directory. To add new applications:
- Create an ArgoCD Application manifest in the appropriate cluster directory
- Commit and push to the repository
- ArgoCD will automatically detect and sync the new application
Example Application:
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
name: my-app-dev
namespace: argocd
spec:
project: default
source:
repoURL: https://github.com/Kobeep/k8s-gitops-template.git
targetRevision: main
path: apps/my-app
destination:
server: https://kubernetes.default.svc
namespace: dev
syncPolicy:
automated:
prune: true
selfHeal: true
k8s-gitops-template/
βββ clusters/ # Cluster-specific configurations
β βββ dev/
β β βββ cluster-config.yaml # k3d dev cluster config (1 server + 2 agents)
β β β # Ports: HTTP:8080, HTTPS:8443, NodePort:30000-30010
β β βββ argocd-apps/ # ArgoCD Applications for dev
β β βββ root-app.yaml # Root app of apps pattern
β β βββ platform.yaml # Platform components (monitoring, logging, etc.)
β β βββ apps.yaml # Application deployments
β βββ prod/
β βββ cluster-config.yaml # k3d prod cluster config (1 server + 3 agents)
β β # Ports: HTTP:9080, HTTPS:9443, NodePort:31000-31010
β βββ argocd-apps/ # ArgoCD Applications for prod
β βββ root-app.yaml
β βββ platform.yaml
β βββ apps.yaml
β
βββ platform/ # Platform components (Helm umbrella charts)
β βββ ingress-nginx/ # Ingress NGINX Controller
β β βββ Chart.yaml # v4.8.3
β β βββ values.yaml # Default values
β β βββ values-dev.yaml # Dev-specific overrides
β β βββ values-prod.yaml # Prod-specific overrides
β β
β βββ monitoring/ # Prometheus + Grafana
β β βββ Chart.yaml # kube-prometheus-stack v55.5.0
β β βββ values.yaml
β β βββ values-dev.yaml
β β βββ values-prod.yaml
β β
β βββ logging/ # Loki + Promtail
β β βββ Chart.yaml # Loki v5.41.4, Promtail v6.15.3
β β βββ values.yaml
β β βββ values-dev.yaml
β β βββ values-prod.yaml
β β
β βββ security/ # Kyverno policies
β βββ Chart.yaml # Kyverno v3.1.4
β βββ values.yaml
β βββ values-dev.yaml
β βββ values-prod.yaml
β
βββ scripts/ # Automation scripts
β βββ bootstrap.sh # Bootstrap both clusters
β βββ destroy.sh # Destroy all clusters
β βββ status.sh # Check cluster status
β βββ install-prerequisites.sh # Install required tools
β
βββ CONTRIBUTING.md # Contribution guidelines
βββ LICENSE # MIT License
βββ README.md # This file
Key Design Principles:
- Separation of Concerns: Platform components are separate from applications
- GitOps-Native: Everything is declarative and stored in Git
- Environment Parity: Dev and prod use the same structure with different values
- Helm-Based: All platform components use Helm for easy customization
- App of Apps Pattern: ArgoCD manages multiple applications through a root app
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β GitHub Repository β
β (GitOps Source of Truth) β
ββββββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββ
β
β ArgoCD pulls manifests
β and syncs to clusters
β
ββββββββββββββββ΄βββββββββββββββ
β β
βββββββββββΌβββββββββββ ββββββββββΌβββββββββββ
β Dev Cluster β β Prod Cluster β
β (k3d) β β (k3d) β
ββββββββββββββββββββββ€ βββββββββββββββββββββ€
β β’ 1 server β β β’ 1 server β
β β’ 2 agents β β β’ 3 agents β
β β β β
β Ports: β β Ports: β
β β’ HTTP: 8080 β β β’ HTTP: 9080 β
β β’ HTTPS: 8443 β β β’ HTTPS: 9443 β
β β’ NodePort: β β β’ NodePort: β
β 30000-30010 β β 31000-31010 β
ββββββββββββββββββββββ βββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Kubernetes Cluster (k3d) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β argocd namespace β β
β β β’ ArgoCD Server β β
β β β’ ArgoCD Application Controller β β
β β β’ ArgoCD Repo Server β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β ingress-nginx namespace β β
β β β’ NGINX Ingress Controller β β
β β β’ LoadBalancer Service β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β monitoring namespace β β
β β β’ Prometheus (metrics collection) β β
β β β’ Grafana (visualization) β β
β β β’ AlertManager (alerting) β β
β β β’ Node Exporter (node metrics) β β
β β β’ Kube State Metrics (k8s metrics) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β logging namespace β β
β β β’ Loki (log aggregation) β β
β β β’ Promtail (log collection) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β security namespace β β
β β β’ Kyverno (policy engine) β β
β β β’ Admission Controller β β
β β β’ Background Controller β β
β β β’ Reports Controller β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β dev/prod namespaces β β
β β β’ Application workloads β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1. Developer pushes changes to Git repository
β
2. ArgoCD detects changes automatically
β
3. ArgoCD pulls updated manifests
β
4. ArgoCD applies changes to cluster
β
5. Applications are deployed/updated
β
6. Monitoring & logging track the deployment
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
For more details, please refer to CONTRIBUTING.md.
Distributed under the MIT License. See LICENSE
for more information.
Jakub Pospieszny - @Kobeep
Project Link: https://github.com/Kobeep/k8s-gitops-template
This project was built using these amazing open-source tools:
- k3d - Lightweight Kubernetes in Docker
- ArgoCD - GitOps continuous delivery tool
- Prometheus - Monitoring and alerting toolkit
- Grafana - Analytics and monitoring platform
- Loki - Log aggregation system
- Kyverno - Kubernetes native policy management
- NGINX Ingress Controller - Ingress controller for Kubernetes
- Helm - The package manager for Kubernetes
- Best-README-Template - README template inspiration
If you find this project helpful, please consider giving it a β