<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/building-a-lightweight-kubernetes-environment-on-k3s-and-the-kubectl-command-on-wsl2-windows-11-exmiiimmx" -->

---
title: Building a Lightweight Kubernetes Environment on K3s and...
description: This tutorial walks through setting up a lightweight Kubernetes environment using K3s on a Google Cloud VM, then connecting to it with kubectl from WSL2 on...
canonical: https://daily.dev/posts/building-a-lightweight-kubernetes-environment-on-k3s-and-the-kubectl-command-on-wsl2-windows-11-exmiiimmx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Building a Lightweight Kubernetes Environment on K3s and the kubectl command on WSL2 Windows 11 | daily.dev
og:description: This tutorial walks through setting up a lightweight Kubernetes environment using K3s on a Google Cloud VM, then connecting to it with kubectl from WSL2 on...
og:url: https://daily.dev/posts/building-a-lightweight-kubernetes-environment-on-k3s-and-the-kubectl-command-on-wsl2-windows-11-exmiiimmx
og:image: https://api.daily.dev/og/posts/exMIIimmX.png
og:image:alt: Building a Lightweight Kubernetes Environment on K3s and the kubectl command on WSL2 Windows 11
og:image:width: 1200
og:image:height: 630
og:locale: en
---

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

# Building a Lightweight Kubernetes Environment on K3s and the kubectl command on WSL2 Windows 11

**[ITNEXT](https://daily.dev/sources/itnext)** · 10 min read · 22 upvotes · 0 comments

## Summary

This tutorial walks through setting up a lightweight Kubernetes environment using K3s on a Google Cloud VM, then connecting to it with kubectl from WSL2 on Windows 11. It installs K3s with a script using the --tls-san flag to add the VM's external IP to the TLS certificate. The k3s.yaml config is copied via scp to ~/.kube/config on WSL2, with the server address changed from 127.0.0.1 to the VM's public IP. It verifies connectivity with curl against port 6443 and confirms the cluster with 'kubectl get nodes', showing K3s version v1.35.5+k3s1 in the author's output. The content is an excerpt from the 563-page book 'Kubernetes and Helm: A Primer'.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://itnext.io/building-a-lightweight-kubernetes-environment-on-k3s-and-the-kubectl-command-on-wsl2-windows-11-e2b2ca3af082>

## Questions this post answers

### How do I connect kubectl running on WSL2 to a K3s cluster hosted on a Google Cloud VM?

Copy the k3s.yaml file from the K3s server to ~/.kube/config on WSL2 using scp, then edit the server address in that file from 127.0.0.1 to the VM's external IPv4 address with a command like 'sed -i s/127.0.0.1/s.s.s.s/ ~/.kube/config'. Also pass --tls-san with that external IP during K3s installation so the certificate is valid for it.

_Developers wiring up local kubectl to a remote K3s cluster can find more setup walkthroughs on daily.dev._

### Why do I need the --tls-san flag when installing K3s on a cloud VM?

The --tls-san flag adds the VM's external IPv4 address to the TLS certificate's Subject Alternative Names, which is needed because cloud VMs like those on Google Cloud assign an internal IP to the local network interface that differs from the public-facing external IP used by remote clients connecting to the K3s API server on port 6443.

_Anyone exposing a K3s API server externally can track networking gotchas like this on daily.dev._

### How do I verify that a K3s API server is reachable before configuring kubectl against it?

Send a curl request to the server's port 6443, for example 'curl -k https://s.s.s.s:6443/'. Getting back a JSON response with '"message": "Unauthorized"' and code 401 is expected and confirms network connectivity to the K3s API server is working, since you haven't yet supplied credentials.

_Developers debugging cluster connectivity issues can keep up with practical Kubernetes tips on daily.dev._

## Similar posts on daily.dev

- [K3s: A Better Way to Deploy a Docker App to a Linux Server](https://daily.dev/posts/k3s-a-better-way-to-deploy-a-docker-app-to-a-linux-server-p8llrvwh7) · Atomic Spin · 16 upvotes · 1 comments
- [Kubernetes Tutorial Part 1: Multi-Node Cluster on a Mac](https://daily.dev/posts/kubernetes-tutorial-part-1-multi-node-cluster-on-a-mac-0pha44itq) · Medium · 0 upvotes · 0 comments
- [A 'small' vanilla Kubernetes install on NixOS](https://daily.dev/posts/a-small-vanilla-kubernetes-install-on-nixos-utc94vkd0) · Lobsters · 1 upvotes · 0 comments
- [K3s vs. K8s: When lightweight Kubernetes distros win \(and when they don’t\)](https://daily.dev/posts/k3s-vs-k8s-when-lightweight-kubernetes-distros-win-and-when-they-don-t--wlhfa9kos) · The New Stack · 1 upvotes · 0 comments
- [A Beginner's Guide to Kubernetes](https://daily.dev/posts/a-beginner-s-guide-to-kubernetes-ucyxczyo1) · MetalBear · 0 upvotes · 0 comments

---

Tags: [#microsoft](https://daily.dev/tags/microsoft), [#kubernetes](https://daily.dev/tags/kubernetes), [#gcp](https://daily.dev/tags/gcp)

[View this post on daily.dev](https://daily.dev/posts/building-a-lightweight-kubernetes-environment-on-k3s-and-the-kubectl-command-on-wsl2-windows-11-exmiiimmx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Building a Lightweight Kubernetes Environment on K3s and the kubectl command on WSL2 Windows 11","url":"https://daily.dev/posts/building-a-lightweight-kubernetes-environment-on-k3s-and-the-kubectl-command-on-wsl2-windows-11-exmiiimmx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/building-a-lightweight-kubernetes-environment-on-k3s-and-the-kubectl-command-on-wsl2-windows-11-exmiiimmx"},"datePublished":"2026-11-14T09:09:04.809Z","dateModified":"2026-11-14T09:20:01.860Z","description":"This tutorial walks through setting up a lightweight Kubernetes environment using K3s on a Google Cloud VM, then connecting to it with kubectl from WSL2 on...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/802c4dc9bee97f37648f16c864deeeb9?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/802c4dc9bee97f37648f16c864deeeb9?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"ITNEXT","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"ITNEXT","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1/logos/itnext2","url":"https://daily.dev/sources/itnext"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/building-a-lightweight-kubernetes-environment-on-k3s-and-the-kubectl-command-on-wsl2-windows-11-exmiiimmx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":22},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"microsoft,kubernetes,gcp","timeRequired":"PT10M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"ITNEXT","item":"https://daily.dev/sources/itnext"},{"@type":"ListItem","position":3,"name":"Building a Lightweight Kubernetes Environment on K3s and the kubectl command on WSL2 Windows 11"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/building-a-lightweight-kubernetes-environment-on-k3s-and-the-kubectl-command-on-wsl2-windows-11-exmiiimmx#faq","mainEntity":[{"@type":"Question","name":"How do I connect kubectl running on WSL2 to a K3s cluster hosted on a Google Cloud VM?","acceptedAnswer":{"@type":"Answer","text":"Copy the k3s.yaml file from the K3s server to ~/.kube/config on WSL2 using scp, then edit the server address in that file from 127.0.0.1 to the VM's external IPv4 address with a command like 'sed -i s/127.0.0.1/s.s.s.s/ ~/.kube/config'. Also pass --tls-san with that external IP during K3s installation so the certificate is valid for it. Developers wiring up local kubectl to a remote K3s cluster can find more setup walkthroughs on daily.dev."}},{"@type":"Question","name":"Why do I need the --tls-san flag when installing K3s on a cloud VM?","acceptedAnswer":{"@type":"Answer","text":"The --tls-san flag adds the VM's external IPv4 address to the TLS certificate's Subject Alternative Names, which is needed because cloud VMs like those on Google Cloud assign an internal IP to the local network interface that differs from the public-facing external IP used by remote clients connecting to the K3s API server on port 6443. Anyone exposing a K3s API server externally can track networking gotchas like this on daily.dev."}},{"@type":"Question","name":"How do I verify that a K3s API server is reachable before configuring kubectl against it?","acceptedAnswer":{"@type":"Answer","text":"Send a curl request to the server's port 6443, for example 'curl -k https://s.s.s.s:6443/'. Getting back a JSON response with '\"message\": \"Unauthorized\"' and code 401 is expected and confirms network connectivity to the K3s API server is working, since you haven't yet supplied credentials. Developers debugging cluster connectivity issues can keep up with practical Kubernetes tips on daily.dev."}}]}
```

