Azure 컨테이너 앱에 Java Azure 함수 배포
Azure Functions는 Azure Container Apps에서 컨테이너화된 함수 앱을 개발, 배포 및 관리하기 위한 통합 지원을 제공합니다. 이를 통해 AKS(Azure Kubernetes Service)와 같은 컨테이너 환경에서 Azure Functions를 독립적으로 실행하는 것에 비해 통합 Azure 관리 포털을 사용하여 Azure Functions를 더 쉽게 실행하고 관리할 수 있습니다. 또한 Azure Container Apps에서 제공하는 기능을 활용하면 Azure Functions에 대한 KEDA, Dapr, Envoy, 크기 조정, 모니터링, 보안 및 액세스 제어와 같은 기능을 쉽게 활용할 수 있습니다.
[참고]
Azure Functions의 Azure Container Apps 호스팅
Azure Container Apps에서 첫 번째 컨테이너화된 함수 만들기
환경 변수 설정
다음은 Azure Container Apps 리소스 생성과 관련된 환경 변수입니다. 여기에서는 생성할 리소스의 다양한 이름과 설치 위치는 물론 컨테이너 이미지 이름과 태그를 지정합니다.
# Azure Container Apps resource names export LOCATION=eastus export RESOURCE_GROUP_NAME=yoshio-rg export CONTAINER_REGISTRY_NAME=cajava2411 export CONTAINER_ENVIRONMENT=YoshioContainerEnvironment export STORAGE_NAME=yoshiojavastorage export AZURE_FUNCTION_NAME=yoshiojavafunc # Container image name and tag export C_IMAGE_NAME=tyoshio2002/java-function-on-aca export C_IMAGE_TAG=1.0
Java Azure 함수 프로젝트 생성 및 테스트
1. Java Maven 프로젝트용 Azure Functions 생성
먼저 Azure Functions for Java용 Maven 프로젝트를 만듭니다. 이 Maven 프로젝트는 Java 21을 사용하여 Azure Functions를 생성하도록 설계되었습니다. mvn archetype:generate 명령을 사용하여 프로젝트를 생성하고 필요에 따라 매개 변수를 수정합니다.
mvn archetype:generate \ -DinteractiveMode=false \ -DarchetypeGroupId=com.microsoft.azure \ -DarchetypeArtifactId=azure-functions-archetype \ -DgroupId=com.yoshio3 \ -Dpackage=com.yoshio3 \ -DartifactId=yoshiojavafunc \ -DappName=Java-Azure-Functions \ -DappRegion=$LOCATION \ -DjavaVersion=21 \ -Dversion=1.0-SNAPSHOT \ -Ddocker
위 명령을 실행하면 디렉터리 구조가 자동으로 생성되고 Function.java에는 HTTP 트리거가 있는 Azure 함수에 대한 샘플 코드가 포함됩니다. Docker 컨테이너 환경에서 Azure Functions를 실행하기 위한 구성이 포함된 Dockerfile도 생성됩니다.
├── Dockerfile ├── host.json ├── local.settings.json ├── pom.xml └── src ├── main │ └── java │ └── com │ └── yoshio3 │ └── Function.java └── test └── java └── com └── yoshio3 ├── FunctionTest.java └── HttpResponseMessageMock.java
2. 로컬에서 Azure 함수 실행
Maven 프로젝트를 빌드하고 Azure Functions를 로컬에서 실행합니다. 다음 명령을 실행하여 HTTP 트리거로 Azure Functions를 시작합니다.
mvn clean package mvn azure-functions:run
Azure Functions가 실행되면 다른 터미널을 열고 다음 명령을 실행하여 HTTP 트리거에 요청을 보냅니다. "Hello, World"라는 응답을 받아야 합니다.
curl "http://localhost:7071/api/HttpExample?name=World" # Output: Hello, World
Azure Functions 컨테이너 이미지 생성 및 테스트
1. Docker 이미지 빌드 및 테스트
자동으로 생성된 Dockerfile을 사용하여 Azure Functions 컨테이너 이미지를 빌드합니다. 다음 명령을 실행하여 이미지를 빌드합니다.
docker build -t $C_IMAGE_NAME:$C_IMAGE_TAG -f ./Dockerfile .
빌드가 완료되면 다음 명령어를 실행하여 이미지가 생성되었는지 확인하세요.
docker images | grep $C_IMAGE_NAME # Output: tyoshio2002/java-function-on-aca 1.0 bcf471e6f774 9 hours ago 1.46GB
이미지가 생성되면 다음 명령을 실행하여 Azure Functions 컨테이너 이미지를 로컬에서 테스트합니다. Azure Functions 컨테이너는 내부적으로 HTTP 포트 80을 사용하므로 로컬 액세스를 위해 포트 8080에 매핑합니다. 컨테이너가 시작된 후 컬 명령을 실행하여 Azure Functions HTTP 트리거에 요청을 보냅니다. 모든 것이 올바르게 작동하면 "Hello, World" 메시지가 표시됩니다.
docker run -p 8080:80 -it $C_IMAGE_NAME:$C_IMAGE_TAG curl "http://localhost:8080/api/HttpExample?name=World" # Output: Hello, World
컨테이너 이미지를 Azure Container Registry로 푸시
1. 애저 CLI에 로그인
먼저 Azure CLI를 사용하여 Azure에 로그인합니다. 다음 명령어를 실행하여 로그인하세요.
az login
2. 리소스 그룹 생성
Azure에서 리소스 그룹을 만듭니다. 이 리소스 그룹은 Azure Container Registry 및 Azure Container Apps와 관련된 리소스를 그룹화하는 데 사용됩니다.
az group create --name $RESOURCE_GROUP_NAME --location $LOCATION
3. Azure Container Registry 생성 및 로그인
Azure Container Registry를 만들고 로그인하세요. Azure Container Registry는 컨테이너 이미지 푸시를 위한 프라이빗 컨테이너 레지스트리입니다.
az acr create --resource-group $RESOURCE_GROUP_NAME --name $CONTAINER_REGISTRY_NAME --sku Basic az acr login --name $CONTAINER_REGISTRY_NAME
4. Azure Container Registry 서버 이름 검색
생성된 Azure Container Registry의 서버 이름을 검색합니다. 서버 이름은 $CONTAINER_REGISTRY_NAME.azurecr.io 형식입니다.
CONTAINER_REGISTRY_SERVER=$(az acr show --name $CONTAINER_REGISTRY_NAME --query loginServer --output tsv)
5. 이미지를 Azure Container Registry에 푸시
로컬에서 생성된 컨테이너 이미지를 Azure Container Registry에 푸시하려면 tag 명령을 사용하여 이미지에 태그를 지정하세요. 태그를 붙인 후 push 명령을 사용하여 이미지를 푸시합니다.
docker tag $C_IMAGE_NAME:$C_IMAGE_TAG $CONTAINER_REGISTRY_SERVER/$C_IMAGE_NAME:$C_IMAGE_TAG docker push $CONTAINER_REGISTRY_SERVER/$C_IMAGE_NAME:$C_IMAGE_TAG
Azure 컨테이너 앱 생성 및 Java Azure 함수 배포
1. Azure CLI에 확장 및 리소스 공급자 등록
Azure CLI에서 Azure Container Apps를 생성하고 관리하려면 필요한 확장 프로그램과 리소스 공급자를 등록하세요.
az upgrade az extension add --name containerapp --upgrade -y az provider register --namespace Microsoft.Web az provider register --namespace Microsoft.App az provider register --namespace Microsoft.OperationalInsights
2. Azure 컨테이너 앱 환경 생성
Azure Container Apps용 환경을 만듭니다. 이 명령은 Azure Container Apps를 호스팅하는 데 필요한 구성을 설정합니다.
az containerapp env create --name $CONTAINER_ENVIRONMENT --enable-workload-profiles --resource-group $RESOURCE_GROUP_NAME --location $LOCATION
3. Create Storage Account for Azure Functions
Azure Functions requires a storage account when creating a Function App instance. Therefore, create a general-purpose storage account for Azure Functions.
az storage account create --name $STORAGE_NAME --location $LOCATION --resource-group $RESOURCE_GROUP_NAME --sku Standard_LRS
4. Create an Instance of Java Azure Function in Azure Container Apps
Create an instance of the Java Azure Function in Azure Container Apps. Execute the following command to create the instance. Since the Azure Function is created using Java 21, specify --runtime java.
az functionapp create --name $AZURE_FUNCTION_NAME \ --resource-group $RESOURCE_GROUP_NAME \ --environment $CONTAINER_ENVIRONMENT \ --storage-account $STORAGE_NAME \ --workload-profile-name "Consumption" \ --max-replicas 15 \ --min-replicas 1 \ --functions-version 4 \ --runtime java \ --image $CONTAINER_REGISTRY_SERVER/$C_IMAGE_NAME:$C_IMAGE_TAG \ --assign-identity
5. Assign Role for Azure Function to Access Azure Container Registry
Finally, configure secure access for Azure Functions to Azure Container Registry. Enable the system-managed identity for Azure Functions and assign the ACRPull role for access.
FUNCTION_APP_ID=$(az functionapp identity assign --name $AZURE_FUNCTION_NAME --resource-group $RESOURCE_GROUP_NAME --query principalId --output tsv) ACR_ID=$(az acr show --name $CONTAINER_REGISTRY_NAME --query id --output tsv) az role assignment create --assignee $FUNCTION_APP_ID --role AcrPull --scope $ACR_ID
6. Retrieve the URL of the Azure Function
Finally, retrieve the HTTP trigger function URL of the deployed Azure Function. Use the az functionapp function show command to get the details of the Azure Functions function.
az functionapp function show --resource-group $RESOURCE_GROUP_NAME --name $AZURE_FUNCTION_NAME --function-name HttpExample --query invokeUrlTemplate # Output: "https://yoshiojavafunc.niceocean-********.eastus.azurecontainerapps.io/api/httpexample"
You can then send a request to the retrieved URL using curl command to confirm that the Azure Functions is working correctly.
curl "https://yoshiojavafunc.niceocean-********.eastus.azurecontainerapps.io/api/httpexample?name=World" # Expected Output: Hello, World
If everything is set up correctly, you should receive a response saying "Hello, World", confirming that your Azure Function is functioning as expected.
Summary
In this guide, you learned how to:
- Set up environment variables for your Azure resources.
- Create a Java Azure Function project using Maven.
- Run the Azure Function locally for testing.
- Build a Docker image for the Azure Function.
- Push the Docker image to Azure Container Registry.
- Create an Azure Container Apps environment and deploy the Java Azure Function.
- Assign necessary roles for secure access to Azure Container Registry.
- Retrieve and test the URL of the deployed Azure Function.
By following these steps, you can successfully deploy a Java Azure Function on Azure Container Apps, leveraging the benefits of containerization and Azure's integrated management capabilities. If you have any further questions or need assistance with specific steps, feel free to ask!
위 내용은 Azure 컨테이너 앱에 Java Azure 함수 배포의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











일부 애플리케이션이 제대로 작동하지 않는 회사의 보안 소프트웨어에 대한 문제 해결 및 솔루션. 많은 회사들이 내부 네트워크 보안을 보장하기 위해 보안 소프트웨어를 배포 할 것입니다. ...

시스템 도킹의 필드 매핑 처리 시스템 도킹을 수행 할 때 어려운 문제가 발생합니다. 시스템의 인터페이스 필드를 효과적으로 매핑하는 방법 ...

데이터베이스 작업에 MyBatis-Plus 또는 기타 ORM 프레임 워크를 사용하는 경우 엔티티 클래스의 속성 이름을 기반으로 쿼리 조건을 구성해야합니다. 매번 수동으로 ...

많은 응용 프로그램 시나리오에서 정렬을 구현하기 위해 이름으로 이름을 변환하는 솔루션, 사용자는 그룹으로, 특히 하나로 분류해야 할 수도 있습니다.

IntellijideAultimate 버전을 사용하여 봄을 시작하십시오 ...

Java 객체 및 배열의 변환 : 캐스트 유형 변환의 위험과 올바른 방법에 대한 심층적 인 논의 많은 Java 초보자가 객체를 배열로 변환 할 것입니다 ...

전자 상거래 플랫폼에서 SKU 및 SPU 테이블의 디자인에 대한 자세한 설명이 기사는 전자 상거래 플랫폼에서 SKU 및 SPU의 데이터베이스 설계 문제, 특히 사용자 정의 판매를 처리하는 방법에 대해 논의 할 것입니다 ...

데이터베이스 쿼리에 tkmyBatis를 사용하는 경우 쿼리 조건을 구축하기 위해 엔티티 클래스 변수 이름을 우아하게 가져 오는 방법이 일반적인 문제입니다. 이 기사는 고정 될 것입니다 ...
