How to host Microservices

59 Views Asked by At

I'm totally new to Azure and overwhelmed by all the azure services. I have simple use-case and want to know what is the best (and cheapest option) to host this in Azure (it must be on azure).

Important: All Docker images are windows-based!

There is an Web Assembly / Webpage, build in a Docker image.
There are two Services. Maybe more in the future. Each service in a separate Docker image.
The hosting of the services should be scalable. But not high-scalable. It's enough if it can be scaled with a redeploy at night time.
There is also an NGINX Docker image for load balancing, routing and certificate handling.

The Web Assembly should have a Public IP Address. The services should be private and not accessible from the internet.

So, how should I deploy this in azure?

Any help is appreciated!

1

There are 1 best solutions below

2
Arko On BEST ANSWER

As mentioned in comments, you have different options. Option 1- Using AKS Option 2- like Azure App Service as Veverke mentioned.

How to choose the best option?

  • If simplicity and cost are your primary concerns, start with Azure Container Instances or Azure Container App Service and Azure Application Gateway or Front Door.

  • For applications that might grow in complexity, requiring detailed orchestration, scaling, and management, then Azure Kubernetes Service is the more suitable option.

Since you have Windows-based Docker images, you can use AKS with Windows Server containers. You can deploy your Web Assembly/Webpage and services as separate deployments in AKS, and use an NGINX ingress controller to handle load balancing, routing, and certificate handling. You can also use Kubernetes secrets to keep your services private and not accessible from the internet.

Similar example to demonstrate # How to host Microservices on AKS

Login to azure using az login Create an ACR and connect to it

az acr create -g rgname -n [registry-name] --sku Basic --admin-enabled

az acr login -n [registry-name]

enter image description here

build your docker image

mvn package

enter image description here enter image description here

docker build -t system:1.0-SNAPSHOT system/.
docker build -t inventory:1.0-SNAPSHOT inventory/.

enter image description here enter image description here

Check your image using-

  docker images

enter image description here

Tag and Push the image into your acr which you created above

docker tag system:1.0-SNAPSHOT [registry-server]/system:1.0-SNAPSHOT
docker tag inventory:1.0-SNAPSHOT [registry-server]/inventory:1.0-SNAPSHOT

docker push [registry-server]/system:1.0-SNAPSHOT
docker push [registry-server]/inventory:1.0-SNAPSHOT

enter image description here

Create your aks cluster

az aks create -g rgname -n guideCluster

enter image description here

Once cluster is up, verify using kubectl get nodes enter image description here

Create your deployments and services accordingly. enter image description here

in my case-

apiVersion: apps/v1
kind: Deployment
metadata:
  name: system-deployment
  labels:
    app: system
spec:
  selector:
    matchLabels:
      app: system
  template:
    metadata:
      labels:
        app: system
    spec:
      containers:
      - name: system-container
        image: arkoacr.azurecr.io/system:1.0-SNAPSHOT
        ports:
        - containerPort: 9080
      imagePullSecrets:
      - name: guidesecret
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: inventory-deployment
  labels:
    app: inventory
spec:
  selector:
    matchLabels:
      app: inventory
  template:
    metadata:
      labels:
        app: inventory
    spec:
      containers:
      - name: inventory-container
        image: arkoacr.azurecr.io/inventory:1.0-SNAPSHOT
        ports:
        - containerPort: 9081
      imagePullSecrets:
      - name: guidesecret
---
apiVersion: v1
kind: Service
metadata:
  name: system-service
spec:
  type: LoadBalancer
  selector:
    app: system
  ports:
  - protocol: TCP
    port: 9080
    targetPort: 9080
---
apiVersion: v1
kind: Service
metadata:
  name: inventory-service
spec:
  type: LoadBalancer
  selector:
    app: inventory
  ports:
  - protocol: TCP
    port: 9081
    targetPort: 9081

apply it using kubectl apply -f <youryamlfilename.yaml> and now when you do kubectl get pods or kubectl get service enter image description here enter image description here

You see that AKS has successfully deployed your microservice. It also provides automated Kubernetes version upgrades and patching, easy cluster scaling, and a self-healing hosted control plane. It also offers cost savings by only charging for running agent pool nodes. With Azure handling the management of the nodes in your AKS cluster, you no longer need to perform many tasks manually, like cluster upgrades. Because Azure handles these critical maintenance tasks for you.