Create a Kubernetes (k8s) cluster in Azure Container Service to run the ASP. NET Core cross-platform application, kubernetesk8s

Source: Internet
Author: User
Tags docker hub k8s

Create a Kubernetes (k8s) cluster in Azure Container Service to run the ASP. NET Core cross-platform application, kubernetesk8s
Introduction

In a previous article, I 've introduced how to run ASP. NET Core cross-platform applications (http://www.cnblogs.com/chenxizhang/p/7148657.html) in a local docker environment and it looks pretty good, isn't it? So what should we do if we want to deploy and run this application in the actual production environment?

Generally, there are two solutions to choose from.

1. apply for a virtual machine in the target running environment (either a local server or a cloud) and enable docker to run these applications. All the details are acceptable (and required) it is controlled by you.

2. Use the PaaS Service on the cloud platform, especially the PaaS Service that supports the containerized cloud platform, which includes Azure Container Service (ACS. In this case, you can hand over some bottom-layer details to Azure and focus your energy on business applications.


ACS Overview

Azure Container service makes it easier to create, configure, and manage Virtual Machine clusters that run containerized applications with pre-configuration. It uses popular open-source plans and Business Process Tools to optimize configurations. With this service, you can deploy and manage container-based applications on Microsoft Azure using existing skills or the increasing community expertise. Please refer to the links below for details, including quick hands-on experiments.

Https://docs.microsoft.com/zh-cn/azure/container-service/


Publish a local docker Image

In fact, no matter which solution you use, a prerequisite is to publish your local image to a public accessible repository. You can publish to hub.doc ker.com or your own repository.

If you want to migrate to hub.doc ker.com, refer to the following steps.

1. You need a Docker ID. Go to https://hub.docker.com/registration.

2. add your own tag to the local image. For example, if my image is mvcapp and my Docker ID is chenxizhang, you need to add a Tag named chenxizhang/mvcapp if you want to publish the image to Docker Hub. Run this command to complete the operation: docker tag mvcapp chenxizhang/mvcapp

You don't have to worry about it. In fact, tagging is just a logic above the ing and does not increase the space occupied by local storage.

3. Run the docker login command to log on to hub.doc ker.com.

4. Run the docker command to push the image to hub.doc ker.com, depending on your network configuration.

If everything goes well, you will see the following results


Note: If you want to create your own docker repository, you can learn about the Azure Container Registry service. (Https://azure.microsoft.com/zh-cn/services/container-registry/), do not expand here.


Create a Kubernetes cluster in Azure Container Service


You can refer to this getting started article (https://docs.microsoft.com/zh-cn/azure/container-service/container-service-kubernetes-walkthrough) to create a Kubernetes cluster with a few simple commands


1. az group create

2. az acs create

3. az acs kubernetes install-cli (this step is optional and can be omitted in azure cloudshell)

4. az acs kubernetes get-credentials

5. kubectl get nodes (please wait until the Status value of each node changes to Ready)



Deploy ASP. NET Core applications in the k8s cluster


We have an image that is publicly accessible and a container cluster. Now let's take a look at how to make this application centrally deployed and run in the k8s group.

In fact, it is very simple. (Of course, this is only an entry-level demonstration. Every command has many details to adjust)


1. Use the kubectl run Command to specify the image to be pulled and set certain parameters to run it. K8s refers to the process of creating a deployment)

Kubectl run mvcapp -- image chenxizhang/mvcapp -- env = "ASPNETCORE_URLS = http: // +: 80"


2. Expose the deployment to external users in some way.

Kubectl export deployments mvcapp -- port = 80 -- type = LoadBalance


3. view the service status until the EXTERNAL-IP returns a specific value, which means the container has been created and runs.

Kubectl get svc

4. Access your application through this external IP address


Other interesting information and control items

If deploying an application to ACS is just such a function, of course there is nothing to praise. In fact, the greatest value of ACS is that it provides a powerful container running platform, it can help developers complete a lot of detailed work, including scaling up and down the container scale. Below are some interesting information and control items

1. You can use kubectl get deploy to view details about each deployment.

2. get the replica set related to each deployment through kubectl get rs (replicas)

3. You can use the kubectl scale command to specify the number of containers to run for an application.

Kubectl scale -- replicas = 3 rs/mvcapp-1456147153

Note: In fact, when you run kubectl, you can specify the number of containers to run at the same time. You can also set it to autoscale if you want)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.