It’s time to move on to a better strategy, which is ingress controller, and as an added bonus we will see how to add SSL certificate to have a secure domain. We have already seen how to setup nginx reverse proxy for aspnet core apps with and without Docker compose and How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service.
This article is a part of a series:
- Part 1 : How to setup nginx reverse proxy for aspnet core apps with and without Docker compose
- Part 2 :How to setup nginx reverse proxy && load balancer for aspnet core apps with Docker and azure kubernetes service
- Part 3 : How to configure an ingress controller using TLS/SSL for the Azure Kubernetes Service (AKS)
- Part 4 : switch to Azure Container Registry from Docker Hub
- Part 5: Using Azure DevOps, Automate Your CI/CD Pipeline and Your Deployments
- Part 6 : Using Github, Automate Your CI/CD Pipeline and Your Deployments
- Part 7 : Possible methods to reduce your costs
Introduction
We created a nginx reverse proxy in a previous article; this time, we’ll employ an ingress controller.
For Kubernetes services, an ingress controller is a piece of software that offers reverse proxy, programmable traffic routing, and TLS termination. Individual Kubernetes services’ ingress rules and routes are configured using Kubernetes ingress resources. A single IP address can be used to route traffic to numerous services in a Kubernetes cluster when ingress rules and an ingress controller are utilized.
In this demonstration, we’ll show you how to switch between four applications as services by using the ingress controller.
Later, we’ll look at adding an SSL certificate and switching (redirect ) from HTTP to HTTPS.
Part 1 : Create deployments in AKS
Using the docker hub, we will begin by defining the applications we will use in this context.
01-backend-deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: backend-restapp
namespace: ingress
labels:
app: backend-restapp
tier: backend
spec:
replicas: 2
selector:
matchLabels:
app: backend-restapp
template:
metadata:
labels:
app: backend-restapp
tier: backend
spec:
containers:
- name: backend-restapp
image: ben2code/backend:latest
ports:
- containerPort: 5000
---
apiVersion: v1
kind: Service
metadata:
name: my-backend-service ## VERY VERY IMPORTANT
labels:
app: backend-restapp
tier: backend
spec:
selector:
app: backend-restapp
ports:
- name: http
port: 5000 # ClusterIP Service Port
targetPort: 5000 # Container Port
type: ClusterIP
01-nginx-frontend.yml
apiVersion: apps/v1
kind: Deployment
metadata:
name: 01-nginx-frontend
namespace: ingress
labels:
app: 01-nginx-frontend
tier: frontend
spec:
replicas: 1
selector:
matchLabels:
app: 01-nginx-frontend
template:
metadata:
labels:
app: 01-nginx-frontend
tier: frontend
spec:
containers:
- name: 01-nginx-frontend
image: ben2code/my_build:v3-release
ports:
- containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
name: my-nginx-service-01 ## VERY VERY IMPORTANT
labels:
app: 01-nginx-frontend
tier: frontend
spec:
selector:
app: 01-nginx-frontend
ports:
- name: http
port: 80 # ClusterIP Service Port
targetPort: 80 # Container Port
type: ClusterIP
In the screenshots I’ll demonstrate, I’ll use two additional deployments of the same type as 01-nginx-frontend.yml, but with a different version (tag) on Docker Hub of the same container .
Now, before we deploy our applications, we will construct a namespace where all of our work will be gathered.
my-namespace.yaml
apiVersion: v1 kind: Namespace metadata: name: ingress
using the following commands, you can deploy our applications:
kubectl apply -f ./my-namespace.yaml kubectl config set-context --current --namespace=ingress kubectl apply -f 01-backend-deployment.yml kubectl apply -f 01-nginx-frontend.yml kubectl apply -f 02-nginx-frontend.yml kubectl apply -f 03-nginx-frontend.yml
Use the following command to view our running services (also you can use the azure portal)
kubectl get services --namespace ingress
As you can see, we are using the ports that we have already set up to operate our services.
Part 2: Create an ingress controller in Azure Kubernetes Service (AKS)
In this section, we will install the ingress controller using a few command-lines .
Configuration :
# Add the ingress-nginx repository
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
# Use Helm to deploy an NGINX ingress controller
helm install app-ingress ingress-nginx/ingress-nginx `
--namespace ingress `
--create-namespace `
--set controller.replicaCount=1 `
--set controller.nodeSelector."kubernetes\.io/os"=linux `
--set defaultBackend.nodeSelector."kubernetes\.io/os"=linux
Now, we can use the following command to view our ingress controller and the newly created public IP address:
kubectl get services --namespace ingress -o wide -w app-ingress-ingress-nginx-controller


As you can see, our ingress domain currently lacks a certificate, making it insecure. In the next section, we’ll discuss how to add a certificate and force HTTP to HTTPS.




This concludes this section of our blog content.





















Comments 3