{"id":18794181,"url":"https://github.com/yandex-cloud-examples/yc-load-testing-create-agent","last_synced_at":"2025-12-29T15:30:14.703Z","repository":{"id":226578293,"uuid":"769047616","full_name":"yandex-cloud-examples/yc-load-testing-create-agent","owner":"yandex-cloud-examples","description":"Создание агента для нагрузочного тестирования в сервисе Yandex Load Testing с помощью инструмента YC CLI.","archived":false,"fork":false,"pushed_at":"2024-03-13T11:45:55.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":8,"default_branch":"main","last_synced_at":"2024-12-29T15:47:04.545Z","etag":null,"topics":["bash","load-testing","load-testing-agent","yandex-cloud","yandexcloud","yc-cli"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yandex-cloud-examples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-08T08:32:06.000Z","updated_at":"2024-03-08T08:33:32.000Z","dependencies_parsed_at":"2024-03-08T11:25:26.652Z","dependency_job_id":"a8ee5678-acec-43d5-85f3-11e5bcf15ba7","html_url":"https://github.com/yandex-cloud-examples/yc-load-testing-create-agent","commit_stats":null,"previous_names":["yandex-cloud-examples/yc-load-testing-create-agent"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandex-cloud-examples%2Fyc-load-testing-create-agent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandex-cloud-examples%2Fyc-load-testing-create-agent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandex-cloud-examples%2Fyc-load-testing-create-agent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yandex-cloud-examples%2Fyc-load-testing-create-agent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yandex-cloud-examples","download_url":"https://codeload.github.com/yandex-cloud-examples/yc-load-testing-create-agent/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239718378,"owners_count":19685726,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","load-testing","load-testing-agent","yandex-cloud","yandexcloud","yc-cli"],"created_at":"2024-11-07T21:28:32.596Z","updated_at":"2025-12-29T15:30:14.657Z","avatar_url":"https://github.com/yandex-cloud-examples.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# Configure your cloud for load testing and create first agent\n\nNOTE: In the snippets below, it is assumed that folder-id setting is already set in `yc` config:\n\n```bash\nyc config set folder-id 'my_folder_id'\n```\n\nif not, you may always pass `--folder-id my_folder_id` argument to `yc` commands.\n\n## 1. Prepare infrastructure\n\nYou need to configure proper infrastructure for load testing agents and testing targets if you haven`t done it before.\n\n### 1.1. Service account\n\nFor cloud agent you will need a service account with role `loadtesting.generatorClient`. One service account may be used with multiple agents within a single folder.\n\nCreate new service account:\n\n```bash\n\n$ YC_LT_SERVICE_ACCOUNT_ID=$(yc iam service-account create --name sa-loadagent --format json | jq -r \".id\")\n\n```\n\nAdd role to service account:\n\n```bash\n\n$ FOLDER_ID=$(yc config get folder-id)\n$ yc resource-manager folder add-access-binding $FOLDER_ID \\\n  --service-account-id $YC_LT_SERVICE_ACCOUNT_ID \\\n  --role loadtesting.generatorClient\n\n```\n\n### 1.2. Agent network\n\nFor load testing agents to operate, it requires to have an access to Yandex Cloud API Gateway from agent subnet.\nBy default single VPC network with subnets for each zone is present in each folder.\n\n#### Example of network configuration with NAT Gateway and route to Yandex Cloud API Gateway\n\nSee [NAT Gateway docs](https://cloud.yandex.ru/en/docs/vpc/operations/create-nat-gateway#console_1) for more details.\n\nEnsure you have a network in the folder:\n\n```bash\n\n$ YC_VPC_NETWORK_ID=$(yc vpc network list --format json | jq -r \".[0] | .id\")\n\n$ echo $YC_VPC_NETWORK_ID\nenp29occlmph********\n\n```\n\nCreate NAT Gateway and route to Internet\n\n```bash\n\n$ YC_NAT_GATEWAY_ID=$(yc vpc gateway create --name load-agents-gateway --format json | jq -r \".id\")\n\n$ yc vpc route-table create \\\n   --name=load-agents-route-table \\\n   --network-id=$YC_VPC_NETWORK_ID \\\n   --route destination=0.0.0.0/0,gateway-id=$YC_NAT_GATEWAY_ID\n\n```\n\n### 1.3. Security groups\n\nTypically, the load testing agent and test target are deployed in separate networks. If you do this, configure security groups to allow traffic from agent to target and from agents to API Gateway.\n\nCreate new security group for load testing agent:\n\n```bash\n\n$ AGENT_SG_ID=$(yc vpc security-group create --format json \\\n  --name sg-load-testing-agents \\\n  --rule \"direction=egress,protocol=tcp,v4-cidrs=[0.0.0.0/0],from-port=0,to-port=65535\" \\\n  --network-id $YC_VPC_NETWORK_ID | jq -r \".id\")\n\n```\n\nCreate new security group for test target with rule to allow all traffic from agents:\n\n```bash\n\n$ yc vpc security-group create \\\n  --name sg-load-testing-targets \\\n  --rule \"direction=ingress,protocol=any,security-group-id=$AGENT_SG_ID,from-port=0,to-port=65535\" \\\n  --network-id $YC_VPC_NETWORK_ID\n\n```\n\n## 2. Create Cloud Agent\n\nFirst you need to pick a zone where agent should be provisioned. In general, you want the same zone where your target is deployed.\n\n```bash\n\n$ LT_ZONE_ID=ru-central1-a\n\n$ yc vpc network list-subnets $YC_VPC_NETWORK_ID --format json | jq \".[] | select(.zone_id == \\\"$LT_ZONE_ID\\\") | {\\\"id\\\":.id,\\\"name\\\":.name}\"\n{\n  \"id\": \"e9bt0v**************\",\n  \"name\": \"lt-net-ru-central1-a\"\n}\n\n$ SUBNET_ZONE_A_ID=e9bt0v**************\n\n```\n\nFinally we can create new agent.\n\n```bash\n$ yc loadtesting agent create \\\n  --name my-agent \\\n  --labels origin=default,label-key=label-value \\\n  --zone $LT_ZONE_ID \\\n  --network-interface subnet-id=$SUBNET_ZONE_A_ID,security-group-ids=$AGENT_SG_ID \\\n  --cores 2 \\\n  --memory 2G \\\n  --service-account-id $YC_LT_SERVICE_ACCOUNT_ID\n```\n\nSee [agents benchmark](https://cloud.yandex.ru/en/docs/load-testing/concepts/agent#benchmark) to adjust agents CPU and RAM for your needs.\n\n\n## 3. SSH access to your agent\n\nTo access the load testing agent VM via ssh, you need a security group rule for incoming traffic on port 22:\n\n```bash\n\n# use your v4-cidrs to limit ip addresses allowed to connect\n$ yc vpc security-group update-rules $AGENT_SG_ID \\\n  --add-rule \"direction=ingress,port=22,protocol=tcp,v4-cidrs=[0.0.0.0/24]\"\n\n```\n\nAlso you need to specify your public ssh key in metadata when creating new agent:\n\n```bash\n\n$ SSH_PUB_FILE_PATH=/path/to/ssh/key.pub\n$ cat $SSH_PUB_FILE_PATH  # ensure file path is correct\n\n$ SSH_USERNAME=agent-root\n$ cat \u003e agent-metadata-user-data.yaml \u003c\u003cEOF\n#cloud-config\nssh_pwauth: 'no'\nusers:\n- groups: sudo\n  name: $SSH_USERNAME\n  shell: /bin/bash\n  ssh-authorized-keys:\n  - $(cat $SSH_PUB_FILE_PATH)\n  sudo:\n  - ALL=(ALL) NOPASSWD:ALL\nEOF\n\n\n$ yc loadtesting agent create \\\n  --name my-agent \\\n  --zone $LT_ZONE_ID \\\n  --network-interface subnet-id=$SUBNET_ZONE_A_ID,security-group-ids=$AGENT_SG_ID \\\n  --cores 2 \\\n  --memory 2G \\\n  --service-account-id $YC_LT_SERVICE_ACCOUNT_ID \\\n  --metadata-from-file user-data=agent-metadata-user-data.yaml\n\n```\n\nThe `user-data` metadata option accepts [cloud-init configs](https://cloudinit.readthedocs.io/en/latest/). Feel free to customize your agent VM with additional software.\n\nIf you don't have ssh key yet, create one:\n\n```bash\n\n$ ssh-keygen -t ed25519\n\nGenerating public/private ed25519 key pair.\nEnter file in which to save the key (/home/username/.ssh/id_ed25519): \nEnter passphrase (empty for no passphrase): \nEnter same passphrase again: \nYour identification has been saved in /home/username/.ssh/id_ed25519\nYour public key has been saved in /home/username/.ssh/id_ed25519.pub\n\n$ SSH_PUB_FILE_PATH=/home/username/.ssh/id_ed25519.pub\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyandex-cloud-examples%2Fyc-load-testing-create-agent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyandex-cloud-examples%2Fyc-load-testing-create-agent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyandex-cloud-examples%2Fyc-load-testing-create-agent/lists"}