MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

kapitan Command line reference

Kapitan is an open-source tool that generates Kubernetes manifests, Terraform JSON, scripts and documentation from one hierarchical inventory, using Jsonnet, Jinja2, Kadet or Helm templates. The help text above lists its subcommands. This page explains what each one does and shows the flags you will use most, and it includes a small working project so you can try compile, inventory, refs, lint and validate for yourself.


usage: kapitan [-h] [--version] {eval,e,compile,c,inventory,i,searchvar,sv,secrets,s,refs,r,lint,l,init,validate,v} ...

Generic templated configuration management for Kubernetes, Terraform and other things

positional arguments:
  {eval,e,compile,c,inventory,i,searchvar,sv,secrets,s,refs,r,lint,l,init,validate,v}
                        commands
    eval (e)            evaluate jsonnet file
    compile (c)         compile targets
    inventory (i)       show inventory
    searchvar (sv)      show all inventory files where var is declared
    secrets (s)         (DEPRECATED) please use refs
    refs (r)            manage refs
    lint (l)            linter for inventory and refs
    init                initialize a directory with the recommended kapitan project skeleton.
    validate (v)        validates the compile output against schemas as specified in inventory

optional arguments:
  -h, --help            show this help message and exit
  --version             show program's version number and exitCode language: JavaScript (javascript)

What Kapitan does and how the commands fit together

Kapitan is built around targets. A target is one YAML file under inventory/targets/, and it usually stands for one environment or deployment, such as dev or prod-eu. A target pulls in reusable classes from inventory/classes/ and sets parameters. When you run kapitan compile, Kapitan merges those parameters into a single inventory for each target. It then renders the templates listed under parameters.kapitan.compile and writes the results to compiled/<target>/.

The subcommands in the help output fall into three groups:

PurposeCommandsAliases
Create and renderinit, compile, evalc, e
Inspect the inventoryinventory, searchvari, sv
Secrets and qualityrefs, lint, validate (secrets is deprecated)r, l, v

Note: Kapitan is not part of Terraform, even though this post sits in the Terraform category. It can write Terraform configuration as .tf.json files, which terraform init, plan and apply then read from the compiled directory.

Installing Kapitan

Kapitan is a Python package. You can install it with pip or run the official container image. Use one of these two options:

# Option 1: pip (Python 3)
pip3 install --user --upgrade kapitan
export PATH="$HOME/.local/bin:$PATH"
kapitan --version

# Option 2: Docker (run from your project root)
alias kapitan='docker run -t --rm -u $(id -u) -v $(pwd):/src:delegated kapicorp/kapitan'
kapitan --versionCode language: PHP (php)

The Docker image works in /src, so mount your project there. The -u $(id -u) option makes the compiled files belong to your user instead of root.

Command reference with examples

CommandCommon usageWhat it does
initkapitan initCreates a recommended project skeleton (inventory, components, templates, lib). Flags differ between releases, so check kapitan init --help.
compile / ckapitan compile or kapitan compile -t dev prodCompiles every target, or only the targets listed after -t/--targets. Output goes to compiled/ unless you set --output-path.
inventory / ikapitan inventory -t devPrints the fully merged inventory for a target. Leave out -t to print all targets. Add --flat for dotted keys.
searchvar / svkapitan searchvar parameters.namespaceLists every inventory file that declares the given variable. Use it to find where a value is overridden.
eval / ekapitan eval file.jsonnet --output yamlEvaluates one Jsonnet file and prints the result without compiling any target.
refs / rkapitan refs --write gpg:dev/db_pass -f pass.txt and kapitan refs --reveal -f <compiled file>Writes encrypted or referenced secrets to refs/ and reveals them in compiled files.
lint / lkapitan lint --fail-on-warningLooks for unused classes, YAML problems and, with --search-secrets, possible plain-text secrets.
validate / vkapitan validateChecks compiled Kubernetes manifests against the schemas configured under parameters.kapitan.validate.
secrets / s(do not use)Deprecated alias for the old secrets workflow. Use refs instead. Newer releases may not include it.

Every subcommand has its own help, for example kapitan compile --help. These compile flags are useful in CI: -p/--parallelism sets how many targets compile in parallel, --fetch downloads external dependencies such as Helm charts or Git sources listed in the inventory, and --inventory-path points to an inventory outside the default ./inventory.

Hands-on: a minimal project

This project needs only three files. It renders one ConfigMap for a dev target from a shared class and a Jinja2 template.

mkdir -p kapitan-demo/inventory/classes kapitan-demo/inventory/targets kapitan-demo/templates
cd kapitan-demo
# inventory/classes/common.yml
parameters:
  log_level: info
  kapitan:
    compile:
      - output_path: manifests
        input_type: jinja2
        input_paths:
          - templates/configmap.ymlCode language: PHP (php)
# inventory/targets/dev.yml
classes:
  - common
parameters:
  namespace: dev
  log_level: debug        # overrides the value from the common class
  kapitan:
    vars:
      target: devCode language: PHP (php)
# templates/configmap.yml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
  namespace: {{ inventory.parameters.namespace }}
data:
  LOG_LEVEL: "{{ inventory.parameters.log_level }}"
  1. Run kapitan inventory -t dev and confirm that log_level is debug. This shows that values set in the target override values from its classes.
  2. Run kapitan searchvar parameters.log_level. Both common.yml and dev.yml should appear in the output.
  3. Run kapitan compile. The output looks similar to Compiled dev (0.05s).
  4. Check the result with cat compiled/dev/manifests/configmap.yml. It should contain namespace: dev and LOG_LEVEL: "debug".
  5. Apply it with kubectl apply -f compiled/dev/manifests/ if you have a cluster.

Note: Commit the compiled/ directory to Git. Kapitan recommends this so that pull request diffs show exactly what will change in your clusters or cloud accounts.

Managing secrets with refs

Refs keep secrets out of the inventory. You store an encrypted value under refs/, and the inventory or a template points to it with the ?{backend:path} syntax. Compiled files contain only a hashed reference until you reveal them.

# Store a value with the base64 backend (encoding only, for demos)
echo -n 's3cr3t' | kapitan refs --write base64:dev/db_password -f -

# Reference it in the inventory:
#   parameters:
#     db_password: ?{base64:dev/db_password}

kapitan compile

# Print the compiled file with real values substituted
kapitan refs --reveal -f compiled/dev/manifests/configmap.ymlCode language: PHP (php)

For real secrets, use an encrypting backend: gpg (with --recipients), gkms, awskms or azkms (with --key), or vaultkv. With -t <target>, Kapitan reads the key or recipients from that target's parameters.kapitan.secrets section, so you do not have to repeat them on every command.

Note: base64 and plain refs are not encrypted. Do not use them for production credentials. Only run refs --reveal in a trusted pipeline step, and never commit the revealed output.

Common errors and fixes

SymptomLikely causeFix
kapitan: command not found after pip install~/.local/bin is not on PATHAdd it to PATH, or use a virtualenv or the Docker image.
Class not found error during compileA name under classes: does not match a file pathcomponent.nginx maps to inventory/classes/component/nginx.yml. Check the spelling and the folders.
Template renders empty or wrong valuesWrong inventory key pathRun kapitan inventory -t <target> to see the actual structure.
refs --reveal failsMissing GPG private key or cloud KMS credentialsImport the key or authenticate to the cloud provider in that shell.
Compiled files owned by rootDocker run without -u $(id -u)Add the user flag, or run chown on compiled/.

Best practices

  • Keep targets small. Put shared defaults in classes and override only what differs in each target.
  • In CI, run kapitan lint --fail-on-warning, kapitan compile and kapitan validate, then fail the build if git diff --exit-code compiled/ shows uncommitted changes.
  • Pin the Kapitan version (a pip version or a Docker image tag) so every engineer and pipeline produces identical output.
  • For Terraform output, run the usual Terraform checks on the generated directory. See pre-commit for Terraform and TFSec scanning.

Frequently asked questions

What is Kapitan used for?

Kapitan generates configuration files, such as Kubernetes manifests, Terraform JSON, scripts and docs, from one hierarchical inventory. Many environments can then share the same templates and differ only in their parameters.

How do I compile only one Kapitan target?

Run kapitan compile -t <target_name>, where the target name matches the file name in inventory/targets/. You can list several targets after -t.

Is kapitan secrets still supported?

No. The secrets command is deprecated and replaced by kapitan refs, which supports the same backends and more. Newer releases may not include secrets at all.

Can Kapitan replace Terraform?

No. Kapitan can write Terraform configuration as .tf.json files, but you still run Terraform to plan and apply them.

Where does Kapitan write its output?

By default, compiled files go to compiled/<target>/<output_path>, where output_path comes from the target's parameters.kapitan.compile entries. You can change the base directory with --output-path.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

How Ansible Automates Cisco IOS and IOS XE Network Devices

Introduction Managing multiple Cisco routers and switches manually can become time-consuming as a network grows. Network engineers regularly configure interfaces, check device status, update settings, and troubleshoot…

Read More

Puppet Training Agenda: A Practical Roadmap from Basics to Real-World Automation

This revised guide converts the original Puppet course outline into a clear learning path for DevOps and platform teams. It covers architecture, run cycle, hands-on manifests, ecosystem tools, and common implementation pitfalls.

Read More

Chef Training Roadmap for DevOps Engineers: Course Tracks, Lab Workflow, and Practical Commands

This guide turns a promotional Chef training post into a practical roadmap for engineers. Compare course levels, understand the learning workflow, and use hands-on commands you can run in a lab.

Read More

Server Configuration Monitoring and Diagnostics: A Practical Drift-Detection Workflow

Learn how to monitor server configuration drift and run fast diagnostics when something changes unexpectedly. This guide gives a practical workflow, approach comparison, and command examples you can adapt to your environment.

Read More

DevOps Tools Collection: A Practical Guide to CI, SCM, Monitoring, and Platform Choices

This revised guide turns the original link collection into a structured DevOps resource map. Use it to navigate tool categories, compare adoption models, and bootstrap a practical toolchain.

Read More

Puppet vs Chef vs Ansible vs CFEngine vs Salt: A Practical Configuration Management Guide

Compare five long-standing configuration management tools across architecture, operating model, and day-to-day usage. This revised guide helps DevOps teams choose the best fit for their infrastructure automation workflow.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x