Installing k3s and kubernetes in homelab and installing kubernetes dashboard.

March 17, 2023
In my local vpn , I chose my nuc2 as a kubernetes server, At this stage since this is just an experimental learning , I didn't care about H.A(High availability) architecture. Hence, I just needed one server and one agent.  In k3s , usually for faul tolerant systems there should be atleast 3 nodes however, it is not my requirement at the moment.

Installing k3s Server
Installing server in my nuc2 .
curl -sfL | INSTALL_K3S_EXEC="--tls-san" sh -

The IP mentioned above is the IP address in my LAN for the nuc2 device.

It should install bunch of tools including kubectl. check by using.
sudo kubectl get nodes

You should get list of a single node and control pane in return.

Adding agent:
Moving on to add an agent.  I chose my old nakhwahp . 

I needed a token to connect to the server.
sudo cat /var/lib/rancher/k3s/server/node-token

SSH into the nakhwahp and executed.
curl -sfL | K3S_URL= K3S_TOKEN=K106aa3ec92104786946bc7f63ff1a73b738b551ffeef0efe5ac6fc4162fabfb44a::server:6c01247f7d51fec0d43afb1ab3e97dae sh -
The value of K3S_TOKEN is the content of /var/lib/rancher/k3s/server/node-token

log back into the server and check if the worker node is added.
sudo kubectl get nodes. 
You should see the new agent node there.

Installing kubectl in osx for daily use:
Now i didn't wanted to log into my homelab systems every time i needed to do something in this cluster. Hence, I needed my daily macbook pro to be able to connect to this cluster and operate. For this needed kubectl in my osx. 
brew install kubectl

From Nuc2 i.e kubernetest server that I had , 
sudo cat /etc/rancher/k3s/k3s.yaml 

I copied the content in my macbook pro locally at 

I could now test in my macbook with 
kubetctl get nodes

This avoided me having to rely on ssh'ing into the macbook pro first.

Deploying kubernetes dashboard 
Logged into my nuc2:
VERSION_KUBE_DASHBOARD=$(curl -w '%{url_effective}' -I -L -s -S ${GITHUB_URL}/latest -o /dev/null | sed -e 's|.*/||')
sudo k3s kubectl create -f${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml

created dashboard.admin-user.yml
apiVersion: v1
kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard
created dashboard.admin-user-role.yml
kind: ClusterRoleBinding
  name: admin-user
  kind: ClusterRole
  name: cluster-admin
- kind: ServiceAccount
  name: admin-user
  namespace: kubernetes-dashboard

let's create this into our cluster.
sudo k3s kubectl create -f dashboard.admin-user.yml -f dashboard.admin-user-role.yml

Now we need to authenticate into this dashboard via token . To generate this token
sudo k3s kubectl -n kubernetes-dashboard create token admin-user

From my macbook pro:
It seems that i needed to create a proxy to be able to connect to my kubernetes cluster from my macbook pro. 
kubectl proxy

Then we could just go to 

Then use the token previously generated to authenticate and enter into the kubernetes dashboard.