Skip to main content

Azure Kubernetes Service에 배포하기

CD(연속 배포) 워크플로의 일부로 프로젝트를 Azure Kubernetes Service (AKS)에 배포하는 방법을 알아보세요.

이 기사에서

필수 조건

GitHub Actions 워크플로를 만들기 전에 먼저 다음 설정 단계를 완료해야 합니다.

  1. 대상 AKS 클러스터 및 ACR(Azure Container Registry)을 만듭니다. 자세한 내용은 Quickstart: Azure 포털을 사용하여 AKS 클러스터 배포 - Azure Kubernetes ServiceQuickstart - 포털에서 레지스트리 만들기 - Azure Container Registry Azure 설명서를 참조하세요.

  2.        `AZURE_CREDENTIALS`라는 비밀을 만들어 Azure 자격 증명을 저장합니다. 이 정보를 찾고 비밀을 구성하는 방법에 대한 자세한 내용은 [`Azure/login` 작업 설명서](https://github.com/Azure/login#configure-a-service-principal-with-a-secret) 참조하세요.
    

워크플로 만들기

필수 구성 요소를 완료한 후에는 워크플로 만들기를 진행할 수 있습니다.

다음 예제 워크플로에서는 코드를 리포지토리에 푸시할 때 Azure Kubernetes Service 프로젝트를 빌드하고 배포하는 방법을 보여 줍니다.

워크플로 env 키에서 다음 값을 바꿉니다. * AZURE_CONTAINER_REGISTRY를 컨테이너 레지스트리의 이름으로 바꿉니다. * PROJECT_NAME을 프로젝트의 이름으로 바꿉니다. * RESOURCE_GROUP을 AKS 클러스터가 포함된 리소스 그룹으로 바꿉니다. * CLUSTER_NAME을 AKS 클러스터 이름으로 바꿉니다.

이 워크플로는 helm``azure/k8s-bake 렌더링 엔진을 사용합니다. helm 렌더링 엔진을 사용하는 경우 CHART_PATH 값을 helm 파일의 경로로 변경합니다. CHART_OVERRIDE_PATH을 재정의 파일 경로 배열로 변경합니다. 다른 렌더링 엔진을 사용하는 경우 azure/k8s-bake 작업에 전송된 입력 매개 변수를 업데이트합니다.

YAML
# 이 워크플로는 GitHub에서 인증되지 않은 작업을 사용합니다.
# 작업은 타사에서 제공하며
# 별도의 서비스 약관, 개인정보처리방침, 지원 설명서에서 규정됩니다.
# 참조하세요.

# 커밋 SHA에 작업을 고정하는 것이 좋습니다.
# 최신 버전을 얻으려면 SHA를 업데이트해야 합니다.
# 태그 또는 분기를 참조할 수도 있지만 경고 없이 작업이 변경될 수 있습니다.

name: Build and deploy to Azure Kubernetes Service

env:
  AZURE_CONTAINER_REGISTRY: MY_REGISTRY_NAME # set this to the name of your container registry
  PROJECT_NAME: MY_PROJECT_NAME              # set this to your project's name
  RESOURCE_GROUP: MY_RESOURCE_GROUP          # set this to the resource group containing your AKS cluster
  CLUSTER_NAME: MY_CLUSTER_NAME              # set this to the name of your AKS cluster
  REGISTRY_URL: MY_REGISTRY_URL              # set this to the URL of your registry
  # If you bake using helm:
  CHART_PATH: MY_HELM_FILE                   # set this to the path to your helm file
  CHART_OVERRIDE_PATH: MY_OVERRIDE_FILES     # set this to an array of override file paths

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v5

    - name: Azure Login
      uses: azure/login@14a755a4e2fd6dff25794233def4f2cf3f866955
      with:
        creds: ${{ secrets.AZURE_CREDENTIALS }}

    - name: Build image on ACR
      uses: azure/CLI@61bb69d64d613b52663984bf12d6bac8fd7b3cc8
      with:
        azcliversion: 2.29.1
        inlineScript: |
          az configure --defaults acr=${{ env.AZURE_CONTAINER_REGISTRY }}
          az acr build -t -t ${{ env.REGISTRY_URL }}/${{ env.PROJECT_NAME }}:${{ github.sha }}

    - name: Gets K8s context
      uses: azure/aks-set-context@94ccc775c1997a3fcfbfbce3c459fec87e0ab188
      with:
          creds: ${{ secrets.AZURE_CREDENTIALS }}
          resource-group: ${{ env.RESOURCE_GROUP }}
          cluster-name: ${{ env.CLUSTER_NAME }}
      id: login

    - name: Configure deployment
      uses: azure/k8s-bake@61041e8c2f75c1f01186c8f05fb8b24e1fc507d8
      with:
        renderEngine: 'helm'
        helmChart: ${{ env.CHART_PATH }}
        overrideFiles: ${{ env.CHART_OVERRIDE_PATH }}
        overrides: |
          replicas:2
        helm-version: 'latest'
      id: bake

    - name: Deploys application
      uses: Azure/k8s-deploy@dd4bbd13a5abd2fc9ca8bdcb8aee152bb718fa78
      with:
        manifests: ${{ steps.bake.outputs.manifestsBundle }}
        images: |
          ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.PROJECT_NAME }}:${{ github.sha }}
        imagepullsecrets: |
          ${{ env.PROJECT_NAME }}

추가 참고 자료