Using kubectl with k3s

kubectl is your main tool for creating, inspecting, and troubleshooting workloads on k3s.

Syntaxkubectl <verb> <resource> [name] [flags]

kubectl is the standard Kubernetes command-line tool, and it works exactly the same on k3s. The install script even sets up a symlink so you can call it directly.

Everyday commands

  • kubectl get — list resources.
  • kubectl describe — detailed info and events for one resource.
  • kubectl apply -f — create or update from a YAML file.
  • kubectl logs — read a Pod's output.
  • kubectl exec — run a command inside a container.

Example

Example · bash
# Explore the cluster
kubectl get nodes
kubectl get pods -A
kubectl describe node server-1

# Read logs and get a shell in a Pod
kubectl logs deploy/web
kubectl exec -it deploy/web -- sh

When to use it

  • A developer uses kubectl to exec into a running pod on k3s and inspect environment variables to debug a misconfigured secret mount.
  • An SRE watches rolling deployment progress on k3s using kubectl rollout status to ensure zero-downtime during an upgrade.
  • A DevOps engineer uses kubectl top nodes to identify which k3s worker is under memory pressure before scheduling new pods.

More examples

Basic resource inspection

Lists all pods across namespaces, shows node details, and describes a specific pod for event and status information.

Example · bash
kubectl get pods -A
kubectl get nodes -o wide
kubectl describe pod <pod-name> -n default

Exec into a running pod

Opens an interactive shell inside a running pod to inspect environment variables and test internal service connectivity.

Example · bash
kubectl exec -it deploy/my-app -- /bin/sh
# Inside the pod:
env | grep APP_
curl http://backend-svc:5000/health

Watch a rolling deployment

Triggers an image update and monitors the rollout progress, then lists the deployment's revision history.

Example · bash
kubectl set image deployment/my-app app=myrepo/my-app:v2
kubectl rollout status deployment/my-app
kubectl rollout history deployment/my-app

Discussion

  • Be the first to comment on this lesson.