---
title: "Kapitan Examples: Kubernetes, Terraform, and Infrastructure"
description: "Explore curated Kapitan examples for Kubernetes, Terraform, and multi-environment infrastructure. Clone the reference repo and compile targets fast."
---

# :kapitan-logo: **Kapitan Examples**

The fastest way to understand Kapitan is to see it in action. This page collects official examples, reference repositories, and small tutorials you can run locally.

## Reference repository

The [kapicorp/kapitan-reference](https://github.com/kapicorp/kapitan-reference) repository is the best place to start. It contains working examples for Kubernetes, Terraform, and mixed infrastructure setups.

```shell
git clone git@github.com:kapicorp/kapitan-reference.git kapitan-templates
cd kapitan-templates

./kapitan compile
```

Expected output:

```
Compiled postgres-proxy (1.51s)
Compiled tesoro (1.70s)
Compiled echo-server (1.64s)
Compiled mysql (1.67s)
Compiled gke-pvm-killer (1.17s)
Compiled prod-sockshop (4.74s)
Compiled dev-sockshop (4.74s)
Compiled tutorial (1.68s)
Compiled global (0.76s)
Compiled examples (2.60s)
Compiled pritunl (2.03s)
Compiled sock-shop (4.36s)
```

The repository includes:

- **Kubernetes manifests** generated with Jsonnet and Kadet
- **Terraform resources** for GCP and AWS
- **Helm chart rendering** with inventory-driven values
- **Secrets management** with Kapitan References
- **Multi-environment setups** (development, staging, production)

## Minimal starter project

If you want a clean slate instead of a full reference repository, use the cookiecutter template:

```shell
pip3 install cruft
cruft create http://github.com/kapicorp/kapitan-reference --checkout cookiecutter --no-input
```

This creates a minimal Kapitan project with:

- A basic inventory structure (`inventory/classes/`, `inventory/targets/`)
- A pre-configured `kapitan` wrapper script
- A small working target you can compile immediately

## Input type examples

### Jsonnet

Generate Kubernetes manifests with Jsonnet and access the Kapitan inventory:

```jsonnet
local kap = import "lib/kapitan.libjsonnet";
local inv = kap.inventory();
local p = inv.parameters;

{
    "deployment": {
        apiVersion: "apps/v1",
        kind: "Deployment",
        metadata: {
            name: p.target_name,
            namespace: p.namespace,
        },
        spec: {
            replicas: p.nginx.replicas,
            template: {
                spec: {
                    containers: [{
                        name: "nginx",
                        image: p.nginx.image,
                    }],
                },
            },
        },
    },
}
```

See the full [Jsonnet input type documentation](input_types/jsonnet.md).

### Jinja

Write plain YAML templates with Jinja2 loops and conditionals:

```yaml
# templates/configmap.yml.j2
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ inventory.parameters.target_name }}
data:
  environment: {{ inventory.parameters.environment }}
```

See the full [Jinja input type documentation](input_types/jinja.md).

### Helm

Render an existing Helm chart with values from the Kapitan inventory:

```yaml
parameters:
  kapitan:
    compile:
      - output_path: .
        input_type: helm
        input_paths:
          - components/charts/nginx-ingress
        helm_values:
          controller:
            name: my-controller
        helm_params:
          name: my-release
          namespace: my-namespace
```

See the full [Helm input type documentation](input_types/helm.md).

### Kustomize

Apply Kustomize patches to base manifests generated by another input type:

```yaml
parameters:
  kapitan:
    compile:
      - output_path: manifests
        input_type: kustomize
        input_paths:
          - components/kustomize/overlays/production
```

See the full [Kustomize input type documentation](input_types/kustomize.md).

## Inventory examples

### Targets and classes

```yaml
# inventory/classes/common.yml
parameters:
  organization: ACME
  timezone: Europe/London
```

```yaml
# inventory/classes/environments/production.yml
classes:
  - common

parameters:
  environment: production
  nginx:
    replicas: 5
```

```yaml
# inventory/targets/production/web.yml
classes:
  - environments.production
  - components.nginx

parameters:
  target_name: web
```

See the [inventory introduction](inventory/introduction.md) for the full concept.

## Secrets examples

Create an encrypted reference with GPG:

```shell
kapitan refs --write gpg:targets/production/web/mysql/root_password -t production/web -f secret.txt
```

Use it in the inventory:

```yaml
parameters:
  mysql:
    root_password: ?{gpg:targets/production/web/mysql/root_password}
```

See the [References documentation](../references.md) for all backends.

## Related projects

- [Tesoro](https://github.com/kapicorp/tesoro) — Kubernetes Admission Controller for Kapitan secrets
- [Kapitan Reference](https://github.com/kapicorp/kapitan-reference) — working examples and starter templates
- [Kapitan Generators](https://generators.kapitan.dev) — reusable generators for Kubernetes and Terraform

---

## Next steps

- [Get started with Kapitan](../getting_started.md)
- Learn [Kapitan core concepts](core_concepts.md)
- Understand the [Kapitan inventory](inventory/introduction.md)
- Compare [Kapitan vs Helm vs Kustomize](kapitan_vs_helm_kustomize.md)
