1. 개요


Azure Kubernetes Service에서 클러스터를 배포하기 위해 Azure CLI와 ARM Template을 사용하는 방법을 소개한다.

 

2. Azure CLI를 사용하여 클러스터 배포


1) Resource group 생성

AKS의 리소스가 생성될 리소스 그룹을 생성한다.

> az group create --name snowball-k8s --location koreacentral
{
  "id": "/subscriptions/5f57fbd8-20d1-4568-aecf-3c3dd6e09717/resourceGroups/snowball-k8s",
  "location": "koreacentral",
  "managedBy": null,
  "name": "snowball-k8s",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": null,
  "type": "Microsoft.Resources/resourceGroups"
}

 

*) location 옵션의 값을 확인하는 방법

az account list-locations 명령어 실행 결과 중 name에 해당하는 값을 확인한다.

> az account list-locations
[
  {
    "displayName": "East Asia",
    "id": "/subscriptions/5f57fbd8-20d1-4568-aecf-3c3dd6e09717/locations/eastasia",
    "latitude": "22.267",
    "longitude": "114.188",
    "name": "eastasia",
    "subscriptionId": null
  },
  {
    "displayName": "Southeast Asia",
    "id": "/subscriptions/5f57fbd8-20d1-4568-aecf-3c3dd6e09717/locations/southeastasia",
    "latitude": "1.283",
    "longitude": "103.833",
    "name": "southeastasia",
    "subscriptionId": null
  },
  ...
    {
    "displayName": "Norway West",
    "id": "/subscriptions/5f57fbd8-20d1-4568-aecf-3c3dd6e09717/locations/norwaywest",
    "latitude": "58.969975",
    "longitude": "5.733107",
    "name": "norwaywest",
    "subscriptionId": null
  },
  {
    "displayName": "Norway East",
    "id": "/subscriptions/5f57fbd8-20d1-4568-aecf-3c3dd6e09717/locations/norwayeast",
    "latitude": "59.913868",
    "longitude": "10.752245",
    "name": "norwayeast",
    "subscriptionId": null
  }
]

 

2) AKS Cluster 생성

az aks create 명령을 실행하여 AKS 클러스터를 생성한다.

> az aks create --resource-group snowball-k8s --name sb-cluster --node-count 1 --enable-addons monitoring --generate-ssh-keys
SSH key files 'id_rsa' and 'id_rsa.pub' have been generated under ~/.ssh to allow SSH access to the VM. If using machines without permanent storage like Azure Cloud Shell without an attached file share, back up your keys to a safe location
Finished service principal creation[##################################]  100.0000%
  • --resource-group: 위에서 생성한 리소스 그룹 지정
  • --name: 쿠버네티스 클러스터 이름 지정
  • --node-count: 쿠버네티스 노드를 1개 생성
  • --enable-addons: monitoring을 위해 컨테이너용 Azure Monitor를 활성화
  • --generate-ssh-keys: 노드에 접속하기 위한 ssh 키 생성

 

3) 클러스터에 연결

# 클러스터를 관리하기 위해 kubectl를 설치
> az aks install-cli --install-location=./kubectl
# AKS 클러스터에 연결하도록 kubectl을 구성
> az aks get-credentials --resource-group snowball-k8s --name sb-cluster
# 클러스터 노드 목록 확인
> kubectl get nodes

 

3. ARM Template를 사용하여 클러스터 배포


1) public SSH Key 생성

노드에 접속하기 위한 SSH 키를 생성한다.

> ssh-keygen -t rsa -b 2048

 

2) Service Principal 생성

AKS 클러스터가 다른 Azure 리소스와 통합하여 사용될 수 있도록 Azure Active Directory Service Principal를 생성한다. 아래 출력 내용을 따로 기록해둔다.

> az ad sp create-for-rbac --skip-assignment
{
  "appId": "///",
  "displayName": "///",
  "name": "///",
  "password": "///",
  "tenant": "///"
}
  • --skip-assignment: 다른 추가 사용 권한 할당을 방지

 

3) ARM Template을 통한 AKS 클러스터 배포

Azure Resource Manager에서는 많이 사용되는 Azure 인프라 구성을 JSON 파일 형태의 템플릿으로 제공한다. AKS 클러스터를 생성하는 JSON 템플릿을 활용하여 클러스터를 배포한다.

홈 > 모든 리소스 > 추가 클릭

새로만들기 > template 검색하여 Template deployment 선택

GitHub 빠른 시작 템플릿 로드 > 101-aks 선택

AKS 클러스터 생성에 필요한 정보 입력

  • SSH RSA Public Key: 위에서 생성한 SSH 키를 입력한다.
  • Service Principal Client Id: 위에서 생성한 Service Principal 결과 값 중 appId 값을 입력한다.
  • Service Principal Client Secret: 위에서 생성한 Service Principal 결과 값 중 password 값을 입력한다.

 

4) 클러스터에 연결

# 클러스터를 관리하기 위해 kubectl를 설치
> az aks install-cli --install-location=./kubectl
# AKS 클러스터에 연결하도록 kubectl을 구성
> az aks get-credentials --resource-group snowball-k8s --name sb-cluster-arm
# 클러스터 노드 목록 확인
> kubectl get nodes