Hitachi

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


2.5.3 Entity-ServiceのKubernetesマニフェストの作成

このKubernetesマニフェストは、サービス間を中継するサービスとしてのEntity-Serviceがある場合だけ作成します。詳細については、取扱説明書「HMP-PCTO テクニカルガイド(SQL-Participant編)」、または取扱説明書「HMP-PCTO テクニカルガイド(TCC-Participant編)」のトランザクションのモデル(その2)に関する説明を参照してください。

5.4.2 Entity-Serviceの要件」に記載されている要件を満たすように、Entity-ServiceをデプロイするためのKubernetesマニフェストを作成してください。

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

apiVersion: apps/v1     …1
kind: Deployment
metadata:
  name: entity-service
  namespace: my-namespace
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: entity-service
  template:
    metadata:
      labels:
        app.kubernetes.io/name: entity-service
    spec:
      serviceAccount: entity-service-service-account     …6
      initContainers:
      - name: dependency-checker     …2
        image: myregistry.example.com/myproject/dependency-checker:V.R.S2
        args:
        - "30"
        - "10"
        - "10"
        - "10"
        - my-namespace/statefulsets/mediator
        - my-namespace/deployments/sql-participant※1
      containers:
      - name: entity-service     …3
        image: myregistry.example.com/myproject/entity-service:V.R.S2
        resources:     …14
          limits:
            cpu: 2
            memory: 1Gi
          requests:
            cpu: 1
            memory: 512Mi
        ports:
        - name: http     …4
          containerPort: 8080
          protocol: TCP
        - name: ucars
          containerPort: 28081     …13
          protocol: TCP
        env:
        - name: TZ     …7
          value: Asia/Tokyo
        - name: HMPPCTO_JAVA_OPTIONS …10
          value: -XX:+UseG1GC
        volumeMounts:
        - name: entity-service-config     …5
          mountPath: /deployments/config
        - name: ucars-config     …11
          mountPath: /opt/hitachi/ucars/conf
        - name: snapshot-volume     …12
          mountPath: /ucars-snapshots
        - name: tomcat                …8
          mountPath: /deployments/tomcat
      - name: filebeat-sidecar
        image: myregistry.example.com/myproject/filebeat:V.R.S2
        env:     …15
        - 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
        securityContext:
          runAsUser: 0
        volumeMounts:
         - name: beatconfig            …9
           mountPath: /usr/share/filebeat/filebeat.yml
           readOnly: true
           subPath: filebeat.yml
         - name: tomcat
           mountPath: /deployments/tomcat
      volumes:
      - name: entity-service-config     …5
        configMap:
          name: entity-service-config
          items:
          - key: application.properties
            path: application.properties
      - name: ucars-config     …11
        configMap:
          name: entity-service-ucars-config
          items:
            - key: config.properties
              path: config.properties
      - name: snapshot-volume     …12
        persistentVolumeClaim:
          claimName: snapshot-volume
      - name: beatconfig  …9
        configMap:
          name: es-filebeat-sidecar-config
      - name: tomcat
---
apiVersion: v1
kind: Service
metadata:
  name: entity-service
  namespace: my-namespace
spec:
  type: ClusterIP
  selector:
    app.kubernetes.io/name: entity-service
  ports:
  - name: http     …4
    protocol: TCP
    port: 8080
    targetPort: http
  - name: grpc     …7
    protocol: TCP
    port: 20552
    targetPort: grpc
  - name: ucars
    protocol: TCP
    port: 28081     …13
    targetPort: ucars
---
apiVersion: v1     …5
kind: ConfigMap
metadata:
  name: entity-service-config
  namespace: my-namespace
data:
  application.properties: |
    server.port=8080
    server.tomcat.accesslog.enabled=true
    server.tomcat.basedir=tomcat
    jp.co.Hitachi.soft.hmppcto.client.proposer.type=SQL
    jp.co.Hitachi.soft.hmppcto.tracing.url=http://jaeger-collector:14268/api/traces
    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=http://localhost:20553
    spring.datasource.username=dummy
    spring.datasource.password=dummy
---
apiVersion: v1  …11
kind: ConfigMap
metadata:
  name: entity-service-ucars-config
  namespace: my-namespace
data:
  config.properties: |
    monitor.rest.bindaddress=0.0.0.0
    monitor.rest.port=28081     …13
    snapshot.log.filepath=/ucars-snapshots/${HOSTNAME}/snapshot
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: es-filebeat-sidecar-config
  namespace: my-namespace  …9
data: 
  filebeat.yml: |
    filebeat.inputs:
      - type: filestream
        id: "tomcat"
        paths:
          - '/deployments/tomcat/logs/access_log.*.log'
    processors:     …15
      - 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"]
---
apiVersion: v1     …6
kind: ServiceAccount
metadata:
  name: entity-service-service-account
  namespace: my-namespace
注※1

SQL-Participantを使用する場合の例を記述しています。TCC-Participantを使用する場合は次の記述に置き換えてください。

- my-namespace/deployments/tcc-participant

注※2

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

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

<説明>

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

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

  2. 初期化コンテナ構成にDependency-Checkerコンテナを定義します。「3.3.4 Dependency-Checkerコンテナイメージの作成(通常版限定)」で作成したコンテナイメージを指定します。

  3. コンテナ構成にEntity-Serviceコンテナを定義します。「2.4.6 Entity-Serviceコンテナイメージの作成」で作成したコンテナイメージを指定します。

  4. ユーザ責務のKubernetesアプリケーション(およびPrometheus向け)で使用する各種ポート番号をKubernetesクラスタ内で公開するように定義します。この例では、アプリケーションが使用するポートをTCPプロトコルの8080ポートとしています。

  5. Entity-Serviceコンテナのパラメタを、Spring Bootのコンフィグソースに設定するように定義します。この例では、必須パラメタだけ指定しています。

  6. Podに対するロールベースアクセス制御(RBAC)に使用するServiceAccountを定義します。

  7. Entity-Serviceコンテナのタイムゾーンを設定します。設定するタイムゾーンはユーザ任意です。この例では、タイムゾーンを日本標準時(Asia/Tokyo、UTC+09:00)としています。

  8. Tomcatのベースディレクトリとして /deployments/tomcat をマウントします。

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

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

  11. オレンジ色の背景で示す行は、uCosminexus Application Runtime with Java for Spring Boot導入ありの場合だけ記述します。

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

    • monitor.rest.bindaddress=0.0.0.0

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

    • monitor.rest.port=28081

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

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

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

  12. オレンジ色の背景で示す行は、uCosminexus Application Runtime with Java for Spring Boot導入ありの場合だけ記述します。

    uCosminexus Application Runtime with Java for Spring Bootスナップショットログの永続ボリュームをEntity-Serviceコンテナ内にマウントします。

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

  13. オレンジ色の背景で示す行は、uCosminexus Application Runtime with Java for Spring Boot導入ありの場合だけ記述します。

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

  14. Entity-Serviceコンテナのリソースを設定します。実稼働を通して、環境に合わせた設定を実施してください。

  15. Kibanaなどの可視化ツールで検索する際、条件として使用するフィールドを付与するために環境変数を設定します。また、環境変数を使用してフィールドを付与する設定をConfigMapに記載します。

重要

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

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