レプリケートされていない環境でのレプリカ数の変更

レプリケートされない環境でデータベースの数を増減する必要がある場合があります。たとえば、休暇で購入がピークとなるシーズン中にリソースを増やし、後でリソースを減らす場合があります。これを行うには、TimesTenClassicオブジェクトのreplicasの数を変更します。

レプリカの数を増やすと、Kubernetesは新しいポッドにTimesTenをプロビジョニングします。

レプリカの数を減らす場合:
  • Kubernetesは、関連するポッドを削除します。

  • TimesTenオペレータでは、PVCを削除しません。

例をステップごとに見てみましょう。この例では、TimesTenClassicオブジェクトがネームスペースにデプロイされます。replicasの数は3です。この例では、レプリカの数を1に減らしてから、レプリカの数を3に戻す方法を示します。

  1. TimesTenClassicオブジェクトがネームスペースにデプロイされていることを確認します。
    kubectl get ttc

    出力は、次のようになります。

    NAME          STATE              ACTIVE   AGE
    norepsample   AllReplicasReady   N/A      17m

    norepsample TimesTenClassicオブジェクトがデプロイされており、AllReplicasReady状態です。すべてのレプリカが使用可能で、実行中であり、データベースが正常に機能しています。

  2. レプリカの数を確認します。
    kubectl describe ttc norepsample | grep 'Replicas'

    出力は、次のようになります。

        Replicas:                   3

    レプリカの数は3です。

  3. ポッドの数を確認します。
    kubectl get pods

    出力は次のようになります

    NAME                                 READY   STATUS    RESTARTS   AGE
    norepsample-0                        3/3     Running   0          18m
    norepsample-1                        3/3     Running   0          18m
    norepsample-2                        3/3     Running   0          18m
    ...

    レプリカの数に対応する3つのポッドが実行されています。各レプリカには、TimesTenデータベースが含まれています。

  4. データベースにデータを挿入します。
    1. norepsample-0ポッドで実行されているデータベース:
      kubectl exec -it norepsample-0 -c tt -- /bin/bash
      [timesten@norepsample-0 ~]$ ttIsql norepsample
      
      Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
      Type ? or "help" for help, type "exit" to quit ttIsql.
      
      
      
      connect "DSN=norepsample";
      Connection successful: DSN=norepsample;UID=timesten;DataStore=/tt/home/timesten/datastore/norepsample;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;AutoCreate=0;PermSize=200;DDLReplicationLevel=3;ForceDisconnectEnabled=1;
      (Default setting AutoCommit=1)
      Command> CREATE TABLE testdata (col1 TT_INTEGER);
      Command> INSERT INTO testdata values (0);
      1 row inserted.
      Command> SELECT * FROM testdata;
      < 0 >
      1 row found.
      Command> exit
      Disconnecting...
      Done.
      [timesten@norepsample-0 ~]$ exit
      exit

      testdata表には1つの行があり、col1の値は0です。

    2. norepsample-1ポッドで実行されているデータベース:
      kubectl exec -it norepsample-1 -c tt -- /bin/bash
      [timesten@norepsample-0 ~]$ ttIsql norepsample
      
      Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
      Type ? or "help" for help, type "exit" to quit ttIsql.
      
      
      
      connect "DSN=norepsample";
      Connection successful: DSN=norepsample;UID=timesten;DataStore=/tt/home/timesten/datastore/norepsample;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;AutoCreate=0;PermSize=200;DDLReplicationLevel=3;ForceDisconnectEnabled=1;
      (Default setting AutoCommit=1)
      Command> CREATE TABLE testdata (col1 TT_INTEGER);
      Command> INSERT INTO testdata values (1);
      1 row inserted.
      Command> SELECT * FROM testdata;
      < 1 >
      1 row found.
      Command> exit
      Disconnecting...
      Done.
      [timesten@norepsample-1 ~]$ exit
      exit

      testdata表には1つの行があり、col1の値は1です。

    3. norepsample-2ポッドで実行されているデータベース:
      kubectl exec -it norepsample-2 -c tt -- /bin/bash
      [timesten@norepsample-0 ~]$ ttIsql norepsample
      
      Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
      Type ? or "help" for help, type "exit" to quit ttIsql.
      
      
      
      connect "DSN=norepsample";
      Connection successful: DSN=norepsample;UID=timesten;DataStore=/tt/home/timesten/datastore/norepsample;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;AutoCreate=0;PermSize=200;DDLReplicationLevel=3;ForceDisconnectEnabled=1;
      (Default setting AutoCommit=1)
      Command> CREATE TABLE testdata (col1 TT_INTEGER);
      Command> INSERT INTO testdata values (2);
      1 row inserted.
      Command> SELECT * FROM testdata;
      < 2 >
      1 row found.
      Command> exit
      Disconnecting...
      Done.
      [timesten@norepsample-2 ~]$ exit
      exit

      testdata表には1つの行があり、col1の値は2です。

  5. レプリカの数を減らします。
    1. norepsample TimesTenClassicオブジェクトを編集し、replicas1に変更します。
      kubectl edit ttc norepsample
      # Please edit the object below. Lines beginning with a '#' will be ignored,
      # and an empty file will abort the edit. If an error occurs while saving this file will be
      # reopened with the relevant failures.
      #
      apiVersion: timesten.oracle.com/v3
      kind: TimesTenClassic
      ...
      spec:
        ttspec:
      ...
          replicas: 1
      ...
    2. 編集内容を保存します。
      出力は、次のようになります。
      timestenclassic.timesten.oracle.com/norepsample edited
  6. TimesTenClassicオブジェクトがAllReplicasReady状態であることを確認します。
    kubectl get ttc

    出力は、次のようになります。

    NAME          STATE              ACTIVE   AGE
    norepsample   AllReplicasReady   N/A      63m
  7. ポッドの数を確認します。
    kubectl get pods

    出力は、次のようになります。

    NAME                                 READY   STATUS    RESTARTS   AGE
    norepsample-0                        3/3     Running   0          65m
    ...

    1つのポッドがあります。1つのTimesTenデータベースがそのポッドで実行されています。

  8. PVCの数を確認します。
    kubectl get pvc

    出力は、次のようになります。

    
    NAME                          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    tt-persistent-norepsample-0   Bound    csi-836f3962-cbfa-4f7d-9271-6393167b00bd   50Gi       RWO            oci-bv         67m
    tt-persistent-norepsample-1   Bound    csi-b2bfa486-6d09-463f-a8a3-25a760d1449d   50Gi       RWO            oci-bv         67m
    tt-persistent-norepsample-2   Bound    csi-820a206b-1662-4c24-821c-a947572b618a   50Gi       RWO            oci-bv         67m
    

    3つのPVCがあります。レプリカの数を変更しても、TimesTenオペレータではTimesTenClassicオブジェクトに関連付けられているPVCを削除しません。

  9. レプリカの数を増やします。
    1. norepsample TimesTenClassicオブジェクトを編集し、replicas3に変更します。
      kubectl edit ttc norepsample
      # Please edit the object below. Lines beginning with a '#' will be ignored,
      # and an empty file will abort the edit. If an error occurs while saving this file will be
      # reopened with the relevant failures.
      #
      apiVersion: timesten.oracle.com/v3
      kind: TimesTenClassic
      ...
      spec:
        ttspec:
      ...
          replicas: 3
      ...
    2. 編集内容を保存します。
      出力は、次のようになります。
      timestenclassic.timesten.oracle.com/norepsample edited
  10. TimesTenClassicオブジェクトがAllReplicasReady状態であることを確認します。
    kubectl get ttc

    出力は、次のようになります。

    NAME          STATE              ACTIVE   AGE
    norepsample   AllReplicasReady   N/A      76m
  11. ポッドの数を確認します。
    kubectl get pods

    出力は、次のようになります。

    NAME                                 READY   STATUS    RESTARTS   AGE
    norepsample-0                        3/3     Running   0          77m
    norepsample-1                        3/3     Running   0          4m
    norepsample-2                        3/3     Running   0          4m

    3つのポッドがあります。各ポッドでは、TimesTenデータベースが実行されています。

  12. PVCの数を確認します。
    kubectl get pvc

    出力は、次のようになります。

    NAME                          STATUS   VOLUME                                     CAPACITY   ACCESS MODES   STORAGECLASS   AGE
    tt-persistent-norepsample-0   Bound    csi-836f3962-cbfa-4f7d-9271-6393167b00bd   50Gi       RWO            oci-bv         79m
    tt-persistent-norepsample-1   Bound    csi-b2bfa486-6d09-463f-a8a3-25a760d1449d   50Gi       RWO            oci-bv         79m
    tt-persistent-norepsample-2   Bound    csi-820a206b-1662-4c24-821c-a947572b618a   50Gi       RWO            oci-bv         79m

    3つのTimesTenデータベースに関連付けられた3つのPVCがあります。

  13. データベース内のデータを検証します。
    1. norepsample-0ポッドで実行されているデータベース:
      kubectl exec -it norepsample-0 -c tt -- /bin/bash
      [timesten@norepsample-0 ~]$ ttIsql norepsample
      
      Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
      Type ? or "help" for help, type "exit" to quit ttIsql.
      
      
      
      connect "DSN=norepsample";
      Connection successful: DSN=norepsample;UID=timesten;DataStore=/tt/home/timesten/datastore/norepsample;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;AutoCreate=0;PermSize=200;DDLReplicationLevel=3;ForceDisconnectEnabled=1;
      (Default setting AutoCommit=1)
      Command> tables;
        TIMESTEN.TESTDATA
      1 table found.
      Command> SELECT * FROM testdata;
      < 0 >
      1 row found.
      

      レプリカの数を減らしたときにこのポッドは削除されなかったため、データベースのデータは変更されていません。

    2. norepsample-1ポッドで実行されているデータベース:
      kubectl exec -it norepsample-1 -c tt -- /bin/bash
      [timesten@norepsample-1 ~]$ ttIsql norepsample
      
      Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
      Type ? or "help" for help, type "exit" to quit ttIsql.
      
      
      
      connect "DSN=norepsample";
      Connection successful: DSN=norepsample;UID=timesten;DataStore=/tt/home/timesten/datastore/norepsample;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;AutoCreate=0;PermSize=200;DDLReplicationLevel=3;ForceDisconnectEnabled=1;
      (Default setting AutoCommit=1)
      Command> tables;
      0 tables found.
      Command> exit
      Disconnecting...
      Done.
      [timesten@norepsample-1 ~]$ exit
      exit

      TimesTenオペレータは、norepsample-1ポッドのTimesTenを正しくプロビジョニングし、元のデータベースを正しく上書きしました。

    3. norepsample-2ポッドで実行されているデータベース:
      kubectl exec -it norepsample-2 -c tt -- /bin/bash
      [timesten@norepsample-2 ~]$ ttIsql norepsample
      
      Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
      Type ? or "help" for help, type "exit" to quit ttIsql.
      
      
      
      connect "DSN=norepsample";
      Connection successful: DSN=norepsample;UID=timesten;DataStore=/tt/home/timesten/datastore/norepsample;DatabaseCharacterSet=AL32UTF8;ConnectionCharacterSet=US7ASCII;AutoCreate=0;PermSize=200;DDLReplicationLevel=3;ForceDisconnectEnabled=1;
      (Default setting AutoCommit=1)
      Command> tables;
      0 tables found.
      Command> exit
      Disconnecting...
      Done.
      [timesten@norepsample-2 ~]$ exit
      exit

      TimesTenオペレータは、norepsample-2ポッドのTimesTenを正しくプロビジョニングし、元のデータベースを正しく上書きしました。

おめでとうございます。レプリケートされていない環境で、TimesTenClassicオブジェクトのレプリカの数が正常に変更されました。