0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Vultr APIでインスタンスを作成する

Last updated at Posted at 2025-08-06

以下の記事でインスタンスを作成するための材料が揃いましたので、今回はVultr APIを使ってインスタンスを作成してみます。


Vultr API」のドキュメントで「Instances」の「Create Instance」を参照すると、「/v2/instances」でインスタンスの作成ができるようです。

image.png


発行済のAPIキーを環境変数「VULTR_API_KEY」に格納します。

$ export VULTR_API_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

ドキュメント内の「Copy」ボタンをクリックしてターミナルに貼り付けて、 jq コマンドで整形するようにして実行します。

$ curl "https://api.vultr.com/v2/instances" \
  -s \
  -X POST \
  -H "Authorization: Bearer ${VULTR_API_KEY}" \
  -H "Content-Type: application/json" \
  --data '{
    "region" : "nrt",
    "plan" : "vc2-1c-1gb",
    "enable_ipv6": false,
    "disable_public_ipv4": false,
    "label" : "My First Instance",
    "sshkey_id" : [
      "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
    ],
    "os_id" : 2284,
    "hostname": "myfirstinstance",
    "firewall_group_id" : "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
  }' | jq .
{
  "instance": {
    "id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    "os": "Ubuntu 24.04 LTS x64",
    "ram": 1024,
    "disk": 0,
    "main_ip": "0.0.0.0",
    "vcpu_count": 1,
    "region": "nrt",
    "plan": "vc2-1c-1gb",
    "date_created": "2025-08-05T23:31:05+00:00",
    "status": "pending",
    "allowed_bandwidth": 1,
    "netmask_v4": "",
    "gateway_v4": "0.0.0.0",
    "power_status": "running",
    "server_status": "none",
    "v6_network": "",
    "v6_main_ip": "",
    "v6_network_size": 0,
    "label": "My First Instance",
    "internal_ip": "",
    "kvm": "",
    "hostname": "myfirstinstance",
    "tag": "",
    "tags": [],
    "os_id": 2284,
    "app_id": 0,
    "image_id": "",
    "firewall_group_id": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
    "features": [],
    "user_scheme": "root",
    "pending_charges": 0,
    "default_password": "XXXXXXXXXXXXXXXX"
  }
}

Vultrのページにログインした状態で、左側のメニューから「Dashboard」>「Compute」をクリックします。

image.png


「Cloud Compute」の画面に先ほど作成した「My First Instance」が表示されています。

Screenshot from 2025-08-06 09-09-40.png


「My First Instance」をクリックすると詳細画面が表示されます。

Screenshot from 2025-08-06 09-11-46.png


詳細画面内の「IP Address」の欄に、このインスタンスに割り当てられたIPアドレスが表示されていますので、これを元にSSHで接続を試してみると、無事に接続できました。

$ ssh root@XXX.XXX.XXX.XXX -i ~/.ssh/vultr 
The authenticity of host 'XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX)' can't be established.
ED25519 key fingerprint is SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'XXX.XXX.XXX.XXX' (ED25519) to the list of known hosts.
Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.8.0-60-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

 System information as of Tue Aug  5 11:33:13 PM UTC 2025

  System load:  0.56               Processes:               147
  Usage of /:   26.0% of 22.88GB   Users logged in:         0
  Memory usage: 20%                IPv4 address for enp1s0: XXX.XXX.XXX.XXX
  Swap usage:   0%


Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status


The list of available updates is more than a week old.
To check for new updates run: sudo apt update


The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

root@myfirstinstance:~#

SSH接続時の画面上にも表示されていますが、念の為、OSのバージョンが指定した通り「Ubuntu 24.04 LTS」になっているかを確認します。

root@myfirstinstance:~# cat /etc/os-release 
PRETTY_NAME="Ubuntu 24.04.2 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.2 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo

すべて異なるクラウド事業者の回線から ping を実行してみた結果。

「東京」(その①)にリージョンがあるクラウド事業者の仮想マシンから ping を実行した結果。

# ping -c 5 XXX.XXX.XXX.XXX
PING XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX) 56(84) bytes of data.
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=1 ttl=52 time=0.640 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=2 ttl=52 time=0.680 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=3 ttl=52 time=0.644 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=4 ttl=52 time=0.633 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=5 ttl=52 time=0.615 ms

--- XXX.XXX.XXX.XXX ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4134ms
rtt min/avg/max/mdev = 0.615/0.642/0.680/0.021 ms

「東京」(その②)にリージョンがあるクラウド事業者の仮想マシンから ping を実行した結果。

# ping -c 5 XXX.XXX.XXX.XXX
PING XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX) 56(84) bytes of data.
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=1 ttl=56 time=1.87 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=2 ttl=56 time=1.71 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=3 ttl=56 time=1.68 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=4 ttl=56 time=1.69 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=5 ttl=56 time=1.71 ms

--- XXX.XXX.XXX.XXX ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4007ms
rtt min/avg/max/mdev = 1.678/1.730/1.868/0.069 ms

「大阪」にリージョンがあるクラウド事業者の仮想マシンから ping を実行した結果。

# ping -c 5 XXX.XXX.XXX.XXX
PING XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX) 56(84) bytes of data.
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=1 ttl=56 time=8.51 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=2 ttl=56 time=8.59 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=3 ttl=56 time=8.53 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=4 ttl=56 time=8.55 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=5 ttl=56 time=8.55 ms

--- XXX.XXX.XXX.XXX ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4006ms
rtt min/avg/max/mdev = 8.505/8.545/8.588/0.027 ms

「九州」にリージョンがあるクラウド事業者の仮想マシンから ping を実行した結果。

# ping -c 5 XXX.XXX.XXX.XXX
PING XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX) 56(84) bytes of data.
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=1 ttl=53 time=16.0 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=2 ttl=53 time=16.0 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=3 ttl=53 time=15.9 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=4 ttl=53 time=15.9 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=5 ttl=53 time=16.0 ms

--- XXX.XXX.XXX.XXX ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4021ms
rtt min/avg/max/mdev = 15.939/15.996/16.034/0.118 ms

「北海道」にリージョンがあるクラウド事業者の仮想マシンから ping を実行した結果。

# ping -c 5 XXX.XXX.XXX.XXX
PING XXX.XXX.XXX.XXX (XXX.XXX.XXX.XXX) 56(84) bytes of data.
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=1 ttl=54 time=18.4 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=2 ttl=54 time=18.8 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=3 ttl=54 time=17.8 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=4 ttl=54 time=17.7 ms
64 bytes from XXX.XXX.XXX.XXX: icmp_seq=5 ttl=54 time=17.8 ms

--- XXX.XXX.XXX.XXX ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4025ms
rtt min/avg/max/mdev = 17.798/18.166/18.815/0.423 ms
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?