My previous post the Kubernetes installation ended with a nodeport configuration as a final step to access a pod (container) from outside the kubernetes network.
In Kubernetes there are several different port configurations for Kubernetes services:
- Port exposes the Kubernetes service on the specified port within the cluster. Other pods within the cluster can communicate with this server on the specified port.
- TargetPort is the port on which the service will send requests to, that your pod will be listening on. Your application in the container will need to be listening on this port also.
- NodePort exposes a service externally to the cluster by means of the target nodes IP address and the NodePort. NodePort is the default setting if the port field is not specified.
Kubernetes installations at cloud providers like AWS, Azure Linode have all a loadbalancer included in their Kubernetes service., Users can access the website (hosted by multiple pod)s from one single IP, which is of course balanced, and your Rasberry Pi Kubernetes doesn't have that option.
There is however a great solution to have loadbalancing funtionality available with your newly build Rasberry Pi Kubernetes cluster, and that is the bare metal load balancer from MetalLB.
The link to their website is https://metallb.universe.tf .
MetalLB supports the use of the flanel network addon we have installed during the installation procedure of installing Kubernetes on a Rasberry Pi Cluster.
What you see in the post below are the excerpts form the installation procedure, which I have used to configure the MetalLB load balancer on my Pi Kubernetes cluster.
I have used the installation by manifest option. To start: type the following commands on the master node via an SSH session to the K8s-master :
kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/namespace.yaml kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.12.1/manifests/metallb.yaml # On first install only kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)"
- The components in the manifest are: The metallb-system/controller deployment. This is the cluster-wide controller that handles IP address assignments.
- The metallb-system/speaker daemonset. This is the component that speaks the protocol(s) of your choice to make the services reachable.
- Service accounts for the controller and speaker, along with the RBAC permissions that the components need to function.
apiVersion: v1 kind: ConfigMap metadata: namespace: metallb-system name: config data: config: | address-pools: - name: default protocol: layer2 addresses: - 192.168.1.65-192.168.1.127 # < example ip range you reserve for MetalLB
- copy & past the text for the yaml file with your own address values
- press Ctrl-V to past
- press Ctrl-O to save
- press Ctrl-X to exit
kubectl create -f metallb-config.yml
kubectl get configmap -n metallb-system
kubectl kubectl expose deployment nginx-1 --port 80 --type=LoadBalancer --name=nginx-1
kubectl get service