---
title: Interacting with Kubernetes from an extension
linkTitle: Interacting with Kubernetes
description: How to connect to a Kubernetes cluster from an extension
keywords: Docker, Extensions, sdk, Kubernetes
aliases:
- /desktop/extensions-sdk/dev/kubernetes/
- /desktop/extensions-sdk/guides/kubernetes/
---
The Extensions SDK does not provide any API methods to directly interact with the Docker Desktop managed Kubernetes cluster or any other created using other tools such as KinD. However, this page provides a way for you to use other SDK APIs to interact indirectly with a Kubernetes cluster from your extension.
To request an API that directly interacts with Docker Desktop-managed Kubernetes, you can upvote [this issue](https://github.com/docker/extensions-sdk/issues/181) in the Extensions SDK GitHub repository.
## Prerequisites
### Turn on Kubernetes
You can use the built-in Kubernetes in Docker Desktop to start a Kubernetes single-node cluster.
A `kubeconfig` file is used to configure access to Kubernetes when used in conjunction with the `kubectl` command-line tool, or other clients.
Docker Desktop conveniently provides the user with a local preconfigured `kubeconfig` file and `kubectl` command within the user’s home area. It is a convenient way to fast-tracking access for those looking to leverage Kubernetes from Docker Desktop.
## Ship the `kubectl` as part of the extension
If your extension needs to interact with Kubernetes clusters, it is recommended that you include the `kubectl` command line tool as part of your extension. By doing this, users who install your extension get `kubectl` installed on their host.
To find out how to ship the `kubectl` command line tool for multiple platforms as part of your Docker Extension image, see [Build multi-arch extensions](../extensions/multi-arch.md#adding-multi-arch-binaries).
## Examples
The following code snippets have been put together in the [Kubernetes Sample Extension](https://github.com/docker/extensions-sdk/tree/main/samples/kubernetes-sample-extension). It shows how to interact with a Kubernetes cluster by shipping the `kubectl` command-line tool.
### Check the Kubernetes API server is reachable
Once the `kubectl` command-line tool is added to the extension image in the `Dockerfile`, and defined in the `metadata.json`, the Extensions framework deploys `kubectl` to the users' host when the extension is installed.
You can use the JS API `ddClient.extension.host?.cli.exec` to issue `kubectl` commands to, for instance, check whether the Kubernetes API server is reachable given a specific context:
```typescript
const output = await ddClient.extension.host?.cli.exec("kubectl", [
"cluster-info",
"--request-timeout",
"2s",
"--context",
"docker-desktop",
]);
```
### List Kubernetes contexts
```typescript
const output = await ddClient.extension.host?.cli.exec("kubectl", [
"config",
"view",
"-o",
"jsonpath='{.contexts}'",
]);
```
### List Kubernetes namespaces
```typescript