Introduction
In a previous article, I described how to run an ASP. NET core cross-platform Application (http://www.cnblogs.com/chenxizhang/p/7148657.html) in a local Docker environment, which looks very good, Isn't it? So what should we do if we want to actually deploy and run the application in the actual production environment?
In general, there are two options to choose from
1. Request virtual machines in the target runtime environment (either local or cloud), then enable Docker to run these applications, and all the details can (and must) be controlled by you.
2. Use the PAAs services of the cloud platform, especially the PAAs services that support the containerized cloud platform, which includes the Azure Container service, referred to as ACS. In this case, you can hand over some of the underlying details to Azure and focus your energy on the business application.
Introduction to ACS
Azure Container Service makes it easier to create, configure, and manage the set of virtual machines provisioned to run containerized applications. It uses the optimized configuration of popular open source plans and business process tools. With this service, users can deploy and manage container-based applications on Microsoft Azure using existing skills or leveraging a growing amount of community expertise. Please refer to the links below for some details, including quick hands-on labs
https://docs.microsoft.com/zh-cn/azure/container-service/
Publish a local Docker image
In fact, either way, a precondition is to publish your local image to a publicly accessible repository. You can publish to hub.docker.com, or you can publish to your own warehouse.
If you want to publish to hub.docker.com, refer to the following steps
1. You need to have a Docker ID. Please go to https://hub.docker.com/to register.
2. Place the image on your own tag locally. For example, my image is Mvcapp, my Docker ID is Chenxizhang, then to be able to publish to the Docker hub, this image needs to be tagged with a tag named Chenxizhang/mvcapp. Use this command to do this: Docker tag Mvcapp Chenxizhang/mvcapp
You don't have to worry, actually tag, just a logic above the map, and does not increase the local storage footprint.
3. Log in hub.docker.com using the Docker login command
4. Push the local image to hub.docker.com using a command such as Docker push Chenxizhang/mvcapp, which may take a certain amount of time, depending on your network configuration
If all goes well, you can see the following results
Note: If you are creating your own Docker warehouse, you can learn about the Azure Container Registry service. (https://azure.microsoft.com/zh-cn/services/container-registry/), do not unfold here.
Create kubernetes clusters in Azure Container service
You can refer to this introductory article completely (https://docs.microsoft.com/zh-cn/azure/container-service/ Container-service-kubernetes-walkthrough), create kubernetes clusters with a few simple commands
1. AZ Group Create
2.az ACS Create
3.az ACS Kubernetes INSTALL-CLI (This step is optional if you can omit it in azure Cloudshell)
4.az ACS Kubernetes Get-credentials
5.kubectl Get nodes (please wait for the status value of each node to become ready)
Deploying ASP. NET core applications in a k8s cluster
We already have a publicly accessible image and a cluster of containers. Here's how to get this app deployed and running in the k8s cluster.
Actually, it's simple. (This is, of course, an entry-level demonstration, with a lot of detail to adjust for each command)
1. Specify the image to pull with the Kubectl Run command, and run it by setting certain parameters. The term k8s This process is called creating a deployment (Deployment)
Kubectl run Mvcapp--image chenxizhang/mvcapp--env= "aspnetcore_urls=http://+:80"
2. Expose this deployment in some way to externally accessible
KUBECTL export deployments Mvcapp--port=80--type=loadbalance
3. Check the status of the service until EXTERNAL-IP has returned a specific value, which means that the container has been created and is running.
Kubectl Get Svc
4. With this external IP address you can access your app
Other interesting information and controls
If deploying an app to ACS is just such a feature, there's nothing to be commended for, in fact, the maximum value of ACS is to provide a powerful container-running platform that can help developers do a lot of detail, including scaling and shrinking container sizes, and so on. Here are some interesting information and controls
1. With Kubectl get deploy, you can view some details about each deployment
2. Kubectl get RS for each deployment-related replication set (replicas)
3. Use the KUBECTL scale command to specify how many containers to run for an app
Kubectl scale--replicas=3 rs/mvcapp-1456147153
Note: In fact, when Kubectl run, you can specify the number of containers to run at the same time, and if you prefer, you can set it to Autoscale (auto-expand)
Running an ASP. Kubernetes (k8s) cluster in Azure Container service Create a cross-platform application