> ## Documentation Index
> Fetch the complete documentation index at: https://inframan.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Access the cluster with kubectl

> Open a tunnel to an infrastructure's Kubernetes API with the Inframan CLI, then use kubectl, Helm, k9s or Lens as usual.

You rarely need direct cluster access, because Inframan deploys, scales and heals for you. When you do want to look inside, `inframan tunnel` connects your machine to the infrastructure's Kubernetes API through Inframan. kubectl, Helm, k9s and Lens then work as usual.

The tunnel carries raw TCP, so kubectl's own TLS connection runs end to end to the cluster and is checked against the cluster's certificate authority. kubectl gets a short-lived token from the CLI each time it needs one, and that token is never written into your kubeconfig.

## Before you begin

* The **Admin** role on the instance. A tunnel has full administrator rights on the cluster, so only admins can open one.
* The Inframan CLI.

```bash macOS and Linux theme={null}
curl -fsSL https://inframan.cloud/install.sh | sh
```

```powershell Windows theme={null}
irm https://inframan.cloud/install.ps1 | iex
```

## Open a tunnel

**1. Sign in**

Sign in with the console address you use in your browser:

```bash theme={null}
inframan login --url https://central1.inframan.cloud
```

A browser window opens for you to sign in. On a machine without a browser, the CLI prints a link and asks you to paste back a code.

If your instance's console runs in your own Google Cloud project, run `inframan login` without `--url`.

**2. Choose the instance**

If you have access to more than one instance, pick one:

```bash theme={null}
inframan instance list
inframan instance use <instance-id>
```

**3. Start the tunnel**

Pass the infrastructure's name or ID. If the instance has only one infrastructure, you can leave it out.

```bash theme={null}
inframan tunnel my-staging-infra
```

The CLI adds a context named `inframan-<infrastructure-name>` to your kubeconfig and makes it the current context. Leave the command running.

**4. Use kubectl**

In another terminal:

```bash theme={null}
kubectl get nodes
kubectl get pods -n <application-namespace>
```

**5. Close the tunnel**

Press **Ctrl+C** in the tunnel's terminal. The CLI removes the context it added.

## Options

| Flag | Default | Description |
| - | - | - |
| `--port` | Chosen automatically | The local port the tunnel listens on |
| `--kubeconfig` | `~/.kube/config` | The kubeconfig file to add the context to |

> [!WARNING]
>
> Changes you make with kubectl aren't recorded in your `inframan.yaml`. Inframan treats a hand-made change to anything it manages as drift and puts it back on the next deploy or reconcile. Change your configuration in `inframan.yaml` instead.

The tunnel works for infrastructures on both Google Cloud and AWS.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.