Kubernetes の StatefulSet を使用してコンテナ化 MID Server を構築およびデプロイする方法Summary Kubernetes では、コンテナ化 MID Server は Pod 上で実行されます。Pod が再起動した場合や障害によって再作成された場合、Pod ストレージは一時的(ephemeral)であるため、Pod のファイルシステムに対するすべての変更は失われます。 MID Server はステートフルアプリケーションです。各 MID Server は config.xml に保存された一意の名前と sys_id を持っています。また、キーストア内に独自の鍵ペアを持ち、work フォルダー内にその他の作業データを保持しています。このようなデータは永続ストレージに保存する必要があります。これにより、MID Server は新しい Pod 上でも継続して動作できます。 Kubernetes Deployment と Kubernetes StatefulSet は、Kubernetes 上でコンテナ化アプリケーションを管理するための 2 つの主要なワークロードリソースです。Deployment はステートレスアプリケーションの管理に適しており、StatefulSet はステートフルアプリケーションの管理に適しています。 StatefulSet は Utah リリースからサポートされていますが、対象はコンテナ化 Linux MID Server のみです。MID Server に Deployment ワークロードリソースを使用することは推奨していません。 注:永続ストレージ上のデータを安全に保つことが重要です。これにアクセスできる人は MID Server を侵害できる可能性があります。 Release この KB は、San Diego または Tokyo を利用しているお客様、およびコンテナ化 Windows MID Server をデプロイしたいお客様向けの回避策を提供します。 Instructions イメージの構築 前提条件:Docker Engine または Docker Desktop がマシンにインストールされていることを確認してください。Windows の場合は Windows Server 2019 が必要です。 Utah Patch 4 以降から MID Docker レシピをダウンロードするか、この KB に添付されているレシピを使用します。レシピをフォルダーに展開します。インスタンスで MID Server ダウンロードページを開き、「Download MID Server as ZIP archive」チェックボックスをオフにして MID インストール ZIP ファイルをダウンロードします。ZIP ファイルの署名を検証します。 jarsigner -verify -verbose -certs -strict <zip-file> 注:jarsigner ツールは JDK に含まれており、JRE には含まれていません。MID インストール ZIP ファイルを、レシピを展開した asset サブフォルダーに移動します。現在のディレクトリをレシピフォルダに変更します。次のコマンドを実行してイメージを構築します。 docker build . --build-arg MID_INSTALLATION_FILE=<zip_file> --build-arg MID_SIGNATURE_VERIFICATION=false --tag <image_tag> 注:<zip_file> はダウンロードした MID インストール ZIP ファイルのパスを含まないファイル名です。例:mid.sandiego-12-22-2021_01-31-2023_0300.linux.x86-64.zip。どの MID バージョンを含むイメージか識別しやすくするため、<image_tag> に MID のビルドタイムスタンプを含めることを推奨します。例:mid:sandiego-12-22-2021_01-31-2023_0300 イメージを Kubernetes クラスターから取得可能なリモートレジストリへプッシュします。 StatefulSet を使用して Kubernetes に MID Server をデプロイする 前提条件:Kubernetes クラスターへのアクセス権が必要です。以下の手順は Azure CLI を使用した AKS 上でテストされています。Windows MID をデプロイする場合は、Windows Server 2019 ノードを含むクラスターが必要です。 添付ファイル内の StatefulSet デプロイメントテンプレートのいずれかを選択し、コピーを作成します。yaml ファイルを次のように変更します。 - Replace <YOUR_SERVICE_NAME> with a K8s service name, i.e. snc-mid-server - Replace <YOUR_NAMESPACE> with a K8s namespace name, i.e. default - Replace <YOUR_STATEFULSET_NAME> with a statefulset name, i.e. statefulset-linux-mid or statefulset-windows-mid - Replace <YOUR_VOLUME_CLAIM_NAME> with a claim template name, i.e. snc-mid-server - Replace <YOUR_STORAGE_CLASS_NAME> with your storage class name, i.e. managed-csi (Tip: run 'kubectl get storageclass' to get a list of available storage classes) - Replace <YOUR_IMAGE_URL> with the url pointing to the image in the remote registry, i.e. midcontainerregistry.azurecr.io/mid:tokyo-07-08-2022_04-11-2023_0200 - Replace <YOUR_INSTANCE_URL> with the instance URL // If the image is in a private registry - Replace <YOUR_REGISTRY_SECRET> with your registry secret name, i.e. midcontainerregistry-secret // If using basic auth - Replace <YOUR_MID_INSTANCE_USER_NAME>" with the mid instance user name, i.e. mid_server_basic_auth - Replace <MID_SECRET_MOUNT_PATH> with the path where the mid secret volume is mounted, i.e. /etc/secrets (linux) or c:\snc_mid_server\secrets (windows) - Replace <YOUR_MID_SECRET_PROPERTIES_FILENAME> with the mid secret properties file name, i.e. mid-secrets.properties - Replace <YOUR_MID_SECRET_NAME> with the mid secret name, i.e. mid-secret // If using mutual auth - Replace <MID_MUTUAL_AUTH_SECRET_MOUNT_PATH> with the path where the mid mutual auth secret volume is mounted, i.e. /etc/secrets (linux) or c:\snc_mid_server\secrets (windows) - Replace <YOUR_MID_MUTUAL_AUTH_PEM_FILENAME> with the mutual auth PEM file, i.e. mid-mutual-auth.pem - Replace <YOUR_MID_MUTUAL_AUTH_SECRET_NAME> with the mid mutual auth secret name, i.e. mid-mutual-auth-secret - Verify all other parameters and make all changes as needed, for example config parameters, replicas number, memory, cpu limits/requests 次のコマンドを実行します。 kubectl apply -f <yaml_file> 手動スケール kubectl scale --replicas=<number> statefulset <YOUR_STATEFULSET_NAME> StatefulSet を削除します。 kubectl delete statefulset <YOUR_STATEFULSET_NAME> * 注:StatefulSet を削除した後も、Persistent Volume Claim と Persistent Volume は残り、再利用できます。必要に応じて明示的に削除してください。 Related Links トラブルシューティング 注: kubectl コマンドの使用方法については、 https://kubernetes.io/docs/reference/kubectl/cheatsheet/ を参照してください ヒント: すべてのコマンドに --namespace フラグを追加しないようにするには、次のコマンドを実行して現在の名前空間を変更できます。kubectl config set-context --current --namespace= 1.statefulset、pvc、および pvc が作成されているかどうかを確認kubectl get statefulsetskubectl describe statefulset kubeclt 取得 PVCkubeclt 取得 PV 2.新しいポッドが作成されて実行されているかどうかを確認するkubectl get ポッドkubectl ログ [-f]kubectl describe pod 3.localhost とポッド間でファイルをコピーするkubectl cp /:/tmp/foo /tmp/barkubectl cp /tmp/foo /:/tmp/bar 例:デフォルト名前空間のポッドから localhost にエージェントログフォルダーをコピーします Linux:mkdir agent_logskubectl cp :/opt/snc_mid_server/agent/logs ./agent_logs Windows:mkdir agent_logskubectl cp :c:\snc_mid_server\agent\logs .\agent_logs 4.MID コンテナにログオンしますLinux:kubectl exec -it -- /bin/bashWindows:kubectl exec -it -- powershell トラブルシューティング 注:kubectl コマンドの使用方法については、https://kubernetes.io/docs/reference/kubectl/cheatsheet/ を参照してください。 ヒント:すべてのコマンドに --namespace フラグを追加しなくて済むようにするには、以下のコマンドを実行して現在のネームスペースを変更できます:kubectl config set-context --current --namespace=<NAMESPACE> 1. StatefulSet、PVC、および PV が作成されているか確認します。kubectl get statefulsetskubectl describe statefulset <STATEFULSET_NAME>kubeclt get pvckubeclt get pv 2. 新しい Pod が作成され実行中であるか確認します。kubectl get podskubectl logs <POD_NAME> [-f]kubectl describe pod <POD_NAME> 3. localhost と Pod 間でファイルをコピーします。kubectl cp <some-namespace>/<some-pod>:/tmp/foo /tmp/barkubectl cp /tmp/foo <some-namespace>/<some-pod>:/tmp/bar 例:default ネームスペース内の Pod から agent logs フォルダーを localhost にコピーする Linux:mkdir agent_logskubectl cp <POD_NAME>:/opt/snc_mid_server/agent/logs ./agent_logs Windows:mkdir agent_logskubectl cp <POD_NAME>:c:\snc_mid_server\agent\logs .\agent_logs 4. MID コンテナーにログインします。Linux:kubectl exec -it <POD_NAME> -- /bin/bashWindows:kubectl exec -it <POD_NAME> -- powershell