After we have installed the MetalLB load balancer (click here for the blog post abour MetalLB), the next step is to install an Ingress controller.
What is in Ingress controller ? The kubernetes definition is
In Kubernetes, an Ingress is an object that allows access to your Kubernetes services from outside the Kubernetes cluster. You configure access by creating a collection of rules that define which inbound connections reach which services. This lets you consolidate your routing rules into a single resource.
Since a kubernetes server can host multiple application/web servers, the ingress controller will (in simple terms) point you to the correct service where the website/application is hosted
I first tried installing the Traefik ingress, but I just couldn''t get it to work properly in combination with the MetalLB load balancer. I guess I have overlooked a minor configuration detail in Traefik, but when I switched to the NGINX-ingress controller, I had it up and running pretty quickly..
The procedure below descibers the installation of the NGINX ingress conteller
- Install NGINX - Ingress Controller
# Create the namespace for ingress-nginx
kubectl create namespace ingress-nginx
# Add nginx repository to helm
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
# Install nginx ingress controller
helm install ingress-nginx ingress-nginx/ingress-nginx --version="4.0.17" \
--set rbac.create=true \
--set controller.kind=DaemonSet \
--set controller.service.type=LoadBalancer \
--set controller.service.externalTrafficPolicy=Local \
--set controller.publishService.enabled=true \
--set defaultBackend.enabled=true \
--set defaultBackend.image.repository="k8s.gcr.io/defaultbackend-arm64" \
--set enable-prometheus-metrics=true \
--namespace ingress-nginx
kubectl get service -n ingress-nginx
- Create a DNS record on your internal network. If you want expose it to the Internet you need to create also a public DNS record).
- Create a service for webapp. This is required to expose the app (pod) within the kubernetes cluster
- Create a ingress rule to expose the app (pod) outside the cluster
nano deploy-nginx-1-k8s.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-1
labels:
app: nginx-1
spec:
replicas: 1
selector:
matchLabels:
app: nginx-1
template:
metadata:
labels:
app: nginx-1
spec:
containers:
- image: nginx
name: nginx-1
---
kind: Service
apiVersion: v1
metadata:
name: nginx-1-service
spec:
selector:
app: nginx-1
ports:
- protocol: TCP
port: 80
---
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: nginx-01
annotations:
kubernetes.io/ingress.class: "nginx"
spec:
rules:
- host: nginx-1.mydomain.com
http:
paths:
- path: /
backend:
serviceName: nginx-1-service
servicePort: 80
- Create an app/pod called nginx-1, which is a web server
- It will create a service to open port with the kubernetes cluster
- It will create an ingress entry called nginx-1.mydomain.com (mydomain.com should changed to your own domain name)
kubectl apply -f deploy-nginx-1-k8s.yml
kubectl get ingress
PS C:\Users\erik> kubectl get ingress
NAME CLASS HOSTS ADDRESS PORTS AGE
nginx-1 <none> nginx-1.mydomain.com 192.168.1.65 80 17h
helm repo add is not working for that url
ReplyDeleteLooks like the chart repository has been changed. I haven't tested it yet, but
Deletehelm repo add center https://repo.chartcenter.io
should be changed to:
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
I have updated the script with the new helm repository. It should be working again.
Deletenice. thanks bud
ReplyDeleteWhen I try to access my url for nginx-1 it comes up with a username/password prompt... any idea how to stop this?
ReplyDeleteAre you opening your site with http:// of https:// ? It should with http:// .
DeleteI'm using http://
DeleteStrange I haven't had this issue. I will see if I can try to reproduce it somewhere next week.
Delete