2.6.3 Relay-ServiceのKubernetesマニフェストの作成
「7.5.2 Relay-Serviceの要件」に記載されている要件を満たすように、Relay-ServiceをデプロイするためのKubernetesマニフェストを作成してください。
Kubernetesマニフェストの記述例を次に示します。
apiVersion: apps/v1
kind: Deployment …1
metadata:
name: relay-service
namespace: my-namespace
spec:
replicas: 1 …17
selector:
matchLabels:
app.kubernetes.io/name: relay-service
template:
metadata:
labels:
app.kubernetes.io/name: relay-service
annotations:
prometheus.io/scrape: 'true'
prometheus.io/path: '/hmppcto/metrics' …24
prometheus.io/port: '8080' …4
spec:
serviceAccount: relay-service-service-account …6
securityContext: …21
fsGroup: 0
imagePullSecrets: …22
- name: regcred
initContainers:
- name: dependency-checker …2
image: myregistry.example.com/myproject/dependency-checker:V.R.S※2
args:
- "30"
- "10"
- "10"
- "10"
- my-namespace/statefulsets/mediator
- my-namespace/deployments/sql-participant※1
containers:
- name: relay-service …3
image: myregistry.example.com/myproject/relay-service:V.R.S※2
resources: …14
limits:
cpu: 2
memory: 1Gi
requests:
cpu: 1
memory: 512Mi
ports:
- name: http …4
containerPort: 8080
protocol: TCP
- name: ucars …13
containerPort: 28081
protocol: TCP
env:
- name: TZ …7
value: Asia/Tokyo
- name: HMPPCTO_JAVA_OPTIONS …10
value: -XX:+UseG1GC
volumeMounts:
- name: relay-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
livenessProbe: …19
exec:
command:
- /deployments/health_check.sh
- "0"
- "0"
- "10"
- "10"
- "8080"
initialDelaySeconds: 180
periodSeconds: 30
failureThreshold: 3
timeoutSeconds: 10
lifecycle:
postStart: …20
exec:
command:
- /deployments/health_check.sh
- "30"
- "10"
- "10"
- "10"
- "8080"
preStop: …23
exec:
command:
- /bin/sh
- -c
- sleep 20
- name: filebeat-sidecar …9
image: myregistry.example.com/myproject/filebeat:V.R.S※2
resources: …18
limits:
cpu: 1000m
memory: 2Gi
requests:
cpu: 1000m
memory: 2Gi
args:
- "-e"
- "-E"
- "http.enabled=true"
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
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 …8
mountPath: /deployments/tomcat
terminationGracePeriodSeconds: 180 …16
volumes:
- name: relay-service-config …5
configMap:
name: relay-service-config
items:
- key: application.properties
path: application.properties
- name: ucars-config …11
configMap:
name: relay-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 …8
---
apiVersion: v1
kind: Service
metadata:
name: relay-service
namespace: my-namespace
spec:
type: ClusterIP
selector:
app.kubernetes.io/name: relay-service
ports:
- name: http …4
protocol: TCP
port: 8080
targetPort: http
- name: ucars …13
protocol: TCP
port: 28081
targetPort: ucars
---
apiVersion: v1 …5
kind: ConfigMap
metadata:
name: relay-service-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=140s
jp.co.Hitachi.soft.hmppcto.client.proposer.type=SQL
jp.co.Hitachi.soft.hmppcto.tracing.instance-id=Relay-Service_001
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
jp.co.Hitachi.soft.hmppcto.use-scaling=true
jp.co.Hitachi.soft.hmppcto.set-routing=inner
---
apiVersion: v1 …11
kind: ConfigMap
metadata:
name: relay-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
monitor.jvm.options=-Dfile.encoding=UTF-8
---
apiVersion: v1 …9
kind: ConfigMap
metadata:
name: es-filebeat-sidecar-config
namespace: my-namespace
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
kind: ServiceAccount …6
metadata:
name: relay-service-service-account
namespace: my-namespace
- 注※1
-
SQL-Participantを使用する場合の例を記述しています。
-
TCC-Participantを使用するときは、次の記述に置き換えてください。
- my-namespace/deployments/tcc-participant
-
TP1連携機能を使用するときは、次の記述に置き換えてください。<リリース名>は、「(15) Kubernetesアプリケーションのデプロイ」でhelmコマンドに指定するリリース名を指定してください。
- my-namespace/deployments/<リリース名>
(例)
リリース名がtp1-bridge1の場合:- my-namespace/deployments/tp1-bridge1
-
- 注※2
-
V.R.Sは使用するHMP-PCTOとFilebeatのバージョンに合わせて読み替えてください。
記述例の番号は、説明の番号と対応しています。
<説明>
この例では、各KubernetesオブジェクトのNamespace名(.metadata.namespaceフィールド)は、「my-namespace」としています。
-
ワークロードリソースを定義します。この例では、ワークロードリソースを「Deployment」としています。
-
「- name: dependency-checker」の行から「- my-namespace/deployments/sql-participant」の行で、初期化コンテナ構成にDependency-Checkerコンテナを定義します。「3.4.5 Dependency-Checkerコンテナイメージの作成(通常版限定)」で作成したコンテナイメージを指定します。
-
「- name: relay-service」の行から「- sleep 20」の行で、コンテナ構成にRelay-Serviceコンテナを定義します。「2.3.6 Relay-Serviceコンテナイメージの作成」で作成したコンテナイメージを指定します。
-
「prometheus.io/port: '8080'」の行、「- name: http」の行から「protocol: TCP」の行、および「- name: http」の行から「targetPort: http」の行で、ユーザ責務のKubernetesアプリケーション(およびPrometheus向け)で使用する各種ポート番号をKubernetesクラスタ内で公開するように定義します。この例では、アプリケーションが使用するポートをTCPプロトコルの8080ポートとしています。
-
「- name: relay-service-config」の行から「mountPath: /deployments/config」の行、「- name: relay-service-config」の行から「path: application.properties」の行、および「apiVersion: v1」の行から「jp.co.Hitachi.soft.hmppcto.set-routing=inner」の行で、Relay-Serviceコンテナのパラメタを、Spring Bootのコンフィグソースに設定するように定義します。この例では、必須パラメタだけ指定しています。
-
「serviceAccount: relay-service-service-account」の行、および「apiVersion: v1」の行から「namespace: my-namespace」の行で、Podに対するロールベースアクセス制御(RBAC)に使用するServiceAccountを定義します。
-
「- name: TZ」の行から「value: Asia/Tokyo」の行で、Relay-Serviceコンテナのタイムゾーンを設定します。設定するタイムゾーンはユーザ任意です。この例では、タイムゾーンを日本標準時(Asia/Tokyo、UTC+09:00)としています。
-
「- name: tomcat」の行から「mountPath: /deployments/tomcat」の行、および「- name: tomcat」の行で、Tomcatのベースディレクトリとして /deployments/tomcat をマウントします。
-
このオレンジ色の背景で示す行(「- name: filebeat-sidecar」の行から「mountPath: /deployments/tomcat」の行、「- name: beatconfig」の行から「name: es-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の設定ファイルをマウントし、 /deployments/tomcat にTomcatのログディレクトリをマウントします。この設定によってTomcatからのログをFilebeatが取得します。なお、output.logstashフィールドのNamespace名にはLogstashアプリケーションをデプロイするNamespaceを指定します。
-
「- name: HMPPCTO_JAVA_OPTIONS」の行から「value: -XX:+UseG1GC」の行で、Relay-ServiceのJavaプロセス起動時にJava VMに渡すオプションを設定します。設定するオプションはユーザ任意です(ただし、「-XX:+UseG1GC」オプションは必ず含めてください)。この例では、オプションを「-XX:+UseG1GC」だけとしています。
-
このオレンジ色の背景で示す行(「- name: ucars-config」の行から「mountPath: /opt/hitachi/ucars/conf」の行、「- name: ucars-config」の行から「path: config.properties」の行、および「apiVersion: v1」の行から「monitor.jvm.options=-Dfile.encoding=UTF-8」の行)は、通常版(uCosminexus Application Runtime for Spring Boot導入あり)の場合だけ記述します。
uCosminexus Application Runtime for Spring Bootの設定ファイル(config.properties)をRelay-Serviceコンテナ内にマウントします。この例では、次のパラメタを設定しています。
-
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を設定します。
-
-
このオレンジ色の背景で示す行(「- name: snapshot-volume」の行から「mountPath: /ucars-snapshots」の行、および「- name: snapshot-volume」の行から「claimName: snapshot-volume」の行)は、通常版(uCosminexus Application Runtime for Spring Boot導入あり)の場合だけ記述します。
uCosminexus Application Runtime for Spring Bootスナップショットログの永続ボリュームをRelay-Serviceコンテナ内にマウントします。
.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」としています。
-
このオレンジ色の背景で示す行(「- 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機能として公開する受付ポート番号を定義します。
-
「resources:」の行から「memory: 512Mi」の行で、Relay-Serviceコンテナのリソースを設定します。実稼働を通して、環境に合わせた設定を実施してください。
オートスケールのメトリクスの監視にMetrics Serverを使用する場合は必ず指定してください。
-
「env:」の行から「fieldPath: spec.nodeName」の行、および「processors:」の行から「name: ${HMPPCTO_NODE_NAME}」の行で、Kibanaなどの可視化ツールで検索する際、条件として使用するフィールドを付与するために環境変数を設定します。また、環境変数を使用してフィールドを付与する設定をConfigMapに記載します。
-
Podライフサイクル設定のterminationGracePeriodSecondsを定義します。
-
オートスケールを使用しない場合だけ、replicasを設定します。
-
「resources:」の行から「requests:」の「memory: 2Gi」の行で、Filebeatコンテナのリソースを設定します。実稼働を通して、環境に合わせた設定を実施してください。
オートスケールのメトリクスの監視にMetrics Serverを使用する場合は必ず指定してください。
-
「livenessProbe:」の行から「timeoutSeconds: 10」の行で、コンテナライフサイクル設定のLiveness Probeを定義します。
-
「postStart:」の行から「- "8080"」の行で、コンテナライフサイクル設定のpostStartフックを定義します。
-
このオレンジ色の背景で示す行は、Google Cloud Platform環境の場合だけ記述します。securityContextを設定します。fsGroupにはコンテナ実行グループと同等の設定をしてください。
-
このオレンジ色の背景で示す行は、コンテナイメージをPullする際に資格情報が必要な場合に記述します。Red Hat OpenShift Container Platform環境で資格情報が不要な場合はimagePullSecrets: []を指定してください。
-
「preStop:」の行から「- sleep 20」の行で、コンテナライフサイクル設定のpreStopフックを定義します。
-
この記述例では、コンテキストパスを設定していない場合の「prometheus.io/path」の例を記載しています。
コンテキストパスを設定する場合は、パスを次のように修正してください。
/<コンテキストパス>/hmppcto/metrics
- 重要
-
Kubernetesマニフェスト作成時の注意事項
Kubernetesマニフェストは、行頭のインデント(文字の開始位置)が厳密に評価されます。注意して作成してください。