When we are deploying the Kubernetes in the local development environment and if we need to publish the services through load balancer services then Metallb load balancer is one of the easiest solutions we can use. All we need is a set of IP range from our network which metal lb can use.
Following are the k8s configurations that need to be applied on the cluster.
Below is the config map which mentions the IPs which can be used for the load balancers.
apiVersion: v1
kind: ConfigMap
metadata:
namespace: metallb-system
name: config
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 172.16.2.80-172.16.2.90
Below is the ansible-playbook I used to deploy the metal load balancer on the k8s cluster.
- Initialize the master with Metallb Clusters
- Copy the metallb Configuration to master
- Kube apply the configuration on master.
- hosts: master
remote_user: ansible
become: yes
become_method: sudo
become_user: root
gather_facts: yes
connection: ssh
tasks:
- name: Initializing Metallb cluster
shell: kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.8.3/manifests/metallb.yaml
register: myshell_output
- name: Copying the Metallb config file
copy:
src: /Users/rahulraj/workspace/vmware-ansible/k8s/playbook/metallb-congif.yml
dest: $HOME/metallb-congif.yml
- name: Configuring Metallb cluster
shell: kubectl apply -f $HOME/metallb-congif.yml
register: myshell_output
For testing it we shall deploy a sample Nginx and expose it through load balancer type services.
k create deployment nginx-deployments --image=nginx --replicas=3 --port=80
k expose deployment nginx-deployments --port=80 --target-port=80 --type=LoadBalancer
Output should be like following
kubectl get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 25h
nginx-deployments LoadBalancer 10.100.137.154 172.16.2.80 80:30973/TCP 13h
No comments:
Post a Comment