> ## Documentation index
> Fetch the complete documentation index at: https://k7d.org/llms.txt
> Ask it with GET https://k7d.org/ask?q=<keywords or question>. Short keywords rank best.
> Use these to discover all available pages before exploring further.

# Quickstart

> Install k7, prepare your node, start the API, and run your first sandbox

k7 lets you run secure VM sandboxes on Kubernetes — Firecracker, QEMU + Longhorn, or [k7d](/k7d/index) (natively or under the Firecracker jailer). This Quickstart gets you from zero to a working sandbox via CLI and Python SDK.

<Note>
If you already installed k7 previously, consider running `make uninstall` before reinstalling to avoid stale cached files in a previous `.deb`.
</Note>

<Note>
These pages track **k7 0.5.0** (tenants, roles and OIDC login, metering, the signed GHCR `k7-api` image, Helm chart, remote node install; Firecracker v1.16.2). The playbook still pins [k7d 0.7.0](https://github.com/Katakate/k7d/releases/tag/v0.7.0) by default. The Launchpad PPA and PyPI `k7-sdk` publish **0.5.0**. Read the [CHANGELOG](https://github.com/Katakate/k7/blob/main/CHANGELOG.md).
</Note>

## Requirements

- Ubuntu host with hardware virtualization (KVM)
  - Check: `ls /dev/kvm` should exist
  - **`kfd` and `kql`**: amd64 or arm64. **`k7d` and `k7d-fc` are amd64 / x86_64 only.**
  - Cloud guidance: AWS `.metal`, GCP (enable nested virtualization), Azure D/Ev series; typical VPS often lack KVM. Hetzner: Robot dedicated only (not Cloud VPS).
- For the `kfd` (Firecracker) backend: one raw, unformatted disk for the LVM thin-pool. `kql`, `k7d`, and `k7d-fc` do not need a spare disk.
- **No Docker and no source checkout.** 0.5.0 deploys the signed GHCR `k7-api` image by digest (`images.lock.yaml`, cosign-verified). Building `k7-api:local` from a checkout, which 0.4.0 did by default, is opt-in with `k7 install --api-image local`.
- Ansible for the installer (Ubuntu), on the machine that runs `k7 install`:

```bash
sudo add-apt-repository universe -y
sudo apt update
sudo apt install -y ansible
```

- Python 3.10+ on the client for the SDK

<Info>
Tested setup: Hetzner Robot dedicated, Ubuntu 24.04, with a **spare raw NVMe** for the `kfd` thin-pool. Dual-NVMe boxes (no third drive): put Ubuntu on **one** disk (`SWRAID 0`) and leave the other raw — see [Hetzner node setup](https://github.com/Katakate/k7/blob/main/tutorials/k7_hetzner_node_setup.md). Do **not** pin `--disk /dev/nvme1n1`: NVMe names swap across reboots; the playbook auto-detects the empty non-root disk.
</Info>

## Install the CLI

The Launchpad PPA publishes **0.5.0** (`k7 -V` after install). PyPI `k7-sdk` is the same version.

```bash
sudo add-apt-repository ppa:katakate.org/k7
sudo apt update
sudo apt install k7
k7 -V   # 0.5.0
```

The same package is on the [GitHub release](https://github.com/Katakate/k7/releases/tag/v0.5.0) if you prefer not to add the PPA:

```bash
curl -fsSL -O https://github.com/Katakate/k7/releases/download/v0.5.0/k7_0.5.0_amd64.deb
sudo apt install ./k7_0.5.0_amd64.deb
```

## Install K7 on your node(s)

`k7 install` runs from any directory — no clone, no Docker. It deploys the signed `ghcr.io/katakate/k7-api` image at the digest recorded in the release's `images.lock.yaml`, and verifies the cosign signature before use.

```bash
k7 install --backend kfd,kql,k7d,k7d-fc --api-mode development
```

Two flags are **required** (no silent defaults):

- `--backend`: `kfd` needs a spare raw disk; `kql` uses Longhorn on the OS disk; `k7d` is the warm-fork daemon; `k7d-fc` adds jailed Firecracker **v1.16.2**; `none` is control-plane only. The playbook pins [k7d 0.7.0](https://github.com/Katakate/k7d/releases/tag/v0.7.0).
- `--api-mode`: `production` (every API key belongs to a [tenant](/k7/guides/tenants-and-roles), HTTPS only, metering mandatory) or `development` (unscoped keys keep working, remote install allowed). Documented in [Hardening](/k7/concepts/security-model#production-and-development-modes).

That installs and wires up Kubernetes (K3s `v1.36.5+k3s1`, override with `--k3s-version`), Cilium, Kata, Firecracker + Jailer + thin-pool (`kfd`), QEMU + Longhorn (`kql`), and the k7d daemon + `RuntimeClass k7` / `k7-fc` (`k7d`, `k7d-fc`). It also deploys the `k7-api` (2 replicas) over HTTPS with a cluster CA, the non-privileged `k7-agent` DaemonSet, Prometheus metrics and the metering spool. Pass `-v` for verbose output. Two-node / HA inventories: [Multi-node clusters](/k7/guides/multi-node); install-time knobs (`--api-allow-cidr`, `--api-hostname`, `--oidc-*`, `--dns-upstream`, `--metering-*`, `--hubble`): [CLI reference](/k7/guides/cli#install). To install a k7d tarball you built yourself instead of GitHub `v0.7.0`, pass `--k7d-artifact /path/to/k7d-v0.9.0-x86_64-linux.tar.gz`.

Already running Kubernetes (RKE2, kubeadm, EKS)? The same stack ships as a Helm chart (`deploy/helm/k7`) that never installs Kubernetes, the CNI or the CSI driver: see [Helm chart](/k7/guides/multi-node#helm-chart-for-existing-clusters).

![Example output: k7 install](/k7/images/ex-install.png)

<Check>
You should see "Installation completed successfully!" when done. Add `-v` for verbose output.
</Check>

## The API and managing keys

`k7 install` deploys the K7 API automatically as a `k7-api` Deployment in
`kube-system`. K3s keeps it running and reschedules it on failure — there's
no separate "start" step. If you want a CLI-only install with no API
deployed, pass `--no-api` to `k7 install`.

### Check API status

On a cluster node (needs `kubectl` / `k3s kubectl`):

```bash
k7 api status
```

From a laptop after `k7 config set`, the same command probes `GET /health` on the configured URL instead of crashing. Replica counts still need kubectl on the node.

### Get the endpoint

```bash
k7 api endpoint          # https://<first-master-ip>:31007
```

On a node this is `/etc/k7/api_endpoint`. From a laptop it prints the URL you configured.

### Trust the cluster CA from your laptop

The default install serves the API over HTTPS with a certificate signed by a cluster CA the playbook minted (Let's Encrypt cannot issue for a bare IP). Copy the CA off the node once and point the CLI at it:

```bash
scp root@<node>:/etc/k7/tls/ca.crt ./k7-ca.crt
k7 config set api.url https://<node-ip>:31007
k7 config set api.ca  ./k7-ca.crt
k7 config set api.key <key>          # from the next step
```

If you installed with `--api-hostname k7.example.com`, the certificate is publicly trusted and `api.ca` is unnecessary. On the node itself the CLI finds `/etc/k7/api_endpoint` and `/etc/k7/tls/ca.crt` automatically; you still have to `k7 config set api.key` with the token `generate-api-key` printed.

### Generate an API key

Every key has a **role** (`--role` is required): `read-only` and `user` belong to a tenant, `operator` and `admin` are cluster-wide. In `--api-mode development` a `user` key without `--tenant` keeps the pre-0.5 "unscoped" behaviour; in `production` every `read-only`/`user` key needs a tenant.

```bash
k7 generate-api-key mykey --role admin                       # cluster-wide, manages keys/tenants/nodes
k7 tenant create acme -n acme-dev -n acme-prod               # a tenant owns namespaces (and quotas, defaults)
k7 generate-api-key acme-ci --role user --tenant acme        # reaches every namespace of acme
k7 generate-api-key acme-ro --role read-only --tenant acme -n acme-dev   # narrowed further to one namespace
```

A tenant key cannot list or mutate another tenant's namespaces and cannot run all-namespaces operations. Details and quotas: [Tenants, roles and OIDC](/k7/guides/tenants-and-roles).

**Save the printed key.** `k7 generate-api-key` stores only a hash in the `kube-system/k7-api-keys` Secret — the raw token is shown once and is **not** auto-loaded on the node. Key commands edit that Secret through kubectl, so run them on a server node (or add `--api` to go through k7-api with an `admin` credential). Point the CLI at it (laptop or node):

```bash
k7 config set api.url https://<node-ip>:31007   # laptop; on the node this is auto-read from /etc/k7/api_endpoint
k7 config set api.ca  ./k7-ca.crt                # laptop; on the node /etc/k7/tls/ca.crt is used automatically
k7 config set api.key <the-printed-key>
k7 list
```

Humans can skip keys altogether: with `k7 install --oidc-issuer … --oidc-client-id …`, `k7 login` signs in through the IdP (device flow by default, `--browser` for Authorization Code + PKCE) and stores a short-lived token; `k7 whoami` shows the resolved role.

![Example: k7 generate-api-key](/k7/images/ex-generate-api-key.png)

### Temporarily disable / re-enable the API

```bash
k7 api disable        # scale k7-api to 0 (temporary off; records the replica count)
k7 api enable         # scale back to the recorded count (default 2)
```

<Info>
- API keys live in the `kube-system/k7-api-keys` Secret (hashes only); every API replica picks up a change within 5 seconds. Keys created before 0.5.0 in `/etc/k7/api_keys.json` were migrated by `k7 install` (`k7 api keys migrate`) and keep working until they expire.
  Authentication accepts the `X-API-Key` header or `Authorization: Bearer <token>` (API key or OIDC JWT).
- The previous top-level commands `k7 start-api` / `k7 stop-api` /
  `k7 api-status` / `k7 get-api-endpoint` are hidden deprecated aliases that
  forward to `k7 api …` with a warning.
</Info>

## Create your first sandbox via CLI

Example `k7.yaml`:

```yaml
name: demo
image: alpine:3.20
namespace: default
backend: k7d
# env_file: /root/secrets.env   # optional; omit unless that file exists on the node
limits:
  cpu: "1"
  memory: "1Gi"
before_script: |
  # Installing curl. Egress is open during before_script, then restricted (empty whitelist) afterwards.
  apk add curl
egress_whitelist: []
```

Do not use `cpu: 100m` / `memory: 128Mi`. Kata Firecracker refuses hypervisor memory below **256Mi** (`io.katacontainers.config.hypervisor.default_memory`) and the pod stays `ContainerCreating` until create times out. Use at least `1Gi` (or omit `limits`).

### Create a sandbox

```bash
# Uses k7.yaml in the current directory by default
k7 create

# Or pick a backend (kfd | kql | k7d | k7d-fc)
k7 create -f k7.yaml --backend k7d

# Need docker build / docker run inside the sandbox? (see the Docker guide)
k7 create --docker --backend k7d --egress-open builder ubuntu:24.04
```

<Note>
CLI `k7 create` with no `--egress` / `--egress-open` **blocks all egress**. An API/YAML request that omits `egress_whitelist` leaves egress **open**. Use `--egress-open` or omit the field in YAML when you want the internet.
</Note>

![Example: k7 create](/k7/images/ex-create.png)

### Shell into your sandbox

```bash
k7 exec demo -- echo hello          # works from a laptop via the API
k7 shell demo                      # interactive; node-local (needs kubectl)
```

![Example: k7 shell](/k7/images/ex-shell.png)

### List sandboxes

```bash
k7 list
```

![Example: k7 list](/k7/images/ex-list.png)

### Delete a sandbox

```bash
k7 delete my-sandbox-123
```

### Delete all sandboxes

```bash
k7 delete-all
```

### Prerequisites for the SDK

```bash
# `k7 install` already deployed the API; just grab the endpoint and a key
k7 api endpoint
k7 generate-api-key my-key --role user      # add --tenant <name> in production mode
```

<Warning>
Always pass the cluster CA (`./k7-ca.crt` from your laptop, or `/etc/k7/tls/ca.crt` on the node). `k7 api status` prints an SDK snippet that already includes `verify_ssl`.
</Warning>

## Create your first sandbox via Python SDK

Install the SDK on your **client** (laptop), not necessarily on the cluster node:

```bash
pip install k7-sdk==0.5.0
```

A freshly installed Ubuntu node does not include `python3-venv`. If you run the SDK on the node: `sudo apt install -y python3-venv python3-pip`, then `python3 -m venv ~/k7sdk && ~/k7sdk/bin/pip install k7-sdk==0.5.0`. `pip install --break-system-packages k7-sdk==0.5.0` also works on Ubuntu 24.04.

Use the synchronous client:

```python
from k7_sdk import Client
import time

# verify_ssl takes the CA bundle path on the default (cluster-CA) install;
# leave it at True for a Let's Encrypt (--api-hostname) cluster.
k7 = Client(endpoint="https://<node-ip>:31007", api_key="<your-key>", verify_ssl="./k7-ca.crt")

sb = k7.create({
    "name": "my-sandbox",
    "image": "alpine:latest"
})

# POST returns once objects exist; poll until Ready before exec.
deadline = time.time() + 120
while time.time() < deadline:
    for s in k7.list():
        if s["name"] == "my-sandbox" and s.get("ready") in (True, "True"):
            break
    else:
        time.sleep(2)
        continue
    break

result = sb.exec('echo "Hello World"')
print(result["stdout"])

print(k7.list())
sb.delete()
```

Async variant:

```python
import asyncio
from k7_sdk import AsyncClient

async def main():
    k7 = AsyncClient(endpoint="https://<node-ip>:31007", api_key="<your-key>", verify_ssl="./k7-ca.crt")
    print(await k7.list())
    await k7.aclose()

asyncio.run(main())
```

## Next steps

- Explore the [CLI guide](/k7/guides/cli)
- Explore the [Python SDK guide](/k7/guides/python-sdk)
- Run [Docker inside a sandbox](/k7/guides/docker)
- Integrate with the [REST API](/k7/api/introduction)
