Installing k3s and kubernetes in homelab and installing kubernetes dashboard.
March 17, 2023
kapilnakhwa
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 .
Installing k3s Server
Installing server in my nuc2 .
curl -sfL https://get.k3s.io | INSTALL_K3S_EXEC="--tls-san 100.96.196.59" 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 https://get.k3s.io | K3S_URL=https://100.96.196.59:6443 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.
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.
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
~/.kuber/config
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:
GITHUB_URL=https://github.com/kubernetes/dashboard/releases 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 https://raw.githubusercontent.com/kubernetes/dashboard/${VERSION_KUBE_DASHBOARD}/aio/deploy/recommended.yaml
created dashboard.admin-user.yml
apiVersion: v1 kind: ServiceAccount metadata: name: admin-user namespace: kubernetes-dashboard
created dashboard.admin-user-role.yml
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: admin-user roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cluster-admin subjects: - 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
http://localhost:8001/api/v1/namespaces/kubernetes-dashboard/services/https:kubernetes-dashboard:/proxy/
Then use the token previously generated to authenticate and enter into the kubernetes dashboard.