このセクションでは、DTP を Kubernetes にデプロイする方法について説明します。このセクションの内容:
概要
DTP を Kubernetes にデプロイするには、以下の説明に従ってください。
要件
DTP を起動する前に、DTP 用の外部データベースを構築してください。サポートされるデータベースは、MySQL、Oracle、および PostgreSQL です (サポートされるバージョンについては、「要件とサポート」を参照)。Docker Hub で公開されている MySQL、Oracle、PostgreSQL の Docker イメージのいずれかを使用できます。
次に、DTP を実行するための名前空間を作成します。
kubectl create namespace parasoft-dtp-namespace
DTP のライセンスを取得した後、名前空間を削除すると、マシンロック ライセンスが無効になります。たとえ同じ名前空間を再作成しても無効です。
次に、Kubernetes クラスターが必要です。クラスターを起動したら、DTP の Pod と関連リソースが必要とするサービス アカウントと権限を作成します。この目的で使用できる yaml ファイルの例を以下に示します。
# Stable access for clients to license server apiVersion: v1 kind: ServiceAccount metadata: name: parasoft-account namespace: parasoft-dtp-namespace --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: parasoft-read namespace: parasoft-dtp-namespace rules: - apiGroups: - "*" resources: - "*" verbs: - get - read - list --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: parasoft-read-bind namespace: parasoft-dtp-namespace roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: parasoft-read subjects: - kind: ServiceAccount name: parasoft-account namespace: parasoft-dtp-namespace
DTP 環境を構築する前に、yaml ファイルを使用して、必要とされる名前空間、サービス アカウント、および権限を作成します。
kubectl create -f parasoft-permissions.yaml
コンソールに以下のような出力が表示されるはずです。
serviceaccount/parasoft-account created role.rbac.authorization.k8s.io/parasoft-read created rolebinding.rbac.authorization.k8s.io/parasoft-read-bind created
カスタム キーストア
カスタム キーストアを設定する場合、.keystore および server.xml ファイルの構成マップを作成する必要があります。以下のコマンドは、カスタムの .keystore および server.xml ファイルのファイル マッピングを含む keystore-cfgmap という構成マップを作成します。この例では、各ファイル マッピングにキーが与えられています。.keystore ファイルに keystore、server.xml ファイルに server-config です。各ファイル マッピングにキーを指定する必要はありませんが、キーをファイル名にしたくない場合に便利です。
~$ kubectl create configmap keystore-cfgmap --from-file=keystore=/path/to/.keystore --from-file=server-config=/path/to/server.xml configmap/keystore-cfgmap created
DTP のセットアップ
DTP をセットアップするには、yaml ファイルを作成します。このファイルは Secret (オプション)、ボリューム、Pod、内部アクセス サービス、および外部アクセス サービス (オプション) を定義します。Secret は、リポジトリから DTP イメージをプルするために使用されます。Pod は、DTP Server と Data Collector を別々のコンテナーで実行するようにセットアップされています。各コンテナーは、データを永続化するためのボリュームと liveness プローブで構成されます。liveness プローブは、Docker のヘルスチェックに相当するものです。内部アクセス サービスは、DTP ポッドを他のポッドに公開し、明示的な IP アドレスの代わりにサービス名を介して通信できるようにします。外部アクセス サービスは、ノードにポートを割り当て、それらをポッドのポートにマッピングすることで、外部クライアント経由で DTP と Data Collector にアクセスできるようにします。この目的で使用される可能性のある yaml ファイルの例を以下に示します。この例では、NFS ボリュームが使用されていますが、これは必須ではありません。ニーズに合ったボリュームタイプを使用してください。
apiVersion: v1
kind: Pod
metadata:
name: dtp
namespace: parasoft-dtp-namespace
labels:
app: DTP
spec:
volumes:
- name: dtp-data
nfs:
server: NFS_SERVER_HOST
path: /dtp/
# Uncomment section below if you are setting up a custom keystore; you will also need to uncomment out the associated volumeMounts below
# - name: keystore-cfgmap-volume
# configMap:
# name: keystore-cfgmap
securityContext:
runAsNonRoot: true
containers:
- name: dtp-server
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
image: DTP_DOCKER_IMAGE
imagePullPolicy: Always
env:
- name: PARASOFT_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: PARASOFT_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
# To inject JVM arguments into the container, specify the "env" property as in the example below, which injects JAVA_CONFIG_ARGS
# - name: JAVA_CONFIG_ARGS
# value: "-Dcom.parasoft.sdm.storage.managers.admin.enable.delete.project.data=true"
args: ["--run", "dtp"]
ports:
- name: "http-server"
containerPort: 8080
- name: "https-server"
containerPort: 8443
volumeMounts:
- mountPath: "/usr/local/parasoft/data"
name: dtp-data
# Uncomment section below if you are setting up a custom keystore. Note that updates made to these files will not be reflected inside the container once it's been deployed; you will need to restart the container for it to contain any updates.
# - name: keystore-cfgmap-volume
# mountPath: "/usr/local/parasoft/dtp/tomcat/conf/.keystore"
# subPath: keystore
# - name: keystore-cfgmap-volume
# mountPath: "/usr/local/parasoft/dtp/tomcat/conf/server.xml"
# subPath: server-config
# To prevent liveness probe failures on environments with low or overly taxed RAM/CPU, we recommend increasing the timeout seconds
livenessProbe:
exec:
command:
- healthcheck.sh
- --verify
- dtp
initialDelaySeconds: 120
periodSeconds: 60
timeoutSeconds: 30
failureThreshold: 5
- name: data-collector
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
image: DTP_DOCKER_IMAGE
imagePullPolicy: Always
# To inject JVM arguments into the container, specify the "env" property as in the example below, which injects JAVA_DC_CONFIG_ARGS
# Note: com.parasoft.sdm.dc.license.License.debug=true is a required argument. Do not change or remove it.
env:
- name: JAVA_DC_CONFIG_ARGS
value: "-Dcom.parasoft.sdm.dc.license.License.debug=true"
args: ["--run", "datacollector", "--no-copy-data"]
ports:
- containerPort: 8082
volumeMounts:
- mountPath: "/usr/local/parasoft/data"
name: dtp-data
# To prevent liveness probe failures on environments with low or overly taxed RAM/CPU, we recommend increasing the timeout seconds
livenessProbe:
exec:
command:
- healthcheck.sh
- --verify
- datacollector
initialDelaySeconds: 120
periodSeconds: 60
timeoutSeconds: 30
failureThreshold: 5
# Uncomment section below if using DTP with Extension Designer
# - name: extension-designer
# securityContext:
# allowPrivilegeEscalation: false
# capabilities:
# drop: ["ALL"]
# seccompProfile:
# type: RuntimeDefault
# image: DTP_DOCKER_IMAGE
# imagePullPolicy: Always
# To inject JVM arguments into the container, specify the "env" property as in the example below, which injects JAVA_CONFIG_ARGS
# args: ["--run", "dtpservices"]
# ports:
# - containerPort: 8314
# volumeMounts:
# - mountPath: "/usr/local/parasoft/data"
# name: dtp-data
# To prevent liveness probe failures on environments with low or overly taxed RAM/CPU, we recommend increasing the timeout seconds
# livenessProbe:
# exec:
# command:
# - healthcheck.sh
# - --verify
# - dtpservices
# initialDelaySeconds: 120
# periodSeconds: 60
# timeoutSeconds: 30
# failureThreshold: 5
# Uncomment section below if using Extension Designer with an external MongoDB
# env:
# - name: DEP_USE_REMOTE_DB
# value: "true"
# - name: DEP_DB_HOSTNAME
# value: "mongodb-hostname" # Put your mongodb hostname here
# - name: DEP_DB_PORT
# value: "27017"
restartPolicy: Always
serviceAccountName: parasoft-account
imagePullSecrets:
- name: YOUR_SECRET
---
apiVersion: v1
kind: Service
metadata:
name: dtp
namespace: parasoft-dtp-namespace
spec:
selector:
app: DTP
ports:
- name: "http-server"
protocol: TCP
port: 8080
targetPort: 8080
- name: "data-collector"
protocol: TCP
port: 8082
targetPort: 8082
- name: "https-server"
protocol: TCP
port: 8443
targetPort: 8443
# Uncomment section below if using DTP with Extension Designer
# - name: "extension-designer"
# protocol: TCP
# port: 8314
# targetPort: 8314
---
apiVersion: v1
kind: Service
metadata:
name: dtp-external
namespace: parasoft-dtp-namespace
spec:
type: NodePort
selector:
app: DTP
ports:
- port: 8080
name: HTTP_PORT_NAME
nodePort: XXXXX
- port: 8082
name: DC_PORT_NAME
nodePort: XXXXX
- port: 8443
name: HTTPS_PORT_NAME
nodePort: XXXXX
# Uncomment section below if using DTP with Extension Designer
# - port: 8314
# name: EXTENSION_DESIGNER_PORT_NAME
# nodePort: XXXXX
# SERVICE CONFIG NOTES:
# 'name' can be whatever you want
# 'nodePort' must be between 30000-32768
# 'spec.selector' must match 'metadata.labels' in pod config
DTP 環境を作成する
ハードウェアの最小要件を満たしている場合、DTP の起動には最大で 2 分かかります。起動中は、ブラウザーから DTP にアクセスできません。
クラスター上のボリューム マウントの場所を準備します。デフォルトでは、イメージは UID 1000 および GID 1000 を持つ parasoft ユーザーとして実行されます。このユーザーが読み取り/書き込みできるようにボリュームを準備します。
次に、前に作成した DTP セットアップ yaml ファイルで定義された DTP 環境を作成します。
kubectl create -f parasoft-dtp.yaml
これにより、永続ボリュームのコンテンツが初期化されますが、DTP および Data Collector コンテナーを正しく実行するには、さらにセットアップが必要です。
JVM 引数をコンテナーに挿入し、そのステータスを確認したい場合は、次のコマンドを実行します。
kubectl exec <POD_NAME> -c <CONTAINER_NAME> -- printenv
データベースに接続するように DTP をセットアップする
関連する JDBC ドライバーをダウンロードして、DTP データ ディレクトリにマウントされている永続ボリュームにインストールします。
DTP_DATA_DIR/lib/thirdparty/
DTP データベースを初期化します。同じクラスターに存在する MySQL データベースの場合:
kubectl exec dtp -c dtp-server -- cat dtp/grs/db/dtp/mysql/create.sql | kubectl exec -i <mysql pod name> -- mysql -u<username> -p<password>
PSTRootConfig.xml ファイルの <dtp-db-connection> セクションでデータベース URL を構成します。このファイルは、DTP データ ディレクトリにマウントされている永続ボリュームに存在します。
DTP_DATA_DIR/conf/PSTRootConfig.xml
データベース URL の構造は、外部データベースへのアクセス方法によって異なります。例:
- データベースがリモートサーバーでホストされている。この場合 (MySQL データベースを想定)、URL は次のようになります: jdbc:mysql://<DB_HOST>:3306/DTP
- データベースは K8 クラスタ内で実行中であり、設定されたサービス名または IP アドレスを介してアクセスできる。この場合 (MySQL データベースを想定)、URL は次のようになります: jdbc:mysql://<CONFIGURED-SERVICE-NAME>.<NAMESPACE>:3306/DTP
DTP 環境を再作成する
この時点で、DTP 環境は完全に構成されています。変更を有効にするには、コンテナーを再起動する必要があります。これを行うには、単純に環境を破棄します。
kubectl delete -f parasoft-dtp.yaml
次に、「DTP 環境を作成する」と同じコマンドを使用して環境を再作成します。
DTP と Extension Designer を併用する場合、初期設定を完了した後、Extension Designer のリバース プロキシ設定を更新し、DTP と Extension Designer にアクセスするための期待されるホスト名と公開ポートを反映する必要があります。
カスタム トラストストア
Kubernetes 環境でのカスタム トラストストアの使用は、上記のカスタム キーストアの使用と同様です。カスタム キーストアの使用手順を適宜読み換えてください。なお、トラスト ストアの場所は /usr/local/parasoft/dtp/jre/lib/security/cacerts です。
トラブルシューティング
追加のログへのアクセス
DTP はデバッグ ログを自動的にキャプチャします。DTP_DATA_DIR/logs/ ディレクトリにある testing.log ファイルでデバッグ ログを参照できます。