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 Tutorial: How to install Kapitan?

Kapitan is an open-source tool from Kapicorp for templated configuration management. It builds Kubernetes manifests, Terraform files, scripts and documentation from one inventory, and it can handle secrets. This page shows how to install it on Ubuntu with pip or Docker. The notes below update those commands for current Ubuntu releases and walk you through compiling your first target to check that the install works.


Install Kapitan in Ubuntu


$ sudo apt-get update && sudo apt-get install -y python3.8-dev python3-pip python3-yaml
$ pip3 install --user --upgrade kapitan

# kapitan will be installed in $HOME/.local/lib/python3.7/bin

#not recommended

$ sudo pip3 install --upgrade kapitanCode language: PHP (php)

Install Kapitan using Docker Container


# Linux
$ alias kapitan="docker run -t --rm -u $(id -u) -v $(pwd):/src:delegated kapicorp/kapitan"
$ kapitan -h

# Mac
$ alias kapitan="docker run -t --rm -v $(pwd):/src:delegated kapicorp/kapitan"
$ kapitan -h
Code language: PHP (php)

Create Kapitan Project from Scratch


If you want to start off with a clean kapitan project, you can run kapitan init --directory <directory> to populate a new directory with the recommended kapitan folder structure.

The bare minimum structure that makes use of kapitan features may look as follows:

$ kapitan init –directory <directory>

Kapitan project folder structure with components, templates, inventory and refs directories explained

Choosing an installation method

Kapitan is a Python application that is published on PyPI and as the kapicorp/kapitan container image. All the methods give you the same CLI. They differ in how they handle Python versions and where the files go.

MethodBest forNotes
Python virtual environmentWorkstations and CI runners with Python 3Keeps Kapitan's dependencies away from the system Python. Works on Ubuntu 23.04 and later.
pipxOne global kapitan command per userpipx creates and manages the virtual environment for you.
Docker imageMachines without a suitable Python, or teams that need identical versionsNeeds Docker. Files are reached through a bind mount.
pip3 install --userOlder distributions onlyBlocked by default on recent Ubuntu (PEP 668).

Note: Recent Kapitan releases need a modern Python 3. If pip only finds an old Kapitan version, or refuses to install it, your Python is probably too old. The PyPI page lists the supported Python versions for each release.

Corrected Ubuntu installation using a virtual environment

The apt command above installs python3.8-dev. That package exists only on older releases such as Ubuntu 20.04. On 22.04 and 24.04, apt reports that it has no installation candidate. Install the generic packages instead, and put Kapitan in a virtual environment:

sudo apt-get update
sudo apt-get install -y python3 python3-venv python3-pip python3-dev build-essential

# Create an isolated environment for Kapitan
python3 -m venv ~/.venvs/kapitan
source ~/.venvs/kapitan/bin/activate

pip install --upgrade pip
pip install --upgrade kapitan

kapitan --versionCode language: JavaScript (javascript)

python3-dev and build-essential are only needed when a dependency has no prebuilt wheel for your platform and pip has to compile it. Installing them up front prevents confusing build failures. You do not need python3-yaml, because pip installs PyYAML as a Kapitan dependency.

To run kapitan without activating the environment each time, link the binary into a directory on your PATH:

mkdir -p ~/.local/bin
ln -sf ~/.venvs/kapitan/bin/kapitan ~/.local/bin/kapitan

# Add ~/.local/bin to PATH if it is not already there
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
which kapitanCode language: PHP (php)

Note: With pip3 install --user, the kapitan executable goes in ~/.local/bin, not $HOME/.local/lib/python3.7/bin as the comment above says. The library files go under ~/.local/lib/python3.X/site-packages.

Installing with pipx

pipx installs each Python CLI in its own virtual environment and exposes the command in ~/.local/bin. This gives you the same isolation as the manual method with fewer steps:

sudo apt-get install -y pipx
pipx ensurepath        # adds ~/.local/bin to PATH; open a new shell afterwards
pipx install kapitan
kapitan --version

# Later upgrades
pipx upgrade kapitanCode language: PHP (php)

Running Kapitan with Docker

The Docker aliases above work. In both, --rm removes the container after each run, and -v $(pwd):/src mounts the current project into the container's working directory. On Linux, -u $(id -u) makes sure that files written to compiled/ are owned by you and not by root. The :delegated mount flag only ever mattered on Docker Desktop for Mac and can be left out.

A shell function passes arguments more reliably than an alias, and a pinned image tag keeps results the same across machines:

# Add to ~/.bashrc or ~/.zshrc
kapitan() {
  docker run -t --rm \
    -u "$(id -u):$(id -g)" \
    -v "$(pwd)":/src \
    kapicorp/kapitan "$@"
}

kapitan --versionCode language: PHP (php)
  • Replace kapicorp/kapitan with a specific release tag from Docker Hub, so that every engineer and CI job compiles with the same version.
  • Run the function from the project root. The container only sees the directory you mount, so files outside it, such as ../shared, are not available.
  • If you use GPG-backed secrets, also mount your keyring into the container at the path your image expects, or run Kapitan natively instead.

Verifying the install with a first target

kapitan init --directory <directory> creates the recommended layout: inventory/ for classes and targets, plus folders for components and templates. You can also write a minimal project by hand, which shows how the parts connect:

mkdir -p demo/inventory/targets demo/templates && cd demo

cat > inventory/targets/dev.yml <<'EOF'
parameters:
  app:
    name: demo-app
    replicas: 2
  kapitan:
    vars:
      target: dev
    compile:
      - output_path: manifests
        input_type: jinja2
        input_paths:
          - templates/configmap.yml
EOF

cat > templates/configmap.yml <<'EOF'
apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ inventory.parameters.app.name }}
data:
  replicas: "{{ inventory.parameters.app.replicas }}"
EOF

kapitan compileCode language: JavaScript (javascript)

Kapitan reads every file in inventory/targets/, renders the inputs listed under parameters.kapitan.compile and writes the results to compiled/<target>/. Here the rendered file is compiled/dev/manifests/configmap.yml, with demo-app and "2" filled in. Some other useful commands:

kapitan inventory -t dev      # show the merged inventory for one target
kapitan compile -t dev        # compile a single target
kapitan searchvar parameters.app.name   # find where a variable is definedCode language: PHP (php)

Common errors and fixes

ErrorCauseFix
error: externally-managed-environmentUbuntu 23.04+ blocks pip from writing to the system or user site-packages (PEP 668).Use a virtual environment or pipx. Avoid --break-system-packages.
Package python3.8-dev has no installation candidateThat versioned package is not in your Ubuntu release.Install python3-dev instead.
kapitan: command not found~/.local/bin or the venv's bin is not on PATH.Activate the venv, run pipx ensurepath, or update PATH and open a new shell.
Permission denied writing compiled/ (Docker)The container ran as root earlier and created root-owned files.Run sudo chown -R $USER: compiled and always pass -u $(id -u).
permission denied ... docker.sockYour user cannot reach the Docker daemon.Add the user to the docker group (sudo usermod -aG docker $USER), then log in again.
Target not found or empty outputYou ran Kapitan outside the project root, or input_paths is wrong.Run from the directory that contains inventory/, or pass --inventory-path. Check that the paths are relative to the root.

Best practices

  • Pin the Kapitan version (pip install kapitan==<version> or a fixed image tag) in CI and on workstations. Different versions can render different output.
  • Commit compiled/ if your team reviews generated manifests in pull requests. Otherwise, regenerate it in CI and check for differences.
  • Never use sudo pip3 install. Root-level pip installs can break system tools that depend on Python packages managed by apt.
  • Store secrets with Kapitan refs (GPG, cloud KMS or Vault backends) instead of plain values in the inventory.

Frequently asked questions

Why does pip3 install –user kapitan fail on Ubuntu 24.04?

Ubuntu 23.04 and later mark the system Python as externally managed (PEP 668), so pip refuses to install into it. Install Kapitan in a virtual environment or with pipx install kapitan instead.

Where is the kapitan executable installed?

A --user or pipx install puts it in ~/.local/bin. A virtual environment install puts it in the environment's bin directory, for example ~/.venvs/kapitan/bin/kapitan.

How do I check which Kapitan version is installed?

Run kapitan --version. With Docker, the version depends on the image tag you pull, so pin a tag to keep it predictable.

Can I use Kapitan on macOS or Windows?

Yes. On macOS, use pipx, a virtual environment or the Docker image. On Windows, the most reliable option is WSL2 with the Ubuntu steps on this page, or Docker Desktop.

How do I upgrade Kapitan?

Run pip install --upgrade kapitan inside the virtual environment, pipx upgrade kapitan for pipx, or pull a newer image tag for Docker. Recompile afterwards and review any differences in compiled/.

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

Newrelic Tutorials: How to Integrate Apache2 in ubuntu

This tutorial shows how to monitor Apache HTTP Server (apache2) on Ubuntu with the New Relic Apache integration. It covers installing Apache, exposing the mod_status page that…

Read More

How to Install Helix Core (Perforce Server)

To install Helix Core (the Perforce server, p4d) on Ubuntu, add the official Perforce APT repository and install the helix-p4d package. Then run the bundled configure-helix-p4d.sh script…

Read More

How to install Kapitan in Windows using wsl?

Kapitan is a Python-based configuration management tool, and on Windows it runs best inside the Windows Subsystem for Linux (WSL). This guide fills in the commands the…

Read More

Install and Configure Gerrit on CentOS and Ubuntu (MySQL + Apache Reverse Proxy)

A practical, step-by-step guide to installing Gerrit for code review on CentOS/RHEL and Ubuntu/Debian. Includes package command comparisons, setup workflow, Apache proxy configuration, and verification checks.

Read More

Install Enlightenment E17 from SVN/Source on Ubuntu (Legacy Method, Updated Guidance)

This revised guide explains the original 2010 workflow for installing Enlightenment E17 from source on Ubuntu using the easy_e17 script. It keeps the legacy commands intact while adding safety checks, verification steps, and modern caveats.

Read More

Datadog Log: Lab and Assignment

Lab Manual: Datadog Logs Search, Filter, Sorting, Display, and Analysis Hands-on Datadog Logs Explorer Lab using Ubuntu Linux Logs and Apache Logs Lab Objective By the end…

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