# `port-forward`

`kix port-forward` builds the cluster, finds the named package's primary
workload, and replaces itself with `kubectl port-forward` against that
workload. `kubectl` picks the pod and picks a new one when the pod is
replaced. `kix pf` is a shorter alias for the same command.

This page is hand-maintained. Check `cli/kix-cli/src/cli.rs`,
`cli/kix-cli/src/commands/port_forward.rs`, and `cli/kix-cli/src/commands/workload.rs`
when in doubt.

## Synopsis

```text
kix port-forward <CLUSTER> <PACKAGE> <PORT>... [--address <ADDRESS>]
                 [--context <CONTEXT>] [--flake <FLAKE>]
```

| Argument or flag | Meaning |
| --- | --- |
| `<CLUSTER>` | Cluster name to build from the flake. |
| `<PACKAGE>` | Package instance name, or `<namespace>/<name>` when the name is not unique. |
| `<PORT>...` | One or more port specs, passed to `kubectl port-forward` unchanged. `8080:80` binds local port 8080, `5432` uses the same port on both sides, and `:80` lets kubectl choose a free local port. At least one is required. |
| `--address <ADDRESS>` | Local addresses to listen on (`kubectl port-forward --address`). kubectl's default is `localhost`. |
| `--context <CONTEXT>` | Kubeconfig context, passed through to `kubectl`. |

The primary workload is chosen as for [`kix logs`](/docs/reference/cli/logs/#workload-selection):
the first Deployment, then StatefulSet, then DaemonSet in the package. `-q`
suppresses the line naming the target.

## Examples

<Command commands={[
  "kix port-forward demo web 8080:80",
  "kix port-forward demo postgres 5432 --address 0.0.0.0",
  "kix pf demo web 8080:80",
]} />

## Exit status

On success `kix port-forward` is replaced by `kubectl`, so the exit status is kubectl's.
A build or package-resolution failure exits `1`.

:::tip[Use it in a task]
See [Use `kix port-forward`](/docs/how-to/operate-a-cluster/use-kix-port-forward/)
for the day-to-day workflow.
:::