Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bulatzamilov/a1122bea5c1c28e69ba466e0c12269a5 to your computer and use it in GitHub Desktop.
Save bulatzamilov/a1122bea5c1c28e69ba466e0c12269a5 to your computer and use it in GitHub Desktop.
1. Скачиваем скрипт и запускаем:
curl https://storage.yandexcloud.net/yandexcloud-yc/install.sh | bash
2. Инициализируем:
yc init
3. Проверяем настройки вашего профиля CLI:
yc config list
Prerequisites:
export INSTANCE=bulat_vm
1. Создадим виртуальную машину:
yc compute instance create \
--name $INSTANCE \
--hostname $INSTANCE \
--memory=4 \
--create-boot-disk image-folder-id=standard-images,image-family=ubuntu-1804,size=10GB \
--network-interface subnet-name=default-ru-central1-a,nat-ip-version=ipv4 \
--metadata serial-port-enable=1 \
--ssh-key ~/.ssh/id_rsa.pub
2. Посмотреть вывод seral port:
yc compute instance get-serial-port-output --name $INSTANCE
3. Отобразить информацию о созданной машине (нужна установленная утилита jq |sudo apt install jq|):
yc compute instance get $INSTANCE --format json | jq
4. Подключимся к машине:
ssh -i ~/.ssh/id_rsa yc-user@EXTERNAL_IP
5. Создадим еще одну машину, но уже с начальной установкой nginx (команда запускается из директории с файлом metadata.yaml):
yc compute instance create \
--name instance-example2 \
--hostname my-instance2 \
--memory=4 \
--create-boot-disk image-folder-id=standard-images,image-family=ubuntu-1804,size=20GB \
--network-interface subnet-name=default-ru-central1-a,nat-ip-version=ipv4 \
--metadata serial-port-enable=1 \
--metadata-from-file user-data=./metadata.yaml
6. Отобразим список созданных инстансов:
yc compute instance list
7. Удалим нашу ВМ:
yc compute instance delete <ИМЯ_ИНСТАНСА>
1. Создадим сервисный аккаунт:
yc iam service-account create --name service
2. Добавим роль нашему сервисному аккаунту:
yc resource-manager folder add-access-binding default \
--role editor \
--subject serviceAccount:<ID_SERVICE_ACCOUNT>
3. Создадим ключи доступа для аккаунта service:
yc iam access-key create --service-account-name service \
--description "this key for my bucket"
4. Установим AWS CLI:
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
5. Проверим версию:
aws --version
6. Сконфигурируем AWS CLI:
aws configure
7. Создать бакет:
aws --endpoint-url=https://storage.yandexcloud.net s3 mb s3://otus
8. Отобразить список созданных бакетов:
aws --endpoint-url=https://storage.yandexcloud.net s3 ls
9. Положить файл в бакет:
aws --endpoint-url=https://storage.yandexcloud.net \
s3 cp testfile.txt s3://otus/folder1/testfile.txt
10. Получить список объектов в баките:
aws --endpoint-url=https://storage.yandexcloud.net \
s3 ls --recursive s3://otus
11. Получить файл из бакета:
aws --endpoint-url=https://storage.yandexcloud.net \
s3 cp s3://otus/folder1/testfile.txt testfile.txt
12. Удалить файл в баките:
aws --endpoint-url=https://storage.yandexcloud.net \
s3 rm s3://otus/folder1/testfile.txt
13. Удалить бакет:
aws --endpoint-url=https://storage.yandexcloud.net s3 rb s3://otus
1. Запустить создание группы из файла:
yc compute instance-group create --file specification.yaml
2. Получить список целевых групп:
yc load-balancer target-group list
3. Создать балансировщик с прикрепленной целевой группой:
yc load-balancer network-load-balancer create \
--region-id ru-central1 \
--name load-balancer-for-my-service \
--listener name=my-listener,external-ip-version=ipv4,port=80 \
--target-group target-group-id=<ID_TARGET_GROUP>,healthcheck-name=http,healthcheck-interval=2s,healthcheck-timeout=1s,healthcheck-unhealthythreshold=2,healthcheck-healthythreshold=2,healthcheck-http-port=80,healthcheck-http-path=/health
4. Удалить балансировщик:
yc load-balancer network-load-balancer delete <ID_LB>
5. Удалить группу инстансов:
yc compute instance-group delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment