You've set up a k3s Kubernetes cluster on your Raspberry Pi and deployed an application. While managing it remotely with kubectl from your main computer is great, sometimes you need to quickly check pod status or logs directly on the Pi itself.
You might notice that just typing kubectl get pods on the Pi gives you a connection error. That's because the standard kubectl command doesn't automatically know where to find the k3s cluster configuration or have the right permissions.
Luckily, k3s provides a handy wrapper command! Here's how to use it:
Steps
-
SSH into your Raspberry Pi:
Connect to your Pi using its hostname or IP address.
ssh <your_pi_user>@<your_pi_hostname_or_ip> # Example: ssh pi-admin@k3s-node.local -
Run the
k3s kubectlCommand:
Prefix your usualkubectlcommands withsudo k3s kubectl. This special command automatically uses the correct admin configuration (/etc/rancher/k3s/k3s.yaml) and runs with the necessary permissions.To check your running pods:
# On the Pi sudo k3s kubectl get pods -A # -A shows pods in all namespacesOr, if you know the namespace (e.g.,
default):
# On the Pi sudo k3s kubectl get pods -n default -
Check Pod Logs (Optional but useful):
First, get the full name of the pod you're interested in from theget podscommand above (it will look something likemy-app-deployment-xxxxxxxxxx-xxxxx). Then, view its logs:
# On the Pi - Replace <your-pod-name> and <namespace> sudo k3s kubectl logs -f <your-pod-name> -n <namespace> # Example: sudo k3s kubectl logs -f my-app-deployment-7f8c9d4b4f-g2hjl -n defaultThe
-fflag follows the logs in real-time, showing you the latest output from your application's container directly in the Pi's terminal.
That's all there is to it! Using sudo k3s kubectl is the straightforward way to interact with your k3s cluster directly on the node it's running on.
Top comments (0)