Today I would like to share how to deploy ASP.NET MVC Core web application to Alibaba Cloud Container Service and also how to enable automatic horizontal scalability by using Serverless Kubernetes.
First, let's create a simple web application using Visual Studio 2019 Community.
We are going to build a docker image and publish to the Alibaba Cloud Container Registry, so remember to check Enable Docker Support. I also presume that you have installed Docker Desktop already.
While you are developing your own web application, you can choose to run the debug mode in IIS Express, self-hosted console or Docker.
Once you are happy with your coding and ready for deployment, go to Alibaba Cloud Container Registry to register a repository.
Once you have created a container repository, you will expect to see the following screen.
Clicking the Repository will bring you to the docker image push guide page. Follow the instruction below to push your docker image to the Alibaba Cloud.
So, back to your PC, fire up command prompt. Change directory to where your ASP.NET MVC Core project folder where you see the Dockerfile exist.
Now, execute the following command to compile your application and create a docker image.
docker build -f Dockerfile ..
Then, execute the docker images command to show your docker image ID.
Now, follow the steps mentioned in Alibaba Cloud Container Registry:
docker login xxxxxxx
docker tag xxxxxxxxx
docker push xxxxxxxx
Now, your docker image has been pushed to the cloud. You may proceed to create a Kubernetes Cluster now. There are many type of cluster, for my own research and testing purpose, I have chosen Standard Serverless Cluster.
Pick a region and select whatever setting that suit you.
Go to next page, then select the Image and Image Version. You will be able to see the docker image that you had pushed in the earlier step.
Select the CPU and Memory you need for each container. Then, configure the port for HTTP.
Then, hit the Create button, the Kubernetes service will be setup.
If you want to test whether your ASP.NET MVC application is hosted successfully, simply go to the Container Service page, then go to the Dashboard screen.
You can check your application status here.
Now, go to the Discovery and Load Balancing section, you can find your load balancer public endpoint IP address.
Simply hit the IP address, it should bring you to your web application.
In summary, horizontal scaling is always a pain in the arse before docker and Kubernetes exists during the old days. We have to spend a lot of money in purchasing the server in advance and manually power up the server, configure the web service and load balancer. With Alibaba Cloud Container Service, imagine how much money we could save from having system engineers and developers in working on the deployment job.
First, let's create a simple web application using Visual Studio 2019 Community.
We are going to build a docker image and publish to the Alibaba Cloud Container Registry, so remember to check Enable Docker Support. I also presume that you have installed Docker Desktop already.
While you are developing your own web application, you can choose to run the debug mode in IIS Express, self-hosted console or Docker.
Once you are happy with your coding and ready for deployment, go to Alibaba Cloud Container Registry to register a repository.
Once you have created a container repository, you will expect to see the following screen.
Clicking the Repository will bring you to the docker image push guide page. Follow the instruction below to push your docker image to the Alibaba Cloud.
So, back to your PC, fire up command prompt. Change directory to where your ASP.NET MVC Core project folder where you see the Dockerfile exist.
Now, execute the following command to compile your application and create a docker image.
docker build -f Dockerfile ..
Then, execute the docker images command to show your docker image ID.
Now, follow the steps mentioned in Alibaba Cloud Container Registry:
docker login xxxxxxx
docker tag xxxxxxxxx
docker push xxxxxxxx
Now, your docker image has been pushed to the cloud. You may proceed to create a Kubernetes Cluster now. There are many type of cluster, for my own research and testing purpose, I have chosen Standard Serverless Cluster.
Pick a region and select whatever setting that suit you.
Once you have done creating the new Kubernetes Cluster, now proceed to the Applications \ Deployments page to deploy your docker image to Kubernetes Container.
Fill up all the required information and select the Cluster as the one you had created in previous step.
Go to next page, then select the Image and Image Version. You will be able to see the docker image that you had pushed in the earlier step.
Select the CPU and Memory you need for each container. Then, configure the port for HTTP.
Go to next page to create a Service with Load Balancer. If you had created Load Balancer before, you can choose the existing one. Or, you can select Create SLB Instance like what I had done in this screen:
Now, setup the Ingress for your Load Balancer Service.
For the automatic horizontal scalability base on the server load, you can turn on the HPA (Horizontal Pod Autoscaler) feature, setup the condition of when should Kubernetes replicate a container to take up more load. For instance, I have setup minimum replica to begin with and if CPU of the replica hit 70% or above, it should replicate a new container immediately, and maximum up to 10 replica.
Then, hit the Create button, the Kubernetes service will be setup.
The following is how the Kubernetes Cluster screen look like:
If you want to test whether your ASP.NET MVC application is hosted successfully, simply go to the Container Service page, then go to the Dashboard screen.
You can check your application status here.
Now, go to the Discovery and Load Balancing section, you can find your load balancer public endpoint IP address.
Simply hit the IP address, it should bring you to your web application.
In summary, horizontal scaling is always a pain in the arse before docker and Kubernetes exists during the old days. We have to spend a lot of money in purchasing the server in advance and manually power up the server, configure the web service and load balancer. With Alibaba Cloud Container Service, imagine how much money we could save from having system engineers and developers in working on the deployment job.