Skip to content

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.

License

Notifications You must be signed in to change notification settings

Kobeep/k8s-gitops-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

27 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ K8s GitOps Template

Production-ready Kubernetes GitOps template with automated local clusters, full observability stack, and security policies

CI Pipeline Contributors Forks Stargazers Issues MIT License

Explore the docs Β»

View Demo Β· Report Bug Β· Request Feature

πŸ“‹ Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Project Structure
  5. Architecture
  6. CI/CD
  7. Contributing
  8. License
  9. Contact
  10. Acknowledgments

🎯 About The Project

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.

(back to top)

οΏ½ Built With

This project leverages the following major frameworks and tools:

  • Kubernetes
  • Docker
  • ArgoCD
  • Prometheus
  • Grafana
  • Helm

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

(back to top)

πŸš€ Getting Started

Follow these steps to get your local Kubernetes clusters up and running with all platform components deployed.

οΏ½ Prerequisites

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

οΏ½ Installation

  1. Clone the repository

    git clone https://github.com/Kobeep/k8s-gitops-template.git
    cd k8s-gitops-template
  2. Install prerequisites (if needed)

    ./scripts/install-prerequisites.sh
  3. 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
  4. Verify cluster status

    ./scripts/status.sh
  5. 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

(back to top)

πŸ’‘ Usage

Managing Clusters

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

Accessing Services

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

Deploying Applications

ArgoCD automatically syncs applications from the clusters/{dev,prod}/argocd-apps/ directory. To add new applications:

  1. Create an ArgoCD Application manifest in the appropriate cluster directory
  2. Commit and push to the repository
  3. 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

(back to top)

πŸ“ Project Structure

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

(back to top)

πŸ— Architecture

Cluster Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         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     β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Platform Components per Cluster

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    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                              β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β”‚                                                               β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

GitOps Flow

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

(back to top)

🀝 Contributing

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

For more details, please refer to CONTRIBUTING.md.

(back to top)

πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

πŸ“§ Contact

Jakub Pospieszny - @Kobeep

Project Link: https://github.com/Kobeep/k8s-gitops-template

(back to top)

πŸ™ Acknowledgments

This project was built using these amazing open-source tools:

(back to top)


Made with ❀️ for the DevOps community
If you find this project helpful, please consider giving it a ⭐

About

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.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages