Azure로 Kubernetes, Terraform 사용하기

이동건·2022년 11월 8일

azure cli 설치

brew update && brew install azure-cli

azure login

az login
A web browser has been opened at https://login.microsoftonline.com/organizations/oauth2/v2.0/authorize. Please continue the login in the web browser. If no web browser is available or if the web browser fails to open, use device code flow with `az login --use-device-code`.
[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": 
    "id": 
    "isDefault": true,
    "managedByTenants": [],
    "name": 
    "state": "Enabled",
    "tenantId": 
    "user": {
      "name": 
      "type": "user"
    }
  }
]
[~/Study/bootstrapping-microservices]$ az account show
{
  "environmentName": "AzureCloud",
  "homeTenantId": 
  "id": 
  "isDefault": true,
  "managedByTenants": [],
  "name": 
  "state": "Enabled",
  "tenantId": 
  "user": {
    "name": 
    "type": "user"
  }
}
[~/Study/bootstrapping-microservices]$ az account list
[
  {
    "cloudName": "AzureCloud",
    "homeTenantId": 
    "id": 
    "isDefault": true,
    "managedByTenants": [],
    "name": 
    "state": "Enabled",
    "tenantId": 
    "user": {
      "name": 
      "type": "user"
    }
  }
]

애저의 미국 서부 지역에서 가용한 쿠버네티스 버전 목록 확인

az aks get-versions --location westus
{
  "id": "/subscriptions/8645a8f2-c69f-4fac-b115-c0da8e26568d/providers/Microsoft.ContainerService/locations/westus/orchestrators",
  "name": "default",
  "orchestrators": [
    {
      "default": null,
      "isPreview": null,
      "orchestratorType": "Kubernetes",
      "orchestratorVersion": "1.22.11",
      "upgrades": [
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.22.15"
        },
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.23.8"
        },
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.23.12"
        }
      ]
    },
    {
      "default": null,
      "isPreview": null,
      "orchestratorType": "Kubernetes",
      "orchestratorVersion": "1.22.15",
      "upgrades": [
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.23.8"
        },
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.23.12"
        }
      ]
    },
    {
      "default": null,
      "isPreview": null,
      "orchestratorType": "Kubernetes",
      "orchestratorVersion": "1.23.8",
      "upgrades": [
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.23.12"
        },
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.24.3"
        },
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.24.6"
        }
      ]
    },
    {
      "default": true,
      "isPreview": null,
      "orchestratorType": "Kubernetes",
      "orchestratorVersion": "1.23.12",
      "upgrades": [
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.24.3"
        },
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.24.6"
        }
      ]
    },
    {
      "default": null,
      "isPreview": null,
      "orchestratorType": "Kubernetes",
      "orchestratorVersion": "1.24.3",
      "upgrades": [
        {
          "isPreview": null,
          "orchestratorType": "Kubernetes",
          "orchestratorVersion": "1.24.6"
        }
      ]
    },
    {
      "default": null,
      "isPreview": null,
      "orchestratorType": "Kubernetes",
      "orchestratorVersion": "1.24.6",
      "upgrades": null
    }
  ],
  "type": "Microsoft.ContainerService/locations/orchestrators"
}

1.24.6을 사용하자.

테라폼 설치

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

terraform --version
Terraform v1.3.4
on darwin_arm64

리소스 그룹 생성

cat scripts/resource-group.tf
# Creates a resource group for FlixTube in your Azure account.

resource "azurerm_resource_group" "flixtube" {
  name     = "flixtube"
  location = "West US"
}

resource : 애저 리소스 그룹을 선언. 우리가 만들 모든 리소스를 포함. 기본적으로 사용.
name : 리소스 그룹 이름 설정
location : 리소스 그룹을 만들 데이터센터 위치 설정

flixtube라는 애저 리소스 그룹을 azurerm_resource_group 타입으로 선언.

terraform init 하니 에러 발생

terraform init

Initializing the backend...

Initializing provider plugins...
- Finding hashicorp/azurerm versions matching "1.38.0"...
╷
│ Warning: Version constraints inside provider configuration blocks are deprecated
│
│   on providers.tf line 4, in provider "azurerm":
│    4:     version = "1.38.0"
│
│ Terraform 0.13 and earlier allowed provider version constraints inside the provider configuration block, but that is now deprecated and will be removed in
│ a future version of Terraform. To silence this warning, move the provider version constraint into the required_providers block.
╵

╷
│ Error: Incompatible provider version
│
│ Provider registry.terraform.io/hashicorp/azurerm v1.38.0 does not have a package available for your current platform, darwin_arm64.
│
│ Provider releases are separate from Terraform CLI releases, so not all providers are available for all platforms. Other versions of this provider may have
│ different platforms supported.
╵

brew uninstall terraform
brew install tfenv
TFENV_ARCH=amd64 tfenv install 1.3.3
tfenv use 1.3.3
해준다

profile
코드를 통한 세계의 창조

0개의 댓글