Share via


자습서: Ansible을 사용하여 Azure에서 AKS(Azure Kubernetes Service) 클러스터 구성

Important

이 문서의 샘플 플레이북을 실행하려면 Ansible 2.8 이상이 필요합니다.

AKS(Azure Kubernetes Service)를 사용하면 Azure에서 관리되는 Kubernetes 클러스터를 간단하게 배포할 수 있습니다. AKS는 대부분의 부담을 Azure에 오프로딩하여 Kubernetes를 관리하는 복잡성 및 운영 과부하를 감소시킵니다. 호스팅되는 Kubernetes 서비스인 Azure는 상태 모니터링 및 유지 관리 같은 중요 작업을 처리합니다. Kubernetes 마스터는 Azure에서 관리됩니다. 에이전트 노드만 관리하고 기본. 관리되는 Kubernetes 서비스, AKS가 무료이므로 마스터가 아니라 클러스터 내의 에이전트 노드에 대해서만 지불합니다.

AKS는 사용자 인증에 Microsoft Entra ID를 사용하도록 구성할 수 있습니다. 구성되면 Microsoft Entra 인증 토큰을 사용하여 AKS 클러스터에 로그인합니다. RBAC는 사용자의 ID 또는 디렉터리 그룹 멤버 자격을 기반으로 할 수 있습니다.

이 문서에서는 다음 방법을 설명합니다.

  • AKS 클러스터 만들기
  • AKS 클러스터 구성

필수 조건

  • Azure 구독: Azure 구독이 아직 없는 경우 시작하기 전에 체험 계정을 만듭니다.
  • Azure 서비스 주체: appId, displayName, 암호테넌트 값을 기록하여 서비스 주체만듭니다.

관리되는 AKS 클러스터 만들기

이 샘플 플레이북은 리소스 그룹 및 리소스 그룹 내부의 AKS 클러스터를 만듭니다.

다음 플레이북을 azure_create_aks.yml로 저장합니다.

- name: Create Azure Kubernetes Service
  hosts: localhost
  connection: local
  vars:
    resource_group: myResourceGroup
    location: eastus
    aks_name: myAKSCluster
    username: azureuser
    ssh_key: "your_ssh_key"
    client_id: "your_client_id"
    client_secret: "your_client_secret"
    aks_version: aks_version
  tasks:
  - name: Create resource group
    azure_rm_resourcegroup:
      name: "{{ resource_group }}"
      location: "{{ location }}"
  - name: Create a managed Azure Container Services (AKS) cluster
    azure_rm_aks:
      name: "{{ aks_name }}"
      location: "{{ location }}"
      resource_group: "{{ resource_group }}"
      dns_prefix: "{{ aks_name }}"
      kubernetes_version: "{{aks_version}}"
      linux_profile:
        admin_username: "{{ username }}"
        ssh_key: "{{ ssh_key }}"
      service_principal:
        client_id: "{{ client_id }}"
        client_secret: "{{ client_secret }}"
      agent_pool_profiles:
        - name: default
          count: 2
          vm_size: Standard_D2_v2
      tags:
        Environment: Production

플레이북을 실행하기 전에 다음 정보를 참조하세요.

  • tasks 의 첫 번째 섹션은 위치 내에서 eastus 명명된 myResourceGroup 리소스 그룹을 정의합니다.
  • tasks 의 두 번째 섹션은 리소스 그룹 내에서 명명된 myAKSCluster AKS 클러스터를 myResourceGroup 정의합니다.
  • your_ssh_key 자리 표시자의 경우 RSA 공개 키를 "ssh-rsa"(따옴표 없이)로 시작하여 한 줄 형식으로 입력합니다.
  • aks_version 자리 표시자의 경우 az aks get-versions 명령을 사용합니다.

ansible-playbook을 사용하여 플레이북 실행

ansible-playbook azure_create_aks.yml

플레이북을 실행하면 다음 출력과 비슷한 결과가 표시됩니다.

PLAY [Create AKS] 

TASK [Gathering Facts] 
ok: [localhost]

TASK [Create resource group] 
changed: [localhost]

TASK [Create an Azure Container Services (AKS) cluster] 
changed: [localhost]

PLAY RECAP 
localhost                  : ok=3    changed=2    unreachable=0    failed=0

AKS 노드 크기 조정

이전 섹션에서 샘플 플레이북은 두 노드를 정의합니다. 블록의 값을 agent_pool_profiles 수정하여 count 노드 수를 조정합니다.

다음 플레이북을 azure_configure_aks.yml로 저장합니다.

- name: Scale AKS cluster
  hosts: localhost
  connection: local
  vars:
    resource_group: myResourceGroup
    location: eastus
    aks_name: myAKSCluster
    username: azureuser
    ssh_key: "your_ssh_key"
    client_id: "your_client_id"
    client_secret: "your_client_secret"
  tasks:
  - name: Scaling an existed AKS cluster
    azure_rm_aks:
        name: "{{ aks_name }}"
        location: "{{ location }}"
        resource_group: "{{ resource_group }}"
        dns_prefix: "{{ aks_name }}"
        linux_profile:
          admin_username: "{{ username }}"
          ssh_key: "{{ ssh_key }}"
        service_principal:
          client_id: "{{ client_id }}"
          client_secret: "{{ client_secret }}"
        agent_pool_profiles:
          - name: default
            count: 3
            vm_size: Standard_D2_v2

플레이북을 실행하기 전에 다음 정보를 참조하세요.

  • your_ssh_key 자리 표시자의 경우 RSA 공개 키를 "ssh-rsa"(따옴표 없이)로 시작하여 한 줄 형식으로 입력합니다.

ansible-playbook을 사용하여 플레이북 실행

ansible-playbook azure_configure_aks.yml

플레이북을 실행하면 다음 출력과 비슷한 결과가 표시됩니다.

PLAY [Scale AKS cluster] 

TASK [Gathering Facts] 
ok: [localhost]

TASK [Scaling an existed AKS cluster] 
changed: [localhost]

PLAY RECAP 
localhost                  : ok=2    changed=1    unreachable=0    failed=0

관리되는 AKS 클러스터 삭제

샘플 플레이북은 AKS 클러스터를 삭제합니다.

다음 플레이북을 azure_delete_aks.yml로 저장합니다.

- name: Delete a managed Azure Container Services (AKS) cluster
  hosts: localhost
  connection: local
  vars:
    resource_group: myResourceGroup
    aks_name: myAKSCluster
  tasks:
  - name:
    azure_rm_aks:
      name: "{{ aks_name }}"
      resource_group: "{{ resource_group }}"
      state: absent

ansible-playbook을 사용하여 플레이북 실행

ansible-playbook azure_delete_aks.yml

플레이북을 실행하면 다음 출력과 비슷한 결과가 표시됩니다.

PLAY [Delete a managed Azure Container Services (AKS) cluster] 

TASK [Gathering Facts] 
ok: [localhost]

TASK [azure_rm_aks] 

PLAY RECAP 
localhost                  : ok=2    changed=1    unreachable=0    failed=0

다음 단계