Setting up Kubernetes Cluster in your home lab
Summary
Kubernetes is the future of automating deployment, scaling, and management of containerised applications which makes development of projects easier and portable. Additionally setting up such an environment within your local lab environment makes it easy to deploy and test out softwares at unprecedented pace.
You might have already setup Kubernetes in your laptop and must have used minikube to do so. But what if you want to setup it in your remote home lab? For instance i've got various DELL server (lab_server) running in my home lab and don't want my laptop to bear the pain of Kubernetes, but outsource the workloads to my lab_server while administering from laptop
Pre-Reqs
- Understanding of Kubernetes
- sudo permission on your home lab and connectivity from your laptop
- https://github.com/alexellis/k3sup
- Add lab_server to /etc/hosts file of your laptop
Steps
Steps in lab_server
- Create a dedicated user (eg: k3user) in lab_server with sudo permission
- Ensure k3user can sudo without password prompt by following below step
sudo su -
echo "k3user ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/k3user
chmod 0440 /etc/sudoers.d/k3user
exit
- Ensure management port (eg 6443) is opened in Iptables/firewall-d etc to your LAN
sudo su -
iptables -I INPUT -s 192.168.1.0/24 -p tcp --dport 6443 -j ACCEPT
iptables-save >/etc/iptables/rules.v4
exit
Steps in laptop
- Connect to the home_server using k3user and setup ssh-keys for automated access
# Generate key-pair if NOT done already
ssh-keygen -b 2048 -t rsa
# The above by default stores in your home location (~/.ssh/id_rsa)
# Copy the public key to lab_server and enter password one-time
ssh-copy-id -i ~/.ssh/id_rsa.pub k3user@lab_server
- Ensure you can connect and sudo without password prompt
# ssh to lab_server and ensure no password prompts
ssh k3user@lab_server
# now sudo to root without password prompt
sudo su -
- Now setup k3s from your laptop.
curl -sLS https://get.k3sup.dev | sh
sudo install k3sup /usr/local/bin/ #Sometimes not required in Mac
k3sup --help # Check All works
- Ensure you navigate to a relevant location as the kubeconfig file will be stored there by default and then run install
cd ~/mydev/
k3sup install --host lab_server --user k3user
# Note down the directory where kubeconfig is stored
- Check if you can connect to lab_server and get kubectl info
export KUBECONFIG=`pwd`/kubeconfig
kubectl get node
kubectl get pods -A
- All set to go now !!