k8s

AGENTS.md - AI Agent Guide

This document provides guidance for AI agents working with this Kubernetes platform repository. It outlines repository structure, conventions, common tasks, and important considerations.

Repository Overview

This repository contains Helm charts implementing a “Platform in a Box” - a GitOps-driven Kubernetes platform foundation using Argo CD’s App-of-Apps pattern. The platform includes:

Key Repository Structure

k8s/
├── argocd-bootstrap-apps/     # Bootstrap Application manifests for each cluster
│   ├── dev-01.yaml
│   ├── ops-01.yaml
│   ├── prod-01.yaml
│   └── stag-01.yaml
├── charts/                     # Helm charts for platform components
│   ├── app-of-apps/           # Root orchestrator chart
│   ├── cert-manager/
│   ├── envoy-gateway/
│   ├── external-dns/
│   ├── kyverno/
│   ├── logging/               # Elastic Stack (ECK operator)
│   ├── monitoring/            # Prometheus/Thanos
│   ├── nginx-ingress-controller/
│   ├── redis/
│   ├── sealed-secrets/
│   └── jaeger/
├── docs/                      # Detailed architecture and operational guides
│   ├── getting-started.md
│   ├── observability.md
│   ├── traffic-management.md
│   ├── compliance.md
│   ├── argocd-best-practices.md
│   ├── elastic-best-practices.md
│   ├── troubleshooting.md
│   ├── faq.md
│   └── alert-catalog.md
├── scripts/                   # CI/CD and utility scripts
│   ├── scan.sh               # Chart scanning (lint, trivy, checkov)
│   ├── scan-config.yaml      # Scan configuration
│   ├── junit.tpl             # JUnit template for test results
│   └── what-runs-where.sh
└── README.md                  # Main documentation

Critical Conventions

1. Branching & Promotion Model

NEVER modify production values directly. Follow the promotion flow:

Key Rules:

2. Values File Pattern

Each chart has environment-specific values files:

When modifying values:

3. Component Enablement

Components are controlled via feature flags in app-of-apps/values.yaml:

sealedSecrets:
  enable: false  # Toggle component on/off
  # ... other config

Important: When adding new components or modifying existing ones:

4. Sync Waves

Argo CD sync waves control deployment order. Lower numbers deploy first:

annotations:
  argocd.argoproj.io/sync-wave: "-5"  # Deploys early (negative = before 0)
  argocd.argoproj.io/sync-wave: "5"   # Deploys later

Dependencies:

Common Tasks

Adding a New Chart

  1. Create chart structure:
    charts/new-component/
    ├── Chart.yaml
    ├── values.yaml
    ├── values.dev-01.yaml
    ├── values.ops-01.yaml
    ├── values.prod-01.yaml
    ├── values.stag-01.yaml
    ├── templates/
    │   └── [templates]
    └── README.md
    
  2. Add to app-of-apps chart:
    • Add component block in charts/app-of-apps/values.yaml
    • Add template in charts/app-of-apps/templates/ (if needed)
    • Include enable toggle and standard fields (project, namespace, source)
  3. Update documentation:
    • Add entry to Inventory table in README.md
    • Document dependencies in Cross-Chart Relationships section
    • Create component-specific README if complex
  4. Test:
    helm template charts/new-component -f charts/new-component/values.dev-01.yaml
    helm lint charts/new-component
    scripts/scan.sh lint
    

Modifying Existing Charts

  1. Always test locally first:
    # Template rendering
    helm template charts/<component> -f charts/<component>/values.dev-01.yaml
       
    # Linting
    helm lint charts/<component>
       
    # Full scan
    scripts/scan.sh lint
    scripts/scan.sh trivy
    scripts/scan.sh checkov
    
  2. Update appropriate values file:
    • Development changes: values.dev-01.yaml
    • Production changes: values.prod-01.yaml (but promote through pipeline!)
    • Base changes: values.yaml (affects all environments)
  3. Consider dependencies:
    • Check Cross-Chart Relationships in README
    • Verify sync waves are appropriate
    • Update dependent components if needed

Updating Documentation

  1. Component changes:
    • Update chart’s README.md if it exists
    • Update Inventory table in main README.md
    • Update Cross-Chart Relationships if dependencies change
  2. Architecture changes:
    • Update relevant doc in docs/ folder
    • Update main README.md if high-level changes
    • Update diagrams if topology changes
  3. Operational changes:
    • Update docs/troubleshooting.md if common issues change
    • Update docs/faq.md if new questions arise
    • Update docs/getting-started.md if bootstrap flow changes

Important Considerations

Security

Multi-Cluster Awareness

Chart Dependencies

Key dependencies to remember:

Testing & Validation

Before committing:

  1. Run helm lint on modified charts
  2. Run helm template to verify rendering
  3. Run scripts/scan.sh lint to check for double document separators
  4. Run scripts/scan.sh trivy to scan container images
  5. Run scripts/scan.sh checkov for security policy checks

Scan Configuration:

Version Management

File-Specific Guidelines

argocd-bootstrap-apps/*.yaml

charts/app-of-apps/values.yaml

charts/*/templates/

scripts/scan.sh

Common Pitfalls to Avoid

  1. Don’t modify production values directly - Always promote through dev → staging → stable
  2. Don’t commit unsealed secrets - Always use kubeseal first
  3. Don’t break sync wave ordering - Verify dependencies before changing sync waves
  4. Don’t skip testing - Always run helm lint and helm template before committing
  5. Don’t forget to update documentation - Keep README and docs in sync with code changes
  6. Don’t ignore scan failures - Address lint, trivy, and checkov issues before merging
  7. Don’t hardcode cluster-specific values - Use environment values files instead
  8. Don’t create circular dependencies - Be careful with cross-chart relationships

Getting Help

Quick Reference

Key Commands:

# Template rendering
helm template charts/<component> -f charts/<component>/values.<env>.yaml

# Linting
helm lint charts/<component>

# Full scan
scripts/scan.sh lint
scripts/scan.sh trivy
scripts/scan.sh checkov

# Bootstrap (in ops cluster)
kubectl apply -f argocd-bootstrap-apps/ops-01.yaml

# Check Argo CD status
kubectl get applications -n argocd
argocd app list

Key Files:

Key Concepts: