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

在这里插入图片描述

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.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值