Kubernetes for Developers: Minikube with Nodes and Load Balancer.
Today we install Minikube locally on Windows 10. We can get Kubernetes with one or more Nodes, L2 type Load Balancer with an access to your App from outside to share it.
Developers, DevOps and Cloud Engineers, IoT professionals use Kubernetes in Clouds like EKS, GKE, AKS, OKE, CCP etc. But quite often they need to have Kubernetes locally for development and experimentation, especially when there is enough RAM. There are plenty solutions like MicroK8s, K3S, KIND, k0s etc.
Install Minikube
Before start, you should install Oracle VM VirtualBox. Download and install VirtualBox-xxx-Win.exe, VirtualBox-6.1.30–148432-Win.exe is today.
You should use latest release of kubectl and helm.
Download and run installer https://minikube.sigs.k8s.io/docs/start/ , I use .exe to download. Today, that is minikube v1.24.0 and Kubernetes v1.22.3 on Docker 20.10.8
Open Windows terminal as administrator and start:
minikube start
By default, VM has 3000MB RAM and 2 CPU but you may change it from the first start:
minikube start --memory 8192 --cpus 2
You can change the Kubernetes version and resources:
minikube start --memory 16384 --cpus 4 –kubernetes-version=v1.20.2
To stop and delete:
minikube stop
minikube delete
If you have enough RAM, you might get multinode Kubernetes with Master and 2 Workers as a local cluster:
minikube start --nodes 3 -p node --memory 4096 --cpus 2
To stop and delete:
minikube stop -p node
minikube delete -p node
Install Load Balancer MetalLB in Layer 2 mode
Edit configmap:
kubectl edit configmap -n kube-system kube-proxy
Set strictARP: false -> strictARP: true
apiVersion: kubeproxy.config.k8s.io/v1alpha1
kind: KubeProxyConfiguration
mode: "ipvs"
ipvs:
strictARP: true
Install namespace and MetalLB into Kubernetes:
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.11.0/manifests/namespace.yamlkubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.11.0/manifests/metallb.yaml
Create secret on first install only:
kubectl create secret generic -n metallb-system memberlist -from-literal=secretkey=”$(openssl rand -base64 128)”
You should set minikube Network adapter 1 NAT to Bridged and choose your Ethernet Adapter using GUI VirtualBox on every virtual machine.
My laptop connected to a Router via Ethernet and has IP address from the pool 192.168.1.2–192.168.1.100 which dynamically distributed by DHCP server on the Router.
Bridged mode creates new interfaces and Router assigns new IP addresses by DHCP to all Nodes within the same pool.
MetalLB has another IP and it should be permanent.
I can use static IP adresses for the Load Balancer and set it in the config.yaml:
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.1.200–192.168.1.205
Create the configmap:
kubectl apply -n metallb-system -f config.yaml
Running Nginx
# One node
kubectl create deployment nginx -image nginx:alpine -port 80 -replicas=1
# or Three nodes
kubectl create deployment nginx -image nginx:alpine -port 80 -replicas=5
kubectl expose deployment nginx -name=nginx-svc -port=80 -type=LoadBalancerkubectl get svc nginx-svc
Test your App in browser http://192.168.1.200/
kubectl get pods -o wide
As you can see, nginx apps are running on Nodes node-m02 and node-m03, you can use Affinity. You have static IP and an access to your App in Kubernetes via Load Balancer. If your Router has real IP address or Dynamic DNS, you can translate an access from real world to your App in Kubernetes, most routers support port forwarding or even NAT inside.
References
https://www.virtualbox.org
https://kubernetes.io/docs/tasks/tools/install-kubectl-windows/
https://github.com/helm/helm/releases
https://minikube.sigs.k8s.io/docs/start/
https://minikube.sigs.k8s.io/docs/tutorials/multi_node/
https://metallb.universe.tf/installation/
https://metallb.universe.tf/configuration/#layer-2-configuration
https://kubernetes.io/docs/reference/kubectl/docker-cli-to-kubectl/
https://microk8s.io
https://k3s.io
https://kind.sigs.k8s.io
https://k0sproject.io