Skip to content

Instantly share code, notes, and snippets.

@indrekj
Last active April 22, 2024 13:59
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save indrekj/8a8121b4964a56cdbb5f6f71d3319457 to your computer and use it in GitHub Desktop.
Save indrekj/8a8121b4964a56cdbb5f6f71d3319457 to your computer and use it in GitHub Desktop.
How to acccess TrueNAS kubectl remotely?

How to acccess TrueNAS kubectl remotely from your local computer?

DISCLAIMER: This is an unofficial guide. If you mess things up then you may lock yourself out of TrueNAS or even worse, make it unusable. There's also no guarantee that this works in the future.

Through SSH

Currently the easiest way to access kubectl is through ssh and k3s tool. If you have ssh access enabled then you can ssh to your TrueNAS server and use it using k3s kubectl get pods -A. This guide shows how to access kubectl without SSH-ing to the server.

From local kubectl (the actual guide)

  1. SSH to your TrueNAS scale instance: ssh root@TRUENAS-IP
  2. Copy the kubectl from: cat /etc/rancher/k3s/k3s.yaml
  3. Add the configuration to your ~/.kube/config
  4. In your local ~/.kube/config change:
  • server: use your TrueScale server IP
  • (optional) Instead of default use some identifier like homelab. This is only useful when you have multiple kubernetes clusters.
  1. In the TrueNAS server open port 6443:
  • iptables -I INPUT -p tcp -s YOUR-IP --dport 6443 -j ACCEPT -m comment --comment 'Allow kubectl access from remote computer' --wait
  • Replace YOUR-IP with your computer IP (e.g. 192.168.1.42).

That's it. Now if you do kubectl --context=homelab get pods -A you should see all running pods.

NOTE: TrueNAS resets the firewall settings after a restart. If you restart your server, then you need to re-run the steps 1 and 5.

NOTE: If you don't have kubectl installed then I'd recommend using asdf with asdf-kubectl plugin. At the time of the writing, the Kubernetes version used by TrueNas was 1.23.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment