第 5 章 安装区识别示例应用程序
使用本节来部署区识别示例应用程序,以验证 OpenShift Container Storage Metro Disaster 恢复设置是否正确配置。
随着数据区域之间的延迟,可以预期与节点和区域之间具有低延迟的 OpenShift 集群(例如,同一位置的所有节点)相比,可以看到性能下降。性能会下降多少,取决于区域之间的延迟和使用存储(如高写流量)的应用行为。请确保使用 Metro DR 集群配置测试关键应用程序,以确保应用程序性能达到所需的服务水平。
5.1. 安装区示例应用程序
在本节中,ocs-storagecluster-cephfs
存储类用于创建一个可由多个 pod 同时使用的 Read-Write-Many(RWX)PVC。我们将使用的应用程序称为文件上传程序。
由于此应用共享用于存储文件的 RWX 卷,我们可以演示如何在拓扑区域之间分散应用,以便在站点中断时仍可用。这也适用于持久数据访问,因为 OpenShift Container Storage 被配置为具有区感知和高可用性的 Metro DR 扩展集群。
创建一个新项目
oc new-project my-shared-storage
部署名为 file-uploader 的 PHP 应用程序示例:
oc new-app openshift/php:7.2-ubi8~https://github.com/christianh814/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 个文件加载器 Pod。重复上述命令,直到 Running STATUS 中有 4 个 file-uploader Pod。
您可以创建一个 PersistentVolumeClaim,并使用 oc set volume 命令将其附加到应用程序中。执行以下命令
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
此命令将:
- 创建 PersistentVolumeClaim
- 更新应用部署,使其包含卷定义
- 更新应用部署,将卷挂载附加到指定的 mount-path
- 导致 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
注意 ACCESSMODE 设置为 RWX(ReadWriteMany)。
所有 4 个文件-uploaderPods 都使用相同的 RWX 卷。如果没有此 ACCESSMODE,OpenShift 将不会尝试可靠地将多个 Pod 附加到同一持久性卷。如果您试图扩展正在使用 RWO( ReadWriteOnce)持久性卷的部署,则 Pod 将在同一节点上被在一起。