Garden Cheat Sheet
Overview
Garden is a development platform for cloud-native applications that automates the build-test-deploy cycle for Kubernetes workloads. It provides a graph-based execution engine that understands dependencies between services, enabling incremental builds, remote development, and end-to-end testing across microservice architectures.
Garden uses declarative configuration (garden.yml) to define how services are built, deployed, and tested. It supports Docker, Helm, Kubernetes manifests, and Terraform, and can run workflows locally or in remote Kubernetes clusters. Garden’s smart caching ensures only changed components are rebuilt and redeployed.
Installation
# macOS
brew install garden-io/garden/garden-cli
# Linux
curl -sL https://get.garden.io/install.sh | bash
# Windows
choco install garden-io
# npm
npm install -g garden-cli
# Verify
garden version
Core Commands
| Command | Description |
|---|---|
garden deploy | Build and deploy all services |
garden dev | Start interactive dev mode |
garden test | Run all tests |
garden build | Build all modules |
garden logs <service> | Stream service logs |
garden exec <service> <cmd> | Execute command in service |
garden get status | Show deployment status |
garden delete | Delete deployed services |
garden validate | Validate configuration |
garden create project | Create new project |
Project Configuration
Basic garden.yml (Project Root)
apiVersion: garden.io/v1
kind: Project
name: my-app
defaultEnvironment: local
environments:
- name: local
defaultNamespace: my-app-dev
- name: staging
defaultNamespace: my-app-staging
- name: production
defaultNamespace: my-app-prod
providers:
- name: local-kubernetes
environments: [local]
context: docker-desktop
- name: kubernetes
environments: [staging, production]
context: my-cluster
defaultHostname: ${environment.name}.myapp.example.com
Service Module
# services/api/garden.yml
apiVersion: garden.io/v1
kind: Module
type: container
name: api
build:
dependencies:
- shared-lib
services:
- name: api
ports:
- name: http
containerPort: 8080
ingresses:
- path: /api
port: http
env:
DATABASE_URL: postgres://postgres:password@postgres:5432/myapp
REDIS_URL: redis://redis:6379
dependencies:
- postgres
- redis
healthCheck:
httpGet:
path: /health
port: http
tests:
- name: unit
command: [npm, test]
- name: integration
command: [npm, run, test:integration]
dependencies:
- postgres
- api
Helm Module
# services/postgres/garden.yml
apiVersion: garden.io/v1
kind: Module
type: helm
name: postgres
chart:
name: postgresql
repo: https://charts.bitnami.com/bitnami
version: "14.0.0"
values:
auth:
postgresPassword: password
database: myapp
primary:
persistence:
size: 1Gi
Development Workflow
Dev Mode
# Start interactive development
garden dev
# Dev mode features:
# - File watching with auto-rebuild/redeploy
# - Log streaming
# - Port forwarding
# - Interactive command execution
# Deploy specific services
garden deploy api frontend
# Deploy with sync (hot-reload)
garden deploy --sync api
Code Sync (Hot Reload)
# garden.yml with sync configuration
apiVersion: garden.io/v1
kind: Module
type: container
name: api
services:
- name: api
ports:
- name: http
containerPort: 8080
sync:
paths:
- source: ./src
target: /app/src
mode: two-way
command: [npm, run, dev]
overrides:
- command: [npm, run, dev]
Testing
# Run all tests
garden test
# Run specific test
garden test api-unit
garden test api-integration
# Run tests with dependencies
garden test --force
# Watch mode
garden test --watch
Configuration
Variables and Templates
# garden.yml
apiVersion: garden.io/v1
kind: Project
name: my-app
variables:
registry: myregistry.example.com
domain: myapp.example.com
---
apiVersion: garden.io/v1
kind: Module
type: container
name: api
image: ${var.registry}/api:${modules.api.version}
services:
- name: api
ingresses:
- hostname: api.${var.domain}
path: /
port: http
Environment-Specific Config
environments:
- name: local
variables:
replicas: 1
logLevel: debug
- name: staging
variables:
replicas: 2
logLevel: info
- name: production
variables:
replicas: 5
logLevel: warn
Workflows
apiVersion: garden.io/v1
kind: Workflow
name: ci
steps:
- name: build
command: [build]
- name: deploy
command: [deploy]
- name: test-unit
command: [test, "--name", "unit-*"]
- name: test-integration
command: [test, "--name", "integration-*"]
- name: cleanup
command: [delete]
skip: ${environment.name != 'ci'}
garden run workflow ci
Advanced Usage
Terraform Integration
apiVersion: garden.io/v1
kind: Module
type: terraform
name: infrastructure
autoApply: true
root: ./terraform
variables:
region: us-east-1
environment: ${environment.name}
Remote Sources
apiVersion: garden.io/v1
kind: Project
name: my-app
sources:
- name: shared-modules
repositoryUrl: https://github.com/org/shared-garden-modules.git#v1.0.0
Custom Commands
apiVersion: garden.io/v1
kind: Module
type: exec
name: scripts
tasks:
- name: db-migrate
command: [bash, -c, "cd api && npm run migrate"]
dependencies:
- deploy.postgres
- deploy.api
- name: db-seed
command: [bash, -c, "cd api && npm run seed"]
dependencies:
- db-migrate
garden run task db-migrate
garden run task db-seed
CI/CD Integration
# .github/workflows/ci.yml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: garden-io/garden-action@v1
with:
command: test
kubeconfig: ${{ secrets.KUBECONFIG }}
deploy:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: garden-io/garden-action@v1
with:
command: deploy --env production
kubeconfig: ${{ secrets.KUBECONFIG }}
Troubleshooting
| Issue | Solution |
|---|---|
| Build cache miss | Check module dependencies; run garden build --force |
| Deploy timeout | Increase timeout in service config; check pod health |
| Sync not working | Verify sync paths; check container has correct mounts |
| Tests failing in CI | Ensure dependencies are deployed; check env vars |
| Config validation error | Run garden validate for detailed errors |
| Cluster access denied | Check kubeconfig context and RBAC |
# Validate configuration
garden validate
# Debug output
garden deploy --log-level verbose
# Show dependency graph
garden get graph
# Show status of all resources
garden get status
# Clean up
garden delete
garden delete --env staging
# Show module details
garden get modules