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

# Connect with kubectl

> Use kubectl on a hosted Cluster with your Akua sign-in, without a stored credential

A hosted Cluster's Kubernetes API accepts your Akua identity. `akua clusters get-credentials` adds the Cluster to your kubeconfig. When kubectl needs a credential, it runs the Akua CLI, which gets a token that is valid for 15 minutes and for this Cluster only. No credential is written to your kubeconfig.

Kubernetes asks Akua about your access whenever it sees a token it has not checked in the last 10 seconds. When an owner removes your role, you lose access to the Cluster within about a minute.

## Prerequisites

* The [Akua CLI](https://docs.akua.dev/cli.md), signed in with `akua auth login`.
* `kubectl`.
* The **Owner** or **Admin** role in the Cluster's Workspace. Both include the `cluster.clusters.get-credentials` permission, which makes you a `cluster-admin` in the Cluster.
* A hosted Cluster whose control plane is ready (see [Create a cluster](https://docs.akua.dev/clusters/create.md)).

## Connect

**1. Add the Cluster to your kubeconfig**

```bash theme={null}
akua clusters get-credentials CLUSTER_ID --workspace WORKSPACE
```

The command adds a context named `akua_WORKSPACE_ID_CLUSTER_NAME` to the first file in `KUBECONFIG`, or to `~/.kube/config`, and switches kubectl to it. Your other contexts stay as they are. To run it again later, for example after you move the CLI, use the same command: it replaces the entry.

**2. Use kubectl**

```bash theme={null}
kubectl get nodes
kubectl auth whoami
```

`kubectl auth whoami` shows your user, `akua:user:` followed by your user ID, in the group `akua:cluster-admins`.

## How access works

| | |
| - | - |
| Who can connect | People with `cluster.clusters.get-credentials` in the Cluster's Workspace: the Owner and Admin roles. |
| What they can do | `cluster-admin`, through the ClusterRoleBinding `akua:cluster-admins` in the Cluster. |
| How long a token lasts | 15 minutes. kubectl gets a new one when it needs one. Access is checked again on every request Kubernetes has not seen in the last 10 seconds. |
| Revoking access | Remove the person's role in the Workspace; access ends within about a minute. Signing out or revoking the API token you used stops new tokens, but a token already issued works until it expires. Commands already running, such as `kubectl logs -f`, keep their connection until they end. |

## Attached clusters

Akua does not run an attached cluster's API server, so `get-credentials` does not apply. Use the kubeconfig you attached the cluster with (see [Attach a cluster](https://docs.akua.dev/clusters/import.md)).


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