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

# nsc kubeconfig write

Generate a kubeconfig to connect to a instance.

`kubeconfig write` generates a kubeconfig that allows connecting `kubectl` to an instance.
The config is written to a temporary file. When running `kubectl`, the created kubeconfig
[can be selected](https://kubernetes.io/docs/concepts/configuration/organize-cluster-access-kubeconfig/)
by setting the `KUBECONFIG` environment variable or by setting the `--kubeconfig` flag.

To skip writing the config and run a configured kubectl directly, see [`nsc kubectl`](/docs/reference/cli/kubectl)

## Usage

```bash theme={null}
nsc kubeconfig write [instance-id]
```

### Example

The following example shows how to generate a kubeconfig and use it to deploy an application into an instance:

<Steps titleSize="h4">
  <Step title="Create an ephemeral instance">
    Create an ephemeral instance and note its ID:

    ```bash theme={null}
    nsc create
    ```

    ```text nocopy Output theme={null}
    Created instance "1lf2ol9ioulce"
     deadline: 2023-04-25T13:24:53Z
    ```
  </Step>

  <Step title="Generate a kubeconfig">
    Generate a kubeconfig for the instance:

    ```bash theme={null}
    nsc kubeconfig write 1lf2ol9ioulce
    ```

    ```text nocopy Output theme={null}
    Wrote Kubeconfig for instance 1lf2ol9ioulce to ~/.cache/ns/tmp/kubeconfig/2342545987.yaml.

    Start using it by setting:
      export KUBECONFIG=~/.cache/ns/tmp/kubeconfig/2342545987.yaml
    ```
  </Step>

  <Step title="Deploy an application">
    Set the generated kubeconfig and deploy the example application:

    ```bash theme={null}
    export KUBECONFIG=~/.cache/ns/tmp/kubeconfig/2342545987.yaml
    kubectl apply -f https://k8s.io/examples/application/nginx-app.yaml
    ```

    ```text nocopy Output theme={null}
    service/my-nginx-svc created
    deployment.apps/my-nginx created
    ```
  </Step>
</Steps>

## Options

<h3 id="--output_to-path">
  \--output\_to \<path>
</h3>

Write the *config path* to file. If file already exists, it will get overwritten.
