CTP を Kubernetes にデプロイするには、以下で説明するプロセスに従ってください。
このバージョンでは、Kubernetes に複数の CTP サーバーをデプロイすることはサポートされていません。サポートは、Kubernetes クラスターで実行されている CTP の 1 つのインスタンスに限定されます。
要件
まず、CTP を実行するための名前空間を作成します。例:
kubectl create namespace parasoft-ctp-namespace
注意: 名前空間名 parasoft-ctp-namespace は、このドキュメント全体のコマンドおよびリソースの例で使用されています。名前空間に別の名前を使用している場合は、parasoft-ctp-namespace をすべて実際の名前空間名に変更してください。
CTP のライセンスが取得されると、たとえ同じ名前空間を再作成した場合でも、名前空間を削除するとマシンロック ライセンスが無効になります。
次に、データベース構成とエクスポートの保存用に、Persistent Volume と Persistent Volume Claim が必要です。これらは、1 GB (データベース構成用) ~ 10 GB (エクスポート ストレージ用) 程度の容量をプロビジョニングし (必要に応じて増減可能)、ReadWriteOnce のアクセス モードを推奨します。この領域は、CTP サーバーのワークスペースに使用されます。
マウントするボリュームに、整形式の db_config.xml が存在する必要があります。以下の db_config.xml の例を参照してください。必要に応じて、マウントするボリュームに以下のサンプルをコピーできます。必要な構成はすべて、アプリケーション自体の中で行われます。URL JDBC 文字列が MariaDB、MySQL、または Oracle 用である場合は、CTP デプロイメント/ポッドを正しい JDBC アダプターで構成する必要があることに注意してください。URL JDBC 文字列が HyperSQL 用の場合は、CTP デプロイメント/ポッドの構成に関係なく起動するはずです。
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<db_config>
<connection>
<url>jdbc:hsqldb:file:/usr/local/parasoft/ctp/hsqldb/em;ifexists=true</url>
<username>em</username>
<password>em</password>
</connection>
</db_config>
</configuration>
デフォルトの Persistent Volume Claim 名は ctp-config-storage と ctp-exports-storage であり、これらの名前は CTP サーバーの yaml 定義を更新することでカスタマイズできます。以下に示すサンプルは、NFS Persistent Volume と Persistent Volume Claim を設定する構成です。この例では NFS を使用していますが、これは必須ではありません。ニーズに合った Persistent Volume タイプを使用してください。
警告: NFS の場合、エクスポートされたディレクトリには、コンテナを実行する Parasoft ユーザーと同じ UID および GID が必要です。たとえば、コマンド chown 1000:1000 <shared_path> を実行します。
# ==== Persistent Volume to Mount db_config.xml ====
apiVersion: v1
kind: PersistentVolume
metadata:
name: ctp-config-storage
namespace: parasoft-ctp-namespace
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
nfs:
path: <path>
server: <ip_address>
---
# ==== PersistentVolumeClaim for db_config.xml ====
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ctp-config-pvc
namespace: parasoft-ctp-namespace
spec:
accessModes:
- ReadWriteOnce
storageClassName: nfs
resources:
requests:
storage: 1Gi
volumeName: "ctp-config-storage"
---
# ==== Persistent Volume for Export Storage ====
apiVersion: v1
kind: PersistentVolume
metadata:
name: ctp-exports-storage
namespace: parasoft-ctp-namespace
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
nfs:
path: <path>
server: <ip_address>
---
# ==== PersistentVolumeClaim for CTP exports folder ====
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ctp-exports-pvc
namespace: parasoft-ctp-namespace
spec:
accessModes:
- ReadWriteOnce
storageClassName: nfs
resources:
requests:
storage: 10Gi
volumeName: "ctp-exports-storage"
yaml ファイルを使用して、Persistent Volume と Persistent Volume Claim を作成します。
kubectl create -f ctp-pv.yaml
Persistent Volume と Persistent Volume Claim が必要です。約 50 GB のスペースをプロビジョニングする必要があり (これは必要に応じて増減できます)、ReadWriteOnce アクセス モードを推奨します。
以下の例のデフォルトの Persistent Volume Claim 名は、CTP サーバーの yaml 定義を更新することでカスタマイズできます。例では NFS を使用していますが、これは必須ではありません。 ニーズに合った Persistent Volume タイプを使用してください。外部データベースの場合、Persistent Volume および Persistent Volume Claim のマウントは、データベース自体ではなく、データベース JDBC アダプター用であることに注意してください。
組込みの HyperSQL データベースおよびサポートされている各外部データベース用に、さまざまな yaml の例が含まれています。環境に適したものを使用してください。
警告: NFS の場合、エクスポートされたディレクトリには、コンテナを実行する Parasoft ユーザーと同じ UID および GID が必要です。たとえば、コマンド chown 1000:1000 <shared_path> を実行します。
HyperSQL (Embedded)
apiVersion: v1
kind: PersistentVolume
metadata:
name: ctp-hsqldb-storage
namespace: parasoft-ctp-namespace
spec:
capacity:
storage: 50Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
nfs:
path: <path>
server: <ip_address>
---
# PersistentVolumeClaim for CTP HyperSQL DB
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ctp-hsqldb-pvc
namespace: parasoft-ctp-namespace
spec:
accessModes:
- ReadWriteOnce
storageClassName: nfs
resources:
requests:
storage: 50Gi
MariaDB
# ==== Persistent Volume for MariaDB JDBC Adapter
apiVersion: v1
kind: PersistentVolume
metadata:
name: ctp-mariadbadapter-storage
namespace: parasoft-ctp-namespace
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
nfs:
path: <path>
server: <ip_address>
---
# ==== PersistentVolumeClaim for MariaDB JDBC Adapter ====
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ctp-mariadbadapter-pvc
namespace: parasoft-ctp-namespace
spec:
accessModes:
- ReadWriteOnce
storageClassName: nfs
resources:
requests:
storage: 1Gi
volumeName: "ctp-mariadbadapter-storage"
MySQL
# ==== Persistent Volume for MySQL JDBC Adapter
apiVersion: v1
kind: PersistentVolume
metadata:
name: ctp-mysqladapter-storage
namespace: parasoft-ctp-namespace
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
nfs:
path: <path>
server: <ip_address>
---
# ==== PersistentVolumeClaim for MySQL JDBC Adapter ====
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ctp-mysqladapter-pvc
namespace: parasoft-ctp-namespace
spec:
accessModes:
- ReadWriteOnce
storageClassName: nfs
resources:
requests:
storage: 1Gi
volumeName: "ctp-mysqladapter-storage"
Oracle
# ==== Persistent Volume for OracleDB JDBC Adapter
apiVersion: v1
kind: PersistentVolume
metadata:
name: ctp-oracleadapter-storage
namespace: parasoft-ctp-namespace
spec:
capacity:
storage: 1Gi
volumeMode: Filesystem
accessModes:
- ReadWriteOnce
persistentVolumeReclaimPolicy: Retain
storageClassName: nfs
nfs:
path: <path>
server: <ip_address>
---
# ==== PersistentVolumeClaim for OracleDB JDBC Adapter ====
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: ctp-oracleadapter-pvc
namespace: parasoft-ctp-namespace
spec:
accessModes:
- ReadWriteOnce
storageClassName: nfs
resources:
requests:
storage: 1Gi
volumeName: "ctp-oracleadapter-storage"
yaml ファイルを使用して、Persistent Volume と Persistent Volume Claim を作成します。
kubectl create -f ctp-db.yaml
また、サービス アカウントと必要な権限を作成する必要があります。
apiVersion: v1 kind: ServiceAccount metadata: name: parasoft-account namespace: parasoft-ctp-namespace automountServiceAccountToken: true --- apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: parasoft-read namespace: parasoft-ctp-namespace rules: - apiGroups: - "" resources: - "namespaces" - "pods" verbs: - get --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: parasoft-read-bind namespace: parasoft-ctp-namespace roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: parasoft-read subjects: - kind: ServiceAccount name: parasoft-account namespace: parasoft-ctp-namespace
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
CTP のデプロイ
前提条件が満たされたら、Kubernetes に CTP をデプロイできます。前の手順でカスタムの Persistent Volume Claim 名を使用した場合は、適切な volumeMounts:name フィールドと claimName フィールドを更新してカスタム名と一致させてください。使用しているデータベースのセクションのコメントを外します。
-env 指定子で ACCEPT_EULA 値を true に設定して、サーバーの EULA に同意する必要があります。さらに、匿名の使用状況データを Parasoft に送信して製品を改善することをオプトインするには、-env 指定子で USAGE_DATA 値を true に変更します。
注意: kind: Deployment はサポートされません。kind: Pod または kind: StatefulSet のいずれかを使用してください。これらはサポートされています。
apiVersion: v1
kind: Pod
metadata:
name: ctp-pod
namespace: parasoft-ctp-namespace
labels:
app: ctp
spec:
securityContext:
runAsNonRoot: true
serviceAccountName: parasoft-account
automountServiceAccountToken: true
containers:
- name: ctp
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
image: parasoft/ctp:latest
ports:
- containerPort: 8080
# Delete database.properties file to prevent overwriting of db_config.xml on pod startup
command: [ "/bin/bash", "-c" ]
args:
-
cd ctp/webapps/em/WEB-INF/classes/META-INF/spring/ &&
rm database.properties &&
cd /usr/local/parasoft &&
./entrypoint.sh
volumeMounts:
- name: ctp-config-storage
mountPath: /usr/local/parasoft/ctp/webapps/em/config/db_config.xml
subPath: db_config.xml
- name: ctp-exports-storage
mountPath: /usr/local/parasoft/exports
# - name: ctp-hsqldb-storage
# mountPath: /usr/local/parasoft/ctp/hsqldb
# === DB JDBC Adapter Volume Mounts ===
# - name: ctp-mariadbadapter-storage
# mountPath: /usr/local/parasoft/ctp/webapps/em/WEB-INF/lib/mariadb-java-client-3.0.8.jar
# subPath: mariadb-java-client-3.0.8.jar
# - name: ctp-mysqladapter-storage
# mountPath: /usr/local/parasoft/ctp/webapps/em/WEB-INF/lib/mysql-connector-java-8.0.30.jar
# subPath: mysql-connector-java-8.0.30.jar
# - name: ctp-oracleadapter-storage
# mountPath: /usr/local/parasoft/ctp/webapps/em/WEB-INF/lib/ojdbc8.jar
# subPath: ojdbc8.jar
env:
# === USE BELOW TO CONFIGURE ENVIRONMENT VARIABLES ===
# Configures CTP to connect to license server at the specified base URL
- name: LICENSE_SERVER_URL
value: https://licenseserver:8443
# Configures CTP to use basic authentication when connecting to license server
- name: LICENSE_SERVER_AUTH_ENABLED
value: "false"
# Configures CTP to connect to license server as the specified user
# - name: LICENSE_SERVER_USERNAME
# value: admin
# Configures CTP to connect to license server with the specified password
# - name: LICENSE_SERVER_PASSWORD
# value: admin
# Set to true or false to opt-in or opt-out of sending anonymous usage data to Parasoft
- name: USAGE_DATA
value: "false"
# Accepts the End User License Agreement if set to true
- name: ACCEPT_EULA
value: "false"
- name: CATALINA_OPTS
value: "-Dparasoft.cloudvm=true
-Dparasoft.cloudvm.config=Kubernetes"
- name: PARASOFT_POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: PARASOFT_POD_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
# === PROBES ===
startupProbe:
httpGet:
path: /em/resources/favicon.ico
port: 8080
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 30
failureThreshold: 3
livenessProbe:
httpGet:
path: /em/resources/favicon.ico
port: 8080
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 30
readinessProbe:
httpGet:
path: /em/healthcheck
port: 8080
initialDelaySeconds: 30
periodSeconds: 30
timeoutSeconds: 30
volumes:
- name: ctp-config-storage
persistentVolumeClaim:
claimName: ctp-config-pvc
- name: ctp-exports-storage
persistentVolumeClaim:
claimName: ctp-exports-pvc
# - name: ctp-hsqldb-storage
# persistentVolumeClaim:
# claimName: ctp-hsqldb-pvc
# === SQL JDBC Adapter Volumes ===
# - name: ctp-mariadbadapter-storage
# persistentVolumeClaim:
# claimName: ctp-mariadbadapter-pvc
# - name: ctp-mysqladapter-storage
# persistentVolumeClaim:
# claimName: ctp-mysqladapter-pvc
# - name: ctp-oracleadapter-storage
# persistentVolumeClaim:
# claimName: ctp-oracleadapter-pvc
---
# ==== CTP Service Definition ====
apiVersion: v1
kind: Service
metadata:
name: ctp-service
namespace: parasoft-ctp-namespace
spec:
selector:
app: ctp
type: NodePort
ports:
- protocol: TCP
port: 8080
targetPort: 8080
nodePort: 30000
yaml ファイルを使用して、Kubernetes で CTP にアクセスするために使用できるサービスを作成します。
kubectl create -f ctp-pod.yaml