4
0

IBM Cloud Databases新モデル:APIでのリソース変更方法 (PostgresSQLを例にご紹介)

Last updated at Posted at 2024-07-12

0. はじめに

IBM Cloud Databases(ICD)について、モデルチェンジが発表されました。
・旧モデル:Multi-tenant >>> 新モデル:Shared Compute
・旧モデル:Dediacted >>> 新モデル:Isolated Compute

※具体的な移行スケジュールについてはこちらに記載されています。

現在(2024年7月時点)、新たにIBM Cloudポータル上のUIでIBM Cloud Databasesを作成すると新モデルが適用されます。
しかし、新モデルのIBM Cloud Databasesのリソース変更を行いたい場合、現時点ではポータル上のUIでは行えないため、CLI・API・Terraformのいずれかの方法にて実施する必要があります。

スクリーンショット 2024-07-08 11.21.44.png

そこで本記事では、"API"を利用したリソースの変更方法をご紹介します。
(参考リンク)

リソース変更可能範囲(Postgresの場合)と注意点

<アロケーションの制約>
「2core以下は1:8」

<リソース変更可能範囲(ドキュメント情報)>
・メモリ:最小4GB、最大112GB (member=ノードあたり)
・CPU:最小0.5CPU、最大28CPU (member=ノードあたり)

※リソース変更可能範囲はデータベースにより異なるため、他データベースについては公式ドキュメントをご確認ください。

<注意>
現在(2024年7月時点)、APIによるCPUリソース変更に関して下記のバグが発生しています。
・バグ① 本来0CPU(ノードあたり)は設定できないはずだが、設定できてしまう
・バグ② 本来最小0.5CPUに変更できるはずだが、最小1CPU(ノードあたり)までにしか変更できない
・バグ② 本来2CPU以下(ノードあたり)を構成する場合は、CPU:Memory=1:8を構成する必要があるが、1:4の値も構成できてしまう
⇒上記バグは今後修正される予定だそうです

1. APIを利用したICDリソース変更方法

今回は、PostgresSQLを例としてご紹介します。
(基本的な操作はどのICDのデータベースでも同じですが、最小構成を含むリソース構成がデータベースごとに異なることがございますので、詳細は公式ドキュメントをご参照ください。)

<手順概要>

以下の手順でリソース変更を行います。

① I AM tokenを取得・・・認証情報を取得します
② デプロイのグループ一覧を取得・・・③で必要な情報を取得します
③ リソース変更・・・リソース変更のAPIを実行します
④ デプロイ情報の取得・・・API実行が上手くいったか確認します

<手順概要>

① I AM tokenを取得

API keyを使用し、I AM token(=認証に必要なトークン)を取得します。

※API keyを取得されていない場合は、こちらの公式docやこちらのQiita記事をご参考に取得いただけますようお願いいたします。
※API keyとtokenの意味については、こちらの記事がわかりやすかったです。(I AM tokenは記事内の「アクセストークン」に該当します。)

IN.json
curl -X POST \
https://iam.cloud.ibm.com/identity/token \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json" \
  -d "grant_type=urn%3Aibm%3Aparams%3Aoauth%3Agrant-type%3Aapikey&apikey={apikey}"
OUT.json
{
    "access_token": "{token}",
    "refresh_token": "not_supported",
    "ims_user_id": xxxxxxxx,
    "token_type": "Bearer",
    "expires_in": 3600,
    "expiration": 1718804839,
    "scope": "ibm openid"
}%

② デプロイのグループ一覧を取得

手順③で必要なパラメータ{group_id}を取得します。

※deploymentsのパラメータ{id}はUI上のOverview>CRN (deployment ID)でも取得できます。
スクリーンショット 2024-07-09 17.43.56.png
※deployments{id}について、/%2Fにエンコードする必要があるためご注意ください。(参考リンク)

手順①で取得した{token}を指定します。

IN.
curl -X GET https://api.{region}.databases.cloud.ibm.com/v5/ibm/deployments/{id}/groups -H 'Authorization: Bearer {token}'
OUT.json
{
    "groups": [
        {
            "id": "member",
            "count": 2,
            "members": {
                "units": "count",
                "allocation_count": 2,
                "minimum_count": 2,
                "maximum_count": 20,
                "step_size_count": 1,
                "is_adjustable": true,
                "is_optional": false,
                "can_scale_down": false
            },
            "memory": {
                "units": "mb",
                "allocation_mb": 8192,
                "minimum_mb": 8192,
                "maximum_mb": 229376,
                "step_size_mb": 256,
                "is_adjustable": true,
                "is_optional": false,
                "can_scale_down": true,
                "cpu_enforcement_ratio_ceiling_mb": 32768,
                "cpu_enforcement_ratio_mb": 8192
            },
            "disk": {
                "units": "mb",
                "allocation_mb": 10240,
                "minimum_mb": 10240,
                "maximum_mb": 8388608,
                "step_size_mb": 2048,
                "is_adjustable": true,
                "is_optional": false,
                "can_scale_down": false,
                "storage_class": {
                    "id": "icd-block-gold",
                    "iops_per_allocation_gb": 10
                }
            },
            "cpu": {
                "units": "count",
                "allocation_count": 4,
                "minimum_count": 0,
                "maximum_count": 56,
                "step_size_count": 2,
                "is_adjustable": true,
                "is_optional": true,
                "can_scale_down": true
            },
            "host_flavor": {
                "id": "multitenant",
                "name": "",
                "hosting_size": ""
            }
        }
    ]
}%

取得した"id"の値(ここでは"member")が手順③で指定するパラメータ{group_id}です。
ついでに現在のリソース構成も確認できます。

③ リソース変更

"member"(=ノード)あたり、1CPU x 8GBの構成に変更したい場合、以下のように指定します。

※PostgresSQLでは、デフォルトで 2 members(ノード)が割り当てられています。
※APIのパラメータでは 全member(ノード) の合計値を指定する必要があるため、2 CPU x 16384 MBを指定します。
※CPU: 2 cpusの倍数、Memory: 256 megabytesの倍数で指定する必要があります。

IN.
curl -X PATCH  https://api.{region}.databases.cloud.ibm.com/v5/ibm/deployments/{id}/groups/{group_id}  -H 'Authorization: Bearer {token}'  -H 'Content-Type: application/json'  -d '{"memory": {"allocation_mb": 8192}, "cpu": {"allocation_count": 1}}' \
OUT.json
{
    "task": {
        "id": "crn:v1:bluemix:public:databases-for-postgresql:{region}:{id}:task:{task_id}",
        "description": "Scaling instance",
        "status": "running",
        "deployment_id": "crn:v1:bluemix:public:databases-for-postgresql:{region}:{id}",
        "progress_percent": 0,
        "created_at": "2024-07-02T09:00:32.000Z"
    }
}%

④ デプロイ情報の取得

最後に、リソース変更後の構成情報を取得します。

手順②と同じコマンドです。

IN.
curl -X GET   https://api.{region}.databases.cloud.ibm.com/v5/ibm/deployments/crn:v1:bluemix:public:databases-for-postgresql:{region}:{id}/groups -H 'Authorization: Bearer {token}'
OUT.json
{
    "groups": [
        {
            "id": "member",
            "count": 2,
            "members": {
                "units": "count",
                "allocation_count": 2,
                "minimum_count": 2,
                "maximum_count": 20,
                "step_size_count": 1,
                "is_adjustable": true,
                "is_optional": false,
                "can_scale_down": false
            },
            "memory": {
                "units": "mb",
                "allocation_mb": 16384,
                "minimum_mb": 8192,
                "maximum_mb": 229376,
                "step_size_mb": 256,
                "is_adjustable": true,
                "is_optional": false,
                "can_scale_down": true,
                "cpu_enforcement_ratio_ceiling_mb": 32768,
                "cpu_enforcement_ratio_mb": 8192
            },
            "disk": {
                "units": "mb",
                "allocation_mb": 10240,
                "minimum_mb": 10240,
                "maximum_mb": 8388608,
                "step_size_mb": 2048,
                "is_adjustable": true,
                "is_optional": false,
                "can_scale_down": false,
                "storage_class": {
                    "id": "icd-block-gold",
                    "iops_per_allocation_gb": 10
                }
            },
            "cpu": {
                "units": "count",
                "allocation_count": 2,
                "minimum_count": 0,
                "maximum_count": 56,
                "step_size_count": 2,
                "is_adjustable": true,
                "is_optional": true,
                "can_scale_down": true
            },
            "host_flavor": {
                "id": "multitenant",
                "name": "",
                "hosting_size": ""
            }
        }
    ]
}%

指定した通りにリソース変更できたことがわかります。(下記の該当箇所を探します。)

Member(=ノード):
“members”{“units”:“count”,“allocation_count”:2
→Memberの割り当て(“allocation_count”)は2です。

CPU:
“cpu”{“units”:“count”,“allocation_count”:2,
→CPUの割り当て(“allocation_count”)は2です。

Memory:
“memory”{“units”:“mb”,“allocation_mb”:16384,
→Memoryの割り当て(“allocation_mb”)は16384です。

出力結果における"memory"の注意点
・結果として出力されるメモリ("memory")のリソースの単位は"MB"です。("GB"ではありません。)
・結果として出力されるメモリ("memory")は、全member(ノード) の合計値(PostgresSQLではデフォルトで全2members(ノード))となります。

上記の例では、全 2members (2ノード) の合計値が 2CPU x 16384MB に変更されたことがわかりました。
member(=ノード)あたりの割り当ては、1CPU x 8GB (8192MB) となっています。

2. おわりに

うまくいきましたでしょうか?
本記事では、APIでのリソース変更方法についてご紹介しました。
UIでの対応が始まる前は、ぜひこちらの方法で対応いただければと思います!

4
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
4
0