This article is the third part of series covering planning, solutioning, designing, developing, deploying and protecting Microservices deployed to Azure Kubernetes Services -
- Planning and Solutioning Microservices using Domain Driven Design
- Developing Microservices using .Net 5
- Deploying-Microservices to Azure Kubernetes Services
- Inter Microservices communication using Azure Service Bus
- Using Redis cache to increase performance during inter Microservices communicaiton
- Protecting Microservices inside Azure Kubernetes Services using Azure API Management
- Authenticate Microservices inside Azure Kubernetes Services using Azure Active Directory
This article covers following things –
- Add Dockerfile to our Employee Microservice project for creating Docker image
- Create Azure Container Registry that will be used to store Docker images of our Microservices
- Create Azure DevOps pipeline connecting GitHub code and deploying the Docker images in Azure Container Registry
- Setup Kubernetes environment using Azure Kubernetes Services where we will deploy our Microservices
- Create Ingress Controller that acts as all-in-one Load Balancer, Cache, API Gateway, and WAF for our Kubernetes environment
- Create Workloads in AKS
- Create Services to access our Workloads
- Create Ingress routes that our Ingress Controller will use to access the Services
- Add another MasterData Microservice using similar steps as Employee Microservice
-
Below is the code for Dockerfile
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging. FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base WORKDIR /app EXPOSE 80 EXPOSE 443 FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build WORKDIR /src COPY ["Employee/Coral.Employee.Api/Coral.Employee.Api.csproj", "Employee/Coral.Employee.Api/"] COPY ["Employee/Coral.Employee.Service/Coral.Employee.Service.csproj", "Employee/Coral.Employee.Service/"] COPY ["Employee/Coral.Employee.Broker/Coral.Employee.Broker.csproj", "Employee/Coral.Employee.Broker/"] COPY ["Employee/Coral.Employee.Persistance/Coral.Employee.Persistance.csproj", "Employee/Coral.Employee.Persistance/"] COPY ["Infrastructure/Coral.Infrastructure.CrossCutting/Coral.Infrastructure.CrossCutting.csproj", "Infrastructure/Coral.Infrastructure.CrossCutting/"] COPY ["Employee/Coral.Employee.Domain/Coral.Employee.Domain.csproj", "Employee/Coral.Employee.Domain/"] RUN dotnet restore "Employee/Coral.Employee.Api/Coral.Employee.Api.csproj" COPY . . WORKDIR "/src/Employee/Coral.Employee.Api" RUN dotnet build "Coral.Employee.Api.csproj" -c Release -o /app/build FROM build AS publish RUN dotnet publish "Coral.Employee.Api.csproj" -c Release -o /app/publish FROM base AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "Coral.Employee.Api.dll"]
-
Provision Azure Container Registry where we will store Docker images of Employee and other Microservices
Create Azure DevOps pipeline connecting GitHub code and deploying the Docker images in Azure Container Registry
-
Create pipeline in Azure DevOps to deploy Docker image of Employee Microservice to Azure Container Registry
Create Ingress Controller that acts as all-in-one Load Balancer, Cache, API Gateway, and WAF for our Kubernetes environment
-
We will use Helm to install nginx-ingress
-
Create a new namespace 'development' in Kubernetes cluster
-
Below is the full script for installing Ingress Contoller
az aks get-credentials --resource-group coral --name coralaks # Create a namespace for your ingress resources kubectl create namespace development # Add the ingress-nginx repository helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx # Use Helm to deploy an NGINX ingress controller helm install nginx-ingress ingress-nginx/ingress-nginx \ --namespace development \ --set controller.replicaCount=1 \ --set controller.nodeSelector."kubernetes\.io/os"=linux \ --set controller.admissionWebhooks.patch.nodeSelector."kubernetes\.io/os"=linux \ --set defaultBackend.nodeSelector."kubernetes\.io/os"=linux \
-
Below is the full code of deployment.yaml file
apiVersion: apps/v1 kind: Deployment metadata: name: employeeservice-deployment namespace: development spec: replicas: 1 selector: matchLabels: app: employeeservice-pod template: metadata: labels: app: employeeservice-pod spec: containers: - name: employeeservice-container image: coralregistry.azurecr.io/employeeservice:437 imagePullPolicy: Always ports: - containerPort: 80
-
Below is the full code of service.yaml file
apiVersion: v1 kind: Service metadata: name: employeeservice-service namespace: development spec: type: ClusterIP ports: - port: 80 selector: app: employeeservice-pod
-
Below is the full code of ingress.yaml file
apiVersion: networking.k8s.io/beta1v1 kind: Ingress metadata: name: ingress-service namespace: development annotations: kubernetes.io/ingress.class: nginx nginx.ingress.kubernetes.io/ssl-redirect: "false" nginx.ingress.kubernetes.io/use-regex: "true" nginx.ingress.kubernetes.io/rewrite-target: /$2 spec: rules: - http: paths: - path: /demo(/|$)(.*) pathType: Prefix backend: serviceName: employeeservice-service servicePort: 80
- Use the same approach to implement MasterData Microservice and deploy to AKS (code is uploaded to this GitHub repository)