Hitachi

Hitachi Microservices Platform - Paxos Commit Transaction Orchestrator ユーザーズガイド


2.6.8 Alternate-Service(SQL)のKubernetesマニフェストの作成(SQL-Participant限定)

7.5.7 Alternate-Service(SQL)の要件(SQL-Participant限定)」に記載されている要件を満たすように、Alternate-Service(SQL))をデプロイするためのKubernetesマニフェストを作成してください。

Kubernetesマニフェストは、通常版とトライアル版で差異があります。トライアル版のKubernetesマニフェストを基に通常版のKubernetesマニフェストを作成する場合は、通常版の記述例に従って修正してください。

Kubernetesマニフェストの記述例を次に示します。

apiVersion: apps/v1
kind: Deployment     …1
metadata:
  name: alternate-service-sql
  namespace: my-namespace
spec:
  replicas: 1     …23
  selector:
    matchLabels:
      app.kubernetes.io/name: alternate-service-sql     …25
  template:
    metadata:
      labels:
        app.kubernetes.io/name: alternate-service-sql
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/path: '/hmppcto/metrics'     …28
        prometheus.io/port: '8080'     …12
    spec:
      serviceAccount: alternate-service-sql-service-account     …9
      securityContext:     …26
        fsGroup: 0
      imagePullSecrets:     …27
      - name: regcred
      initContainers:
      - name: dependency-checker     …2
        image: myregistry.example.com/myproject/dependency-checker:V.R.S※1
        args:
        - "30"
        - "10"
        - "10"
        - "10"
        - my-namespace/statefulsets/mediator
        - my-namespace/statefulsets/eads-server※2
        - my-namespace/statefulsets/postgresql
      containers:
      - name: alternate-service-sql     …3
        image: myregistry.example.com/myproject/alternate-service-sql:V.R.S※1
        resources:     …20
          limits:
            cpu: 2
            memory: 1Gi
          requests:
            cpu: 1
            memory: 512Mi
        ports:
        - name: http     …12
          containerPort: 8080
          protocol: TCP
        - name: ucars     …19
          containerPort: 28081
          protocol: TCP
        env:
        - name: TZ     …11
          value: Asia/Tokyo
        - name: HMPPCTO_JAVA_OPTIONS     …16
          value: -XX:+UseG1GC
        volumeMounts:
        - name: alternate-service-sql-config
          mountPath: /deployments/config
        - name: alternate-service-sql-ucars-config  …17
          mountPath: /opt/hitachi/ucars/conf
        - name: snapshot-volume  …18
          mountPath: /ucars-snapshots
        - name: eads-config     …10
          mountPath: /eads-properties
        - name: tomcat     …14
          mountPath: /deployments/tomcat
        - name: eads   …15
          mountPath: /deployments/eads-log
        livenessProbe:     …5
          exec:
            command:
            - /deployments/health_check.sh
            - "0"
            - "0"
            - "10"
            - "10"
            - "8080"
          initialDelaySeconds: 180
          periodSeconds: 30
          failureThreshold: 3
          timeoutSeconds: 10
        lifecycle:
          postStart:     …6
            exec:
              command:
              - /deployments/health_check.sh
              - "30"
              - "10"
              - "10"
              - "10"
              - "8080"
          preStop:     …7
            exec:
              command:
              - /deployments/wait_transactions.sh
              - "10"
              - "10"
              - "10"
              - "10"
              - "8080"
      - name: filebeat-sidecar     …13
        image: myregistry.example.com/myproject/filebeat:V.R.S※1
        resources:     …24
          limits:
            cpu: 1000m
            memory: 2Gi
          requests:
            cpu: 1000m
            memory: 2Gi
        args:
        - "-e"
        - "-E"
        - "http.enabled=true"
        env:     …21
        - name: HMPPCTO_POD_NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        - name: HMPPCTO_POD_NAME
          valueFrom:
            fieldRef:
              fieldPath: metadata.name
        - name: HMPPCTO_NODE_NAME
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        livenessProbe:
          exec:
            command:
              - sh
              - -c
              - |
                #!/usr/bin/env bash -e
                curl --fail 127.0.0.1:5066
          initialDelaySeconds: 10
          periodSeconds: 10
          failureThreshold: 3
          timeoutSeconds: 5
        readinessProbe:
          exec:
            command:
              - sh
              - -c
              - |
                #!/usr/bin/env bash -e
                filebeat test output
          initialDelaySeconds: 10
          periodSeconds: 10
          failureThreshold: 3
          timeoutSeconds: 5
        securityContext:
          runAsUser: 0
        volumeMounts:
          - name: beatconfig
            mountPath: /usr/share/filebeat/filebeat.yml
            readOnly: true
            subPath: filebeat.yml
          - name: tomcat     …14
            mountPath: /deployments/tomcat
          - name: eads     …15
            mountPath: /deployments/eads-log
      terminationGracePeriodSeconds: 180     …8
      volumes:
      - name: snapshot-volume     …18
        persistentVolumeClaim:
          claimName: snapshot-volume
      - name: alternate-service-sql-config
        configMap:
          name: alternate-service-sql-config
          items:
          - key: application.properties
            path: application.properties
      - name: alternate-service-sql-ucars-config …17
        configMap:
          name: alternate-service-sql-ucars-config
          items:
            - key: config.properties
              path: config.properties
      - name: eads-config     …10
        configMap:
          name: eads-config
          items:
          - key: hmp-pcto.eads-client.properties
            path: hmp-pcto.eads-client.properties
      - name: beatconfig     …13
        configMap:
          name: alternate-service-sql-filebeat-sidecar-config
      - name: tomcat     …14
      - name: eads     …15
---
apiVersion: v1
kind: Service
metadata:
  name: alternate-service-sql
  namespace: my-namespace
spec:
  type: ClusterIP
  selector:
    app.kubernetes.io/name: alternate-service-sql
  ports:
  - name: http     …12
    protocol: TCP
    port: 8080
    targetPort: http
  - name: ucars     …19
    protocol: TCP
    port: 28081
    targetPort: ucars
---
apiVersion: v1     …4
kind: ConfigMap
metadata:
  name: alternate-service-sql-config
  namespace: my-namespace
data:
  application.properties: |
    server.port=8080
    server.tomcat.accesslog.enabled=true
    server.tomcat.basedir=tomcat
    server.shutdown=graceful
    spring.lifecycle.timeout-per-shutdown-phase=20s
    jp.co.Hitachi.soft.hmppcto.learner.consensus-type=Three-Quarters
    jp.co.Hitachi.soft.hmppcto.mediator.name=mediator
    jp.co.Hitachi.soft.hmppcto.mediator.name-suffix=.mediator.my-namespace.svc.cluster.local
    jp.co.Hitachi.soft.hmppcto.mediator.size=5
    jp.co.Hitachi.soft.hmppcto.instance-id=alternate-service-sql
    jp.co.Hitachi.soft.hmppcto.client.proposer.type=SQL
    spring.datasource.type=jp.co.Hitachi.soft.hmppcto.jdbc.client.PctoDataSource
    spring.datasource.driver-class-name=jp.co.Hitachi.soft.hmppcto.jdbc.client.PctoDriver
    spring.datasource.url=pctodriver
    spring.datasource.username=dummy
    spring.datasource.password=dummy
    spring.sql.init.mode=never
    jp.co.Hitachi.soft.hmppcto.sql.pod.service-name=sp.my-namespace
    jp.co.Hitachi.soft.hmppcto.sql.jdbc.driver.path=/deployments/postgresql-42.2.22.jar
    jp.co.Hitachi.soft.hmppcto.sql.datasource.class-name=org.postgresql.xa.PGXADataSource
    jp.co.Hitachi.soft.hmppcto.sql.datasource.property.values=serverName=postgresql;portNumber=5432;databaseName=appuser1;user=appuser1;password=appuser1
    jp.co.Hitachi.soft.hmppcto.sql.pool.max-pool-size=10
    jp.co.Hitachi.soft.hmppcto.mediator.port=20551
    jp.co.Hitachi.soft.hmppcto.sql.db-type=PostgreSQL     …22
    jp.co.Hitachi.soft.hmppcto.tracing.instance-id=Alternate-Service-SQL_001
    jp.co.Hitachi.soft.hmppcto.tracing.url=http://jaeger-collector:14268/api/traces
    jp.co.Hitachi.soft.hmppcto.use-scaling=true
    jp.co.Hitachi.soft.hmppcto.set-routing=inner
---
apiVersion: v1 …17
kind: ConfigMap
metadata:
  name: alternate-service-sql-ucars-config
  namespace: my-namespace
data:
  config.properties: |
    monitor.rest.bindaddress=0.0.0.0
    monitor.rest.port=28081 …19
    snapshot.log.filepath=/ucars-snapshots/${HOSTNAME}/snapshot
    monitor.jvm.options=-Dfile.encoding=UTF-8
    healthcheck.startdelay.timeout=90000
    healthcheck.startdelay.actions.failure.retrymax=4
---
apiVersion: v1     …10
kind: ConfigMap
metadata:
  name: eads-config
  namespace: my-namespace
data:
  hmp-pcto.eads-client.properties: |
    eads.client.connect.servers=sv1,sv2,sv3
    eads.client.sv1.address=eads-service-eads-service-0.my-namespace
    eads.client.sv1.port=24600
    eads.client.sv2.address=eads-service-eads-service-1.my-namespace
    eads.client.sv2.port=24600
    eads.client.sv3.address=eads-service-eads-service-2.my-namespace
    eads.client.sv3.port=24600
    eads.client.logger.dir=eads-log
    eads.client.connectionPool.poolsize=1
---
apiVersion: v1     …9
kind: ServiceAccount
metadata:
  name: alternate-service-sql-service-account
  namespace: my-namespace
---
apiVersion: v1     …13
kind: ConfigMap
metadata:
  name: alternate-service-sql-filebeat-sidecar-config
  namespace: my-namespace
data:
  filebeat.yml: |
    filebeat.inputs:
      - type: filestream
        id: "eads"
        paths:
          - '/deployments/eads-log/eads_client_message*.log'
          - '/deployments/eads-log/maintenance/eads_client_maintenance*.log'
      - type: filestream
        id: "tomcat"
        paths:
          - '/deployments/tomcat/logs/access_log.*.log'
    processors:     …21
      - add_fields:
          target: kubernetes
          fields:
            namespace: ${HMPPCTO_POD_NAMESPACE}
            pod:
              name: ${HMPPCTO_POD_NAME}
            node:
              name: ${HMPPCTO_NODE_NAME}
    output.logstash:
      hosts: ["logstash.my-namespace.svc.cluster.local:5044"]
注※1

V.R.Sは使用するHMP-PCTOとFilebeatのバージョンに合わせて読み替えてください。

注※2

通常版の場合はmy-namespace/statefulsets/eads-serverを記載してください。トライアル版の場合はmy-namespace/deployments/ext-consを記載してください。

記述例の番号は、説明の番号と対応しています。

<説明>

この例では、各KubernetesオブジェクトのNamespace名(.metadata.namespaceフィールド)は、「my-namespace」としています。

  1. ワークロードリソースを定義します。この例では、ワークロードリソースを「Deployment」としています。

  2. 「- name: dependency-checker」の行から「- my-namespace/statefulsets/postgresql」の行で、初期化コンテナ構成にDependency-Checkerコンテナを定義します。「3.4.5 Dependency-Checkerコンテナイメージの作成(通常版限定)」で作成したコンテナイメージを指定します。

    Dependency-Checkerの対象として接続するRDBMSのKubernetesオブジェクトを指定する必要があります。

    この例では、「- my-namespace/statefulsets/postgresql」を指定しています。

  3. 「- name: alternate-service-sql」の行から「preStop」の「- "8080"」の行で、コンテナ構成にAlternate-Service(SQL)コンテナを定義します。「2.3.11 Alternate-Service(SQL)コンテナイメージの作成(SQL-Participant限定)」で作成したコンテナイメージを指定します。

  4. 「apiVersion: v1」の行から「jp.co.Hitachi.soft.hmppcto.set-routing=inner」の行で、Alternate-Service(SQL)のパラメタを、Spring Bootのコンフィグソースに設定するように定義します。この例では、必須パラメタだけ指定しています。

  5. 「livenessProbe:」の行から「timeoutSeconds: 10」の行で、コンテナライフサイクル設定のLiveness Probeを定義します。

  6. 「postStart:」の行から「- "8080"」の行で、コンテナライフサイクル設定のpostStartフックを定義します。

  7. 「preStop:」の行から「- "8080"」の行で、コンテナライフサイクル設定のpreStopフックを定義します。

  8. Podライフサイクル設定のterminationGracePeriodSecondsを定義します。

  9. 「serviceAccount: alternate-service-sql-service-account」の行、および「apiVersion: v1」の行から「kind: ServiceAccount」の「namespace: my-namespace」の行で、Podに対するロールベースアクセス制御(RBAC)に使用するServiceAccountを定義します。

  10. 「- name: eads-config」の行から「mountPath: /eads-properties」の行、「- name: eads-config」の行から「path: hmp-pcto.eads-client.properties」の行、および「apiVersion: v1」の行から「eads.client.connectionPool.poolsize=1」の行で、EADSクライアント定義のパラメタを、EADSクライアント定義ファイルのコンフィグソースに設定するように定義します。この例では、必須パラメタだけ指定しています。EADSクライアント定義ファイルのディレクトリおよび名称は「9.2.5 SQL-Participant」のパラメタjp.co.Hitachi.soft.hmppcto.external-consensus.eads.propertiesに指定した値と合わせる必要があります。

    トライアル版の場合、この定義は必要ありません。

  11. 「- name: TZ」の行から「value: Asia/Tokyo」の行で、Alternate-Service(SQL)コンテナのタイムゾーンを設定します。設定するタイムゾーンはユーザ任意です。この例では、タイムゾーンを日本標準時(Asia/Tokyo、UTC+09:00)としています。

  12. 「prometheus.io/port: '8080'」の行、「- name: http」の行から「protocol: TCP」の行、および「- name: http」の行から「targetPort: http」の行で、ユーザ責務のKubernetes アプリケーション(およびPrometheus向け)で使用する各種ポート番号をKubernetesクラスタ内で公開するように定義します。この例では、アプリケーションが使用するポートをTCPプロトコルの8080ポートとしています。

  13. このオレンジ色の背景で示す行(「- name: filebeat-sidecar」の行から「mountPath: /deployments/eads-log」の行、「- name: beatconfig」の行から「name: alternate-service-sql-filebeat-sidecar-config」の行、および「apiVersion: v1」の行から「hosts: ["logstash.my-namespace.svc.cluster.local:5044"]」の行)は、Elastic Stack、JaegerおよびPrometheusを使用してトラブルシュート情報を収集する場合だけ記述します。

    FilebeatのSidecarコンテナを定義します。 /usr/share/filebeat/filebeat.yml にFilebeatの設定ファイルをマウントします。この設定によってEADSからのログをFilebeatが取得します。なお、output.logstashフィールドのNamespace名にはLogstashアプリケーションをデプロイするNamespaceを指定します。

  14. 「- name: tomcat」の行から「mountPath: /deployments/tomcat」の行、および「- name: tomcat」の行で、Tomcatのベースディレクトリとして /deployments/tomcat をマウントします。

  15. 「- name: eads」の行から「mountPath: /deployments/eads-log」の行、および「- name: eads」の行で、EADSのログ出力ディレクトリとして/deployments/eads-logをマウントします。

  16. 「- name: HMPPCTO_JAVA_OPTIONS」の行から「value: -XX:+UseG1GC」の行で、Alternate-Service(SQL)のJavaプロセス起動時にJava VMに渡すオプションを設定します。設定するオプションはユーザ任意です(ただし、「-XX:+UseG1GC」オプションは必ず含めてください)。この例では、オプションを「-XX:+UseG1GC」だけとしています。

  17. このオレンジ色の背景で示す行(「- name: alternate-service-sql-ucars-config」の行から「mountPath: /opt/hitachi/ucars/conf」の行、「- name: alternate-service-sql-ucars-config」の行から「path: config.properties」の行、および「apiVersion: v1」の行から「healthcheck.startdelay.actions.failure.retrymax=4」の行)は、通常版(uCosminexus Application Runtime for Spring Boot導入あり)の場合だけ記述します。

    uCosminexus Application Runtime for Spring Bootの設定ファイル(config.properties)をAlternate-Service(SQL)コンテナ内にマウントします。この例では、次のパラメタを設定しています。

    • monitor.rest.bindaddress=0.0.0.0

      プロセスモニタのHTTP機能に割り当てるIPアドレスを定義します。コンテナ外部から通信を受け付けることができるようにするために、設定を行います。

    • monitor.rest.port=28081

      プロセスモニタのHTTP機能の受付ポート番号を定義します。

    • snapshot.log.filepath=/ucars-snapshots/${HOSTNAME}/snapshot

      異常検知時のスナップショットログ出力先を、永続ボリュームにマウントするパスに変更します。親ディレクトリ名に「${HOSTNAME}」を採用してコンテナごとに異なるディレクトリに出力されるようにすることで、同時刻に複数のコンテナから同じファイル名で出力することを防止できます。

      スナップショットログの収集対象を追加したい場合は、「11.6.2 情報の収集方法」を参照して設定してください。

    • monitor.jvm.options=-Dfile.encoding=UTF-8

      プロセスモニタのエンコーディングにUTF-8を設定します。

    • healthcheck.startdelay.timeout=90000

      モニタ対象プロセス(Alternate-Service(SQL))開始完了通知待ちタイムアウト時間を定義します。Alternate-Service(SQL)の起動時に、設定した時間が経過するとsnapshot.log.filepathで指定した先にスナップショットを出力します。モニタ対象プロセス開始完了通知待ちタイムアウト時間の詳細は、マニュアル「uCosminexus Application Runtime for Spring Bootユーザーズガイド」を参照してください。

    • healthcheck.startdelay.actions.failure.retrymax=4

      モニタ対象プロセス(Alternate-Service(SQL))開始完了通知待ちタイムアウトが発生した場合に、モニタ対象プロセス開始完了待ちをリトライする最大回数を定義します。最大リトライ回数を超えると、デフォルトの設定ではモニタ対象プロセスを停止します。モニタ対象プロセス開始完了待ちリトライ回数の詳細は、マニュアル「uCosminexus Application Runtime for Spring Bootユーザーズガイド」を参照してください。

      モニタ対象プロセス開始完了通知待ちタイムアウトの合計時間(下記のA)とAlternate-Service(SQL)の開始に掛かる時間(下記のB、およびC)の関係を、「A>B>C」にしてください。

      A:モニタ対象プロセス開始完了通知待ちタイムアウトの合計時間

      healthcheck.startdelay.timeoutに指定した値×(healthcheck.startdelay.actions.failure.retrymaxに指定した値+1)

      B:postStartフックに指定するトランザクションヘルスチェックスクリプト(health_check.sh)の合計時間

      リトライ回数×リトライ間隔秒数

      C:コネクションプールの初期化で、DBとのコネクションの取得に失敗した場合に行うリトライの合計時間

      sql.pool.connection-retry-interval-in-secondsに指定した値×sql.pool.connection-retry-limitに指定した値

      AをBよりも大きな値にするのは、モニタ対象プロセス開始完了通知待ちタイムアウトによるプロセス停止が、postStartフックに指定するトランザクションヘルスチェックスクリプトによるAlternate-Service(SQL)の開始完了待ちを中止することを防ぐためです。

      BをCよりも大きな値とするのは、postStartフックに指定するトランザクションヘルスチェックスクリプトのタイムアウトによるAlternate-Service(SQL)の停止が、Alternate-Service(SQL)のコネクション接続処理を中止することを防ぐためです。

      この記述例では、Alternate-Service(SQL)の開始に掛かる時間(300秒)の間に、スナップショットを複数回(3回)出力するように設定しています。

  18. このオレンジ色の背景で示す行(「- name: snapshot-volume」の行から「mountPath: /ucars-snapshots」の行、および「- name: snapshot-volume」の行から「claimName: snapshot-volume」の行)は、通常版(uCosminexus Application Runtime for Spring Boot導入あり)の場合だけ記述します。

    uCosminexus Application Runtime for Spring Bootスナップショットログの永続ボリュームをAlternate-Service(SQL)コンテナ内にマウントします。.spec.template.spec.volumes[].persistentVolumeClaim.claimNameフィールドには、「2.6.11 uCosminexus Application Runtime for Spring Bootスナップショットログの永続ボリュームおよび永続ボリューム要求のKubernetesマニフェストの作成(通常版限定)」で作成するuCosminexus Application Runtime for Spring BootスナップショットログのPersistentVolumeClaimリソースの名称(.metadata.nameフィールドに指定した値)を設定してください。この例では、PersistentVolumeClaimリソースの名称を「snapshot-volume」としています。

  19. このオレンジ色の背景で示す行(「- name: ucars」の行から「protocol: TCP」の行、「- name: ucars」の行から「targetPort: ucars」の行、および「monitor.rest.port=28081」の行)は、通常版(uCosminexus Application Runtime for Spring Boot導入あり)の場合だけ記述します。

    uCosminexus Application Runtime for Spring Bootのスナップショットログの手動取得のため、HTTP機能として公開する受付ポート番号を定義します。

  20. 「resources:」の行から「memory: 512Mi」の行で、Alternate-Service(SQL)コンテナのリソースを設定します。実稼働を通して、環境に合わせた設定を実施してください。

    オートスケールのメトリクスの監視にMetrics Serverを使用する場合は必ず指定してください。

  21. 「env:」の行から「fieldPath: spec.nodeName」の行、および「processors:」の行から「name: ${HMPPCTO_NODE_NAME}」の行で、Kibanaなどの可視化ツールで検索する際、条件として使用するフィールドを付与するために環境変数を設定します。また、環境変数を使用してフィールドを付与する設定をConfigMapに記載します。

  22. Alternate-Service(SQL)が接続するRDBMSを指定します。PostgreSQLを指定する場合、「9.4.1 PostgreSQL(SQL-Participant限定)」のパラメタも確認してください。

  23. オートスケールを使用しない場合だけ、replicasを設定します。

  24. 「resources:」の行から「requests:」の「memory: 2Gi」の行で、Filebeatコンテナのリソースを設定します。実稼働を通して、環境に合わせた設定を実施してください。

    オートスケールのメトリクスの監視にMetrics Serverを使用する場合は必ず指定してください。

  25. 「app.kubernetes.io/name」を必ず指定してください。

    「app.kubernetes.io/name」は、ほかのKubernetesアプリケーションに設定した値と異なる値を設定してください。

    16バイト以内の文字列を指定してください。

    Blue/Greenデプロイメントを実施する場合は、BlueとGreenの「app.kubernetes.io/name」には同一の値を設定してください。

  26. このオレンジ色の背景で示す行は、Google Cloud Platform環境の場合だけ記述します。securityContextを設定します。fsGroupにはコンテナ実行グループと同等の設定をしてください。

  27. このオレンジ色の背景で示す行は、コンテナイメージをPullする際に資格情報が必要な場合に記述します。Red Hat OpenShift Container Platform環境で資格情報が不要な場合はimagePullSecrets: []を指定してください。

  28. この記述例では、コンテキストパスを設定していない場合の「prometheus.io/path」の例を記載しています。

    コンテキストパスを設定する場合は、パスを次のように修正してください。

    /<コンテキストパス>/hmppcto/metrics
重要

Kubernetesマニフェスト作成時の注意事項

  • Kubernetesマニフェストは、行頭のインデント(文字の開始位置)が厳密に評価されます。注意して作成してください。

  • Alternate-Service(SQL)を構成するPodを定義したKubernetesのServiceのService名とNamespace名の長さの合計は、40バイト以下としてください。