Deploying to Microsoft Azure Cloud
本指南涵盖:
This guide covers:
-
Update Quarkus HTTP Port
-
Install the Azure CLI
-
Create an Azure Registry Service instance and upload the Docker image
-
Deploy the Docker image to Azure Container Instances
-
Deploy the Docker image to Azure Kubernetes Service
-
Deploy the Docker image to Azure App Service for Linux Containers
Prerequisites
Unresolved directive in deploying-to-azure-cloud.adoc - include::{includes}/prerequisites.adoc[]* 能够访问某个 Azure 订阅。 Get a free one here
Unresolved directive in deploying-to-azure-cloud.adoc - include::{includes}/prerequisites.adoc[] * Having access to an Azure subscription. Get a free one here
本指南将以本机应用程序为输入,这些应用程序开发于 building native image guide中。
This guide will take as input a native application developed in the building native image guide.
确保你备有入门应用程序,或者克隆 Git 存储库: git clone {quickstarts-clone-url}
,或下载一个 {quickstarts-archive-url}[存档]。该解决方案位于 `getting-started`目录中。
Make sure you have the getting-started application at hand, or clone the Git repository: git clone {quickstarts-clone-url}
, or download an {quickstarts-archive-url}[archive]. The solution is located in the getting-started
directory.
Change Quarkus HTTP Port
如果已正确遵循 building native image guide,你应该有一个名为 `quarkus-quickstart/getting-started`的本地容器映像。
If you correctly followed the building native image guide, you should have a local container image named quarkus-quickstart/getting-started
.
Quarkus 虽然默认在 8080 端口上运行,但大多数 Azure 服务都期望 Web 应用程序在 80 端口上运行。在继续阅读前,返回快速入门代码并打开文件 src/main/docker/Dockerfile.native
。
While Quarkus by default runs on port 8080, most Azure services expect web applications to be running on port 80. Before we continue, go back to your quickstart code and open the file src/main/docker/Dockerfile.native
.
更改 `Dockerfile.native`文件中的最后两条命令,并使其如下文所示:
Change the last two commands in the Dockerfile.native
file and make it read like this:
EXPOSE 80
CMD ["./application", "-Dquarkus.http.host=0.0.0.0", "-Dquarkus.http.port=80"]
现在,你可以重新生成 docker 映像:
Now you can rebuild the docker image:
$ docker build -f src/main/docker/Dockerfile.native -t quarkus-quickstart/getting-started .
要进行测试,通过在你自己的主机中将端口 80 映射到端口 8080 来运行它:
To test, run it by exposing port 80 into port 8080 in your host:
$ docker run -i --rm -p 8080:80 quarkus-quickstart/getting-started
你的容器映像现在已准备好可在 Azure 上运行。记住,Quarkus 应用程序映射为在端口 80 上运行。
Your container image is now ready to run on Azure. Remember, the Quarkus application is mapped to run on port 80.
Install the Azure CLI
为了方便你在本指南中的用户体验,最好安装 Azure CLI 并进行身份验证。
To ease the user experience throughout this guide, it is better to have the Azure CLI installed and authenticated.
请访问 Azure CLI安装页面,以获取特定于你操作系统的信息。
Visit the Azure CLI installation page for instructions specific to your operating system.
安装后,确保你已通过身份验证:
Once installed, ensure you are authenticated:
$ az login
Create an Azure Container Registry instance
可以部署托管在 Docker Hub 上的映像,但这会使映像默认对所有人可访问。为了更好地保护你的容器映像,本指南展示了如何在 Azure 容器注册表服务的私有实例中托管你的映像。
It is possible to deploy images hosted on Docker Hub, but this location by default leaves images accessible to anyone. To better protect your container images, this guide shows how to host your images on a private instance of the Azure Container Registry service.
首先,创建一个 Azure 资源组:
First, create an Azure Resource Group:
$ az group create --name <resource-group-name> --location eastus
然后,你可以创建 ACR:
Then you can create the ACR:
$ az acr create --resource-group <resource-group-name> --name <registry-name> --sku Basic --admin-enabled true
最后,通过运行以下命令对你的本地 Docker 安装进行身份验证,使其能够使用此容器注册表:
Finally, authenticate your local Docker installation with this container registry by running:
$ az acr login --name <registry-name>
Upload Container Image on Azure
如果你已按照生成本机映像指南进行操作,你应会拥有一个名为 `quarkus-quickstart/getting-started`的本地容器映像。
If you’ve followed the build native image guide, you should have a local container image named quarkus-quickstart/getting-started
.
要将此映像上传至你的 ACR,你必须标记该映像并将该映像推送至 ACR 登录服务器下。要查找 Azure 容器注册表的登录服务器,请运行此命令:
To upload this image to your ACR, you must tag and push the image under the ACR login server. To find the login server of the Azure Container Registry, run this command:
$ az acr show -n <registry-name> --query loginServer -o tsv
要上传,现在执行:
To upload, now do:
$ docker tag quarkus-quickstart/getting-started <acr-login-server>/quarkus-quickstart/getting-started
$ docker push <acr-login-server>/quarkus-quickstart/getting-started
在这一点上,Azure 容器注册表中应该有 Quarkus 容器映像。若要验证,请运行以下命令:
At this point, you should have your Quarkus container image on your Azure Container Registry. To verify, run the following command:
$ az acr repository list -n <registry-name>
Deploy to Azure Container Instances
在云中启动此容器的最简单方法是使用 Azure 容器实例服务。它只在 Azure 基础架构上创建一个容器。
The simplest way to start this container in the cloud is with the Azure Container Instances service. It simply creates a container on Azure infrastructure.
对于使用 ACI 有不同的方法。请查看文档以了解详细信息。使容器启动并运行的最快方法如下。
There are different approaches for using ACI. Check the documentation for details. The quickest way to get a container up and running goes as it follows.
第一步是查找管理员的用户名和密码,以便 ACI 可以验证 ACR 并提取 Docker 映像:
First step is to find the username and password for the admin, so that ACI can authenticate into ACR and pull the Docker image:
$ az acr credential show --name <registry-name>
现在,在 ACI 上创建一个指向 ACR 上映像的 Docker 实例:
Now create the Docker instance on ACI pointing to your image on ACR:
$ az container create \
--name quarkus-hello \
--resource-group <resource-group> \
--image <acr-login-server>/quarkus-quickstart/getting-started \
--registry-login-server <acr-login-server> \
--registry-username <acr-username> \
--registry-password <acr-password> \
--dns-name-label quarkus-hello-<random-number> \
--query ipAddress.fqdn
如果运行成功,则上面的命令将为你提供你在云中的容器的地址。以显示为输出的地址访问你的 Quarkus 应用程序。
The command above, if run successfully, will give you the address of your container in the Cloud. Access your Quarkus application in the address displayed as output.
有关 ACR 身份验证和服务主体使用的详细信息和更多信息,请遵循以下指南,并记住 Azure 容器注册表 loginServer
中的 Quarks 应用程序现已托管在 ACR 上的映像名称。
For more information and details on ACR authentication and the use of service principals, follow this guide below and remember the Azure Container Registry loginServer
and the image name of your Quarkus application now hosted on the ACR.
请记住,此服务不提供可扩展性。容器实例是唯一的,不会扩展。
Keep in mind that this service does not provide scalability. A container instance is unique and does not scale.
Deploy to Azure Kubernetes Service
你还可以将容器映像作为 Azure 上 Kubernetes 集群中的微服务进行部署。为此,请遵循本教程:
You can also deploy the container image as a microservice in a Kubernetes cluster on Azure. To do that, follow this tutorial:
部署后,应用程序将运行在用于公开服务的任何端口上。默认情况下,Quarkus 应用程序在内部运行在端口 8080 上。
Once deployed, the application will be running on whatever port is used to expose the service. By default, Quarkus apps run on port 8080 internally.
Deploy to Azure App Service on Linux Containers
此服务为 Web 应用程序开箱即用地提供可扩展性。如果需要更多实例,它将自动提供负载平衡,外加监控、指标、日志记录等等。
This service provides scalability out of the box for web applications. If more instances are required, it will provide a load-balancing automatically, plus monitoring, metrics, logging and so on.
若要将 Quarkus 原生容器映像部署到此服务,请遵循本教程:
To deploy your Quarkus Native container image to this service, follow this tutorial: