5.7. 安装区示例应用程序
部署区域感知示例应用,以验证 OpenShift Data Foundation,扩展集群设置是否正确配置。
随着数据区域之间的延迟,可以预期与节点和区域之间具有低延迟的 OpenShift 集群(例如,同一位置的所有节点)相比,可以看到性能下降。性能下降的速度取决于区域之间的延迟和使用存储(如高写流量)的应用程序行为。请确保使用扩展集群配置测试关键应用程序,以确保应用程序性能达到所需的服务水平。
ReadWriteMany(RWX)持久性卷声明(PVC)是使用 ocs-storagecluster-cephfs 存储类创建的。多个 pod 同时使用新创建的 RWX PVC。使用的应用称为文件上传程序。
演示应用程序如何在拓扑区间分布,以便在站点中断时仍然可用:
此演示是可行的,因为此应用共享同一个 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 路由资源。您需要手动创建路线。
5.7.1. 安装后扩展应用程序 复制链接链接已复制到粘贴板!
步骤
将应用缩放为四个副本,并公开其服务,使应用区域了解和可用。
$ 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几分钟后,您应该有四个 file-uploader pod。重复上述命令,直到有 4 个文件加载程序容器集处于
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。
- 更新应用部署,以包含卷定义。
- 更新应用部署,将卷挂载附加到指定的 mount-path 中。
- 使用四个应用 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。所有四个
file-uploaderpod 都使用相同的 RWX 卷。如果没有这种访问模式,OpenShift 不会尝试可靠地将多个容器集附加到同一持久卷(PV)。如果您试图扩展正在使用 ReadWriteOnce(RWO) PV 的部署,则 pod 可能会在同一节点上在一起。
5.7.2. 将 Deployment 修改为区域 Aware 复制链接链接已复制到粘贴板!
目前,file-uploader Deployment 不是区域感知型,它可以调度同一区域中的所有 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
将部署缩减为零个容器集,然后重新扩展到四个容器集。这是必要的,因为部署在 pod 的放置方面发生了变化。
- 缩减至零个 pod
$ oc scale deployment file-uploader --replicas=0 -n my-shared-storage输出示例:
deployment.apps/file-uploader scaled- 扩展到四个 pod
$ oc scale deployment file-uploader --replicas=4 -n my-shared-storage输出示例:
deployment.apps/file-uploader scaled
验证这四个容器集分散到 datacenter1 和 datacenter2 区域中的四个节点上。
$ 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 的简单文件上传工具
- 单击 已上传文件列表,以查看所有当前上传的文件的列表。
OpenShift Container Platform 镜像 registry、入口路由和监控服务不被区识别