Я не публиковал сообщения уже несколько недель, но, наконец, у меня появилось время сделать это: я присоединился к команде AI Platform Notebooks 2 месяца назад. В рамках этой роли я в основном работал с Notebooks API, что было очень интересно (изучение инфраструктуры Google Cloud Backend и GoLang). Одной из запрошенных нами функций было добавление поддержки API Notebooks в Terraform. (Terraform: инструмент, используемый для превращения разработки инфраструктуры в код). Поэтому я решил взяться за эту задачу, разработав модуль Terraform для ноутбуков, позвольте мне объяснить вам, как его использовать:
Сегодня вы можете развернуть образ виртуальной машины Deep Learning с помощью Terraform. Но теперь вы можете использовать Notebooks API прямо в Terraform (google_notebooks_instance).
Изменить: Terraform Notebooks теперь использует Notebooks API v1. Это означает, что вам больше не нужно использовать бета-версию Google.
Чтобы начать работу с записными книжками на платформе AI в Terraform, сделайте следующее:
Загрузите и установите последнюю версию Terraform, в данном случае версию 0.12.28.
wget https://releases.hashicorp.com/terraform/1.0.9/terraform_1.0.9_linux_amd64.zip unzip terraform_1.0.9_linux_amd64.zip mv terraform /usr/local/bin/terraform # Verify version terraform version # Enable Google Cloud Notebooks API gcloud services enable notebooks.googleapis.com
Создайте следующие файлы:
- main.tf
- variables.tf
- instance.tf
Детали экземпляра:
resource “random_id” “instance_id” { byte_length = 8 } resource “google_notebooks_instance” “instance” { provider = google-beta name = “nb-${random_id.instance_id.hex}” location = var.location machine_type = “n1-standard-1” install_gpu_driver = true accelerator_config { type = “NVIDIA_TESLA_T4” core_count = 1 } vm_image { project = “deeplearning-platform-release” image_family = “tf-latest-gpu” } }
Инициализировать Terraform
terraform init
Выполните этап планирования, чтобы проверить синтаксис конфигурации и предварительно просмотреть то, что будет создано.
terraform plan
Развернуть экземпляр
terraform apply
Пример
# Clone repo git clone https://github.com/GoogleCloudPlatform/ai-platform-samples.git cd ai-platform-samples/notebooks/tools/terraform/notebooks # Google Cloud configuration export GOOGLE_APPLICATION_CREDENTIALS="${KEYFILE}" gcloud config set project "${PROJECT_ID}" # Initialize Terraform terraform init # Validate Terraform configuration terraform plan # Deploy Google Cloud Notebooks Instance terraform apply
Пример:
var.credentials_file Enter a value: /Users/gogasca/Documents/Development/keys/gogasca-dev.json var.project_id gogasca-dev Enter a value: gogasca-dev An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # google_notebooks_instance.instance will be created + resource “google_notebooks_instance” “instance” { + create_time = (known after apply) + id = (known after apply) + install_gpu_driver = true + location = “us-west1-b” + machine_type = “n1-standard-1” + name = (known after apply) + network = (known after apply) + project = (known after apply) + proxy_uri = (known after apply) + service_account = (known after apply) + state = (known after apply) + subnet = (known after apply) + update_time = (known after apply) + accelerator_config { + core_count = 1 + type = “NVIDIA_TESLA_T4” } + vm_image { + image_family = “tf-latest-gpu” + project = “deeplearning-platform-release” } } # random_id.instance_id will be created + resource “random_id” “instance_id” { + b64 = (known after apply) + b64_std = (known after apply) + b64_url = (known after apply) + byte_length = 8 + dec = (known after apply) + hex = (known after apply) + id = (known after apply) } Plan: 2 to add, 0 to change, 0 to destroy. Do you want to perform these actions? Terraform will perform the actions described above. Only ‘yes’ will be accepted to approve. Enter a value: yes random_id.instance_id: Creating… random_id.instance_id: Creation complete after 0s [id=t8Ur0z6OpLE] google_notebooks_instance.instance: Creating… google_notebooks_instance.instance: Still creating… [10s elapsed] google_notebooks_instance.instance: Still creating… [20s elapsed] google_notebooks_instance.instance: Still creating… [30s elapsed] google_notebooks_instance.instance: Still creating… [40s elapsed] google_notebooks_instance.instance: Still creating… [50s elapsed] google_notebooks_instance.instance: Still creating… [1m0s elapsed] google_notebooks_instance.instance: Still creating… [1m10s elapsed] google_notebooks_instance.instance: Still creating… [1m20s elapsed] google_notebooks_instance.instance: Still creating… [1m30s elapsed] google_notebooks_instance.instance: Still creating… [1m40s elapsed] google_notebooks_instance.instance: Still creating… [1m50s elapsed] google_notebooks_instance.instance: Still creating… [2m0s elapsed] google_notebooks_instance.instance: Still creating… [2m10s elapsed] google_notebooks_instance.instance: Still creating… [2m20s elapsed] google_notebooks_instance.instance: Still creating… [2m30s elapsed] google_notebooks_instance.instance: Creation complete after 2m34s [id=projects/gogasca-dev/locations/us-west1-b/instances/nb-b7c52bd33e8ea4b1]
Экземпляр будет создан в разделе «Блокноты» в Google Cloud Console.
Документация Terraform здесь