How to install and enable metallb(load balancer) and Nginx ingress controller for v1.15.0

Sometimes, we need to publish/expose your service(for example, front-end service) outside of your cluster, then you need to consider how to expose your service on an external IP address. if you cluster is on some commercial Cloud provider platforms such as AWS/Azure/IBM Cloud/Ali Cloud etc, you need to read their instructions for how to expose your service outside of your cluster. But if your cluster is setup manually(setup on a baremetal nodes), then you need to consider how to install a load balancer and ingress controller for your cluster, in this blog, I will decribe how to install and enable MetalLB and Nginx controller, then you can expose your service on an external ip address.

in order to do this, you must have at least one worker node with external IP address, then you can use this IP address to expose your service, you also can expose your service with type NodePort on an IP address, but for a better infrastructure, I suggest you expose your service through ingress, this is the reason why we need a load balancer and ingress controller.

here is the steps to install MetalLB:

here to get the latest installation guide:
https://metallb.universe.tf/installation/

kubectl apply -f https://raw.githubusercontent.com/google/metallb/v0.7.3/manifests/metallb.yaml

create MetalLB configMap:

vi metallb-configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  namespace: metallb-system
  name: config
data:
  config: |
    address-pools:
    - name: default
      protocol: layer2
      addresses:
      - 9.X.XXX.233-9.X.XXX.239    #this is the ip adress pool

kubectl create -f metallb-configmap.yaml

**check pods** 
kubectl get pods -n metallb-system
NAME                          READY   STATUS    RESTARTS   AGE
controller-547d466688-nbt92   1/1     Running   0          5d23h
speaker-b5kzg                 1/1     Running   0          5d23h
speaker-ht8qn                 1/1     Running   0          5d23h
speaker-ss6wv                 1/1     Running   0          5d23h
speaker-zw8ff                 1/1     Running   0          5d23h
root@ppydalbik0102:~# 

Steps to install Ingress Nginx controller

Ingress is an entry to access services in your K8s cluster, it can provide load balancer, SSL termination and name-based virtual hosting. in order to create an ingress in K8s, you need to first install an ingress controller, there are many different ingress controllers provided by different companies, such as F5, HAProxy, Nginx etc, here I will show how to install a Nginx ingress controller:

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml

wget -k https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/baremetal/service-nodeport.yaml

vi service-nodeport.yaml

change service type from NodePort to LoadBalancer

How to install and enable metallb(load balancer) and Nginx ingress controller for v1.15.0_第1张图片

kubectl apply -f  service-nodeport.yaml

Then we can check if metallb allocate a external-ip to nginx-controller service ( we might need to wait for a few minutes for the external ip address)

root@ppydalbik0102:/etc/kubernetes# kubectl get service -n ingress-nginx
NAME            TYPE           CLUSTER-IP      EXTERNAL-IP     PORT(S)                      AGE
ingress-nginx   LoadBalancer   172.17.98.226   9.x.xxx.235   80:30737/TCP,443:30753/TCP   5d23h

now you have successfully install an ingress controller, then you can create ingress to access your service.

你可能感兴趣的:(Kubernetes)