5.7. ゾーン認識サンプルアプリケーションのインストール
ゾーン対応サンプルアプリケーションをデプロイし、OpenShift Data Foundation、ストレッチクラスター設定が正しく設定されているかどうかを検証します。
データゾーン間のレイテンシーがあると、ノードやゾーン間のレイテンシーが低い (たとえば、すべてのノードが同じ場所にある) OpenShift クラスターと比較して、パフォーマンスの低下が予想されます。パフォーマンスの低下の速度または量は、ゾーン間の待ち時間と、ストレージを使用するアプリケーションの動作 (大量の書き込みトラフィックなど) によって異なります。必要なサービスレベルに対して十分なアプリケーションのパフォーマンスを確保するために、必ずストレッチクラスター設定で重要なアプリケーションをテストしてください。
ReadWriteMany (RWX) 永続ボリューム要求 (PVC) は、ocs-storagecluster-cephfs
ストレージクラスを使用して作成されます。複数の Pod は、新規に作成された RWX PVC を同時に使用します。使用されるアプリケーションは File Uploader と呼ばれます。
アプリケーションがトポロジーゾーン全体に分散されるかに関するデモンストレーションにより、サイトが停止した場合にアプリケーションが引き続き利用可能となります。
このアプリケーションはファイルを保存するために同じ RWX ボリュームを共有するため、このデモンストレーションが可能です。Red Hat OpenShift Data Foundation は、ゾーン認識および高可用性を備えたストレッチクラスターとして設定されているため、これは永続的なデータアクセスにも有効です。
新しいプロジェクトを作成する。
$ oc new-project my-shared-storage
file-uploader という名前の PHP アプリケーションのサンプルをデプロイします。
$ oc new-app openshift/php:latest~https://github.com/mashetty330/openshift-php-upload-demo --name=file-uploader
出力例:
Found image 4f2dcc0 (9 days old) in image stream "openshift/php" under tag "7.2-ubi8" for "openshift/php:7.2- ubi8" Apache 2.4 with PHP 7.2 ----------------------- PHP 7.2 available as container is a base platform for building and running various PHP 7.2 applications and frameworks. PHP is an HTML-embedded scripting language. PHP attempts to make it easy for developers to write dynamically generated web pages. PHP also offers built-in database integration for several commercial and non-commercial database management systems, so writing a database-enabled webpage with PHP is fairly simple. The most common use of PHP coding is probably as a replacement for CGI scripts. Tags: builder, php, php72, php-72 * A source build using source code from https://github.com/christianh814/openshift-php-upload-demo will be cr eated * The resulting image will be pushed to image stream tag "file-uploader:latest" * Use 'oc start-build' to trigger a new build --> Creating resources ... imagestream.image.openshift.io "file-uploader" created buildconfig.build.openshift.io "file-uploader" created deployment.apps "file-uploader" created service "file-uploader" created --> Success Build scheduled, use 'oc logs -f buildconfig/file-uploader' to track its progress. Application is not exposed. You can expose services to the outside world by executing one or more of the commands below: 'oc expose service/file-uploader' Run 'oc status' to view your app.
ビルドログを表示し、アプリケーションがデプロイされるまで待機します。
$ oc logs -f bc/file-uploader -n my-shared-storage
出力例:
Cloning "https://github.com/christianh814/openshift-php-upload-demo" ... [...] Generating dockerfile with builder image image-registry.openshift-image-regis try.svc:5000/openshift/php@sha256:d97466f33999951739a76bce922ab17088885db610c 0e05b593844b41d5494ea STEP 1: FROM image-registry.openshift-image-registry.svc:5000/openshift/php@s ha256:d97466f33999951739a76bce922ab17088885db610c0e05b593844b41d5494ea STEP 2: LABEL "io.openshift.build.commit.author"="Christian Hernandez <christ ian.hernandez@yahoo.com>" "io.openshift.build.commit.date"="Sun Oct 1 1 7:15:09 2017 -0700" "io.openshift.build.commit.id"="288eda3dff43b02f7f7 b6b6b6f93396ffdf34cb2" "io.openshift.build.commit.ref"="master" " io.openshift.build.commit.message"="trying to modularize" "io.openshift .build.source-location"="https://github.com/christianh814/openshift-php-uploa d-demo" "io.openshift.build.image"="image-registry.openshift-image-regi stry.svc:5000/openshift/php@sha256:d97466f33999951739a76bce922ab17088885db610 c0e05b593844b41d5494ea" STEP 3: ENV OPENSHIFT_BUILD_NAME="file-uploader-1" OPENSHIFT_BUILD_NAMESP ACE="my-shared-storage" OPENSHIFT_BUILD_SOURCE="https://github.com/christ ianh814/openshift-php-upload-demo" OPENSHIFT_BUILD_COMMIT="288eda3dff43b0 2f7f7b6b6b6f93396ffdf34cb2" STEP 4: USER root STEP 5: COPY upload/src /tmp/src STEP 6: RUN chown -R 1001:0 /tmp/src STEP 7: USER 1001 STEP 8: RUN /usr/libexec/s2i/assemble ---> Installing application source... => sourcing 20-copy-config.sh ... ---> 17:24:39 Processing additional arbitrary httpd configuration provide d by s2i ... => sourcing 00-documentroot.conf ... => sourcing 50-mpm-tuning.conf ... => sourcing 40-ssl-certs.sh ... STEP 9: CMD /usr/libexec/s2i/run STEP 10: COMMIT temp.builder.openshift.io/my-shared-storage/file-uploader-1:3 b83e447 Getting image source signatures [...]
Push successful
を確認すると、コマンドプロンプトは tail モードから復帰します。注記new-app コマンドは、アプリケーションを git リポジトリーから直接デプロイして、OpenShift テンプレートを使用しないため、OpenShift ルートリソースはデフォルトでは作成されません。ルートを手動で作成する必要があります。
アプリケーションのスケーリング
アプリケーションを 4 つのレプリカにスケーリングし、そのサービスを公開して、アプリケーションゾーンを認識して使用できるようにします。
$ oc expose svc/file-uploader -n my-shared-storage
$ oc scale --replicas=4 deploy/file-uploader -n my-shared-storage
$ oc get pods -o wide -n my-shared-storage
数分後には、4 つの file-uploader Pod が必要です。4 つの file-uploader Pod が
Running
ステータスになるまで、上記のコマンドを繰り返します。PVC を作成し、これをアプリケーションに割り当てます。
$ oc set volume deploy/file-uploader --add --name=my-shared-storage \ -t pvc --claim-mode=ReadWriteMany --claim-size=10Gi \ --claim-name=my-shared-storage --claim-class=ocs-storagecluster-cephfs \ --mount-path=/opt/app-root/src/uploaded \ -n my-shared-storage
このコマンドは、以下のようになります。
- PVC を作成します。
- ボリューム定義を含めるようにアプリケーションデプロイメントを更新します。
- アプリケーションのデプロイメントを更新して、ボリュームマウントを指定されたマウントパスに割り当てます。
- 4 つのアプリケーション Pod で新規デプロイメントを作成します。
ボリュームの追加の結果を確認します。
$ oc get pvc -n my-shared-storage
出力例:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE my-shared-storage Bound pvc-5402cc8a-e874-4d7e-af76-1eb05bd2e7c7 10Gi RWX ocs-storagecluster-cephfs 52s
ACCESS MODE
が RWX に設定されている点に注意してください。4 つの
file-uploader
Pod はすべて同じ RWX ボリュームを使用しています。このアクセスモードがないと、OpenShift は複数の Pod を同じ永続ボリューム (PV) に確実にアタッチしようとしません。ReadWriteOnce (RWO) PV を使用するデプロイメントをスケールアップしようとすると、Pod は同じノードに配置される可能性があります。
5.7.1. インストール後のアプリケーションのスケーリング
手順
アプリケーションを 4 つのレプリカにスケーリングし、そのサービスを公開して、アプリケーションゾーンを認識して使用できるようにします。
$ oc expose svc/file-uploader -n my-shared-storage
$ oc scale --replicas=4 deploy/file-uploader -n my-shared-storage
$ oc get pods -o wide -n my-shared-storage
数分後には、4 つの file-uploader Pod が必要です。4 つの file-uploader Pod が
Running
ステータスになるまで、上記のコマンドを繰り返します。PVC を作成し、これをアプリケーションに割り当てます。
$ oc set volume deploy/file-uploader --add --name=my-shared-storage \ -t pvc --claim-mode=ReadWriteMany --claim-size=10Gi \ --claim-name=my-shared-storage --claim-class=ocs-storagecluster-cephfs \ --mount-path=/opt/app-root/src/uploaded \ -n my-shared-storage
このコマンドは、以下のようになります。
- PVC を作成します。
- ボリューム定義を含めるようにアプリケーションデプロイメントを更新します。
- アプリケーションのデプロイメントを更新して、ボリュームマウントを指定されたマウントパスに割り当てます。
- 4 つのアプリケーション Pod で新規デプロイメントを作成します。
ボリュームの追加の結果を確認します。
$ oc get pvc -n my-shared-storage
出力例:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE my-shared-storage Bound pvc-5402cc8a-e874-4d7e-af76-1eb05bd2e7c7 10Gi RWX ocs-storagecluster-cephfs 52s
ACCESS MODE
が RWX に設定されている点に注意してください。4 つの
file-uploader
Pod はすべて同じ RWX ボリュームを使用しています。このアクセスモードがないと、OpenShift は複数の Pod を同じ永続ボリューム (PV) に確実にアタッチしようとしません。ReadWriteOnce (RWO) PV を使用するデプロイメントをスケールアップしようとすると、Pod は同じノードに配置される可能性があります。
5.7.2. ゾーンを意識したデプロイメントの変更
現在、file-uploader
Deployment はゾーンを認識せず、すべての Pod を同じゾーンでスケジュールできます。この場合、サイトに障害が発生すると、アプリケーションは利用できなくなります。詳細は、Pod トポロジー分散制約を使用した Pod 配置の制御 を参照してください。
アプリケーションデプロイメント設定に Pod 配置ルールを追加して、アプリケーションゾーンを認識させます。
以下のコマンドを実行して出力を確認します。
$ oc get deployment file-uploader -o yaml -n my-shared-storage | less
出力例:
[...] spec: progressDeadlineSeconds: 600 replicas: 4 revisionHistoryLimit: 10 selector: matchLabels: deployment: file-uploader strategy: rollingUpdate: maxSurge: 25% maxUnavailable: 25% type: RollingUpdate template: metadata: annotations: openshift.io/generated-by: OpenShiftNewApp creationTimestamp: null labels: deployment: file-uploader spec: # <-- Start inserted lines after here containers: # <-- End inserted lines before here - image: image-registry.openshift-image-registry.svc:5000/my-shared-storage/file-uploader@sha256:a458ea62f990e431ad7d5f84c89e2fa27bdebdd5e29c5418c70c56eb81f0a26b imagePullPolicy: IfNotPresent name: file-uploader [...]
トポロジーゾーンラベルを使用するようにデプロイメントを編集します。
$ oc edit deployment file-uploader -n my-shared-storage
Start
とEnd
の間に、以下の新しい行を追加します (前のステップの出力に表示)。[...] spec: topologySpreadConstraints: - labelSelector: matchLabels: deployment: file-uploader maxSkew: 1 topologyKey: topology.kubernetes.io/zone whenUnsatisfiable: DoNotSchedule - labelSelector: matchLabels: deployment: file-uploader maxSkew: 1 topologyKey: kubernetes.io/hostname whenUnsatisfiable: ScheduleAnyway nodeSelector: node-role.kubernetes.io/worker: "" containers: [...]
出力例:
deployment.apps/file-uploader edited
デプロイを 0 個 の Pod に変更し、その後 4 個 の Pod に戻します。これは、デプロイメントが Pod の配置に関して変更されたために必要です。
- 0 個 の Pod へのスケールダウン
$ oc scale deployment file-uploader --replicas=0 -n my-shared-storage
出力例:
deployment.apps/file-uploader scaled
- 4 個 の Pod へのスケールアップ
$ oc scale deployment file-uploader --replicas=4 -n my-shared-storage
出力例:
deployment.apps/file-uploader scaled
4 つの Pod が datacenter1 および datacenter2 ゾーンの 4 つのノードに分散されていることを確認します。
$ oc get pods -o wide -n my-shared-storage | egrep '^file-uploader'| grep -v build | awk '{print $7}' | sort | uniq -c
出力例:
1 perf1-mz8bt-worker-d2hdm 1 perf1-mz8bt-worker-k68rv 1 perf1-mz8bt-worker-ntkp8 1 perf1-mz8bt-worker-qpwsr
使用されるゾーンラベルを検索します。
$ oc get nodes -L topology.kubernetes.io/zone | grep datacenter | grep -v master
出力例:
perf1-mz8bt-worker-d2hdm Ready worker 35d v1.20.0+5fbfd19 datacenter1 perf1-mz8bt-worker-k68rv Ready worker 35d v1.20.0+5fbfd19 datacenter1 perf1-mz8bt-worker-ntkp8 Ready worker 35d v1.20.0+5fbfd19 datacenter2 perf1-mz8bt-worker-qpwsr Ready worker 35d v1.20.0+5fbfd19 datacenter2
ブラウザーを使用して file-uploader Web アプリケーションを使用して新規ファイルをアップロードします。
作成されたルートを検索します。
$ oc get route file-uploader -n my-shared-storage -o jsonpath --template="http://{.spec.host}{'\n'}"
出力例:
http://file-uploader-my-shared-storage.apps.cluster-ocs4-abdf.ocs4-abdf.sandbox744.opentlc.com
直前の手順のルートを使用して、ブラウザーを Web アプリケーションに指定します。
Web アプリケーションはアップロードしたすべてのファイルをリスト表示し、新しいファイルをアップロードしたり、既存のデータをダウンロードする機能を提供します。今は何もありません。
ローカルマシンから任意のファイルを選択し、これをアプリケーションにアップロードします。
- Choose file をクリックして任意のファイルを選択します。
Upload をクリックします。
図5.1 簡単な PHP ベースのファイルのアップロードツール
- List uploaded files をクリックし、現在アップロードされているファイルのリストを表示します。
OpenShift Container Platform イメージレジストリー、Ingress ルーティング、およびモニタリングサービスはゾーンを認識しません。