A concise guide for configuring a Dev Container with kubectl to manage a local or remote Kubernetes / K3s cluster directly from VS Code.
Note: This setup was created and tested on an ARM-based architecture (e.g., Apple Silicon / Raspberry Pi).
- Create a new project folder and open it in VS Code.
- Inside that folder, create a directory named
.devcontainer. - Within
.devcontainer, create a file calleddevcontainer.json.
Copy the following content into your devcontainer.json file:
{
"name": "K3s Dev",
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"postCreateCommand": "curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl && curl -LO https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/arm64/kubectl.sha256 && sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl && mkdir -p ~/.kube && touch ~/.kube/config && chmod 600 ~/.kube/config"
}Before running, make sure you have the Dev Containers extension from Microsoft installed.
Click the blue >< icon in the bottom-left corner of VS Code,
then select “Reopen in Dev Container”.
This will build and open your project inside a ready-to-use container environment.
On your control-plane node, run the following command to display your cluster configuration:
sudo cat /etc/rancher/k3s/k3s.yaml
The output should look like this:

parts of my cluster are covered for security purposes. you should not share it with other people.
Copy the entire output and save it temporarily to a text file.
Inside the Dev Container, open the config file:
nano ~/.kube/configPaste the content you copied earlier into this file.
Locate the line that looks like this:
server: https://127.0.0.1:6443
Replace the IP address with the actual IP of your control-plane node.
You can find it using:
ifconfigRun the following command to confirm that kubectl is connected to your cluster:
kubectl get nodesIf you see your cluster nodes listed — everything is configured correctly.
