4.6. 部署 Python 应用程序
以下流程为 parksmap
应用程序部署后端服务。Python 应用程序针对 MongoDB 数据库执行 2D geo-spatial 查询,以定位和返回世界上的所有国家公园的信息。
部署的后端服务是 nationalparks
。
先决条件
- 有访问 OpenShift Container Platform 集群的权限。
-
已安装 OpenShift CLI(
oc
)。 - 您已部署了一个镜像。
流程
要创建新 Python 应用程序,请输入以下命令:
$ oc new-app python~https://github.com/openshift-roadshow/nationalparks-py.git --name nationalparks -l 'app=national-parks-app,component=nationalparks,role=backend,app.kubernetes.io/part-of=national-parks-app,app.kubernetes.io/name=python' --allow-missing-images=true
输出示例
--> Found image 0406f6c (13 days old) in image stream "openshift/python" under tag "3.9-ubi8" for "python" Python 3.9 ---------- Python 3.9 available as container is a base platform for building and running various Python 3.9 applications and frameworks. Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python's elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms. Tags: builder, python, python39, python-39, rh-python39 * A source build using source code from https://github.com/openshift-roadshow/nationalparks-py.git will be created * The resulting image will be pushed to image stream tag "nationalparks:latest" * Use 'oc start-build' to trigger a new build --> Creating resources with label app=national-parks-app,app.kubernetes.io/name=python,app.kubernetes.io/part-of=national-parks-app,component=nationalparks,role=backend ... imagestream.image.openshift.io "nationalparks" created buildconfig.build.openshift.io "nationalparks" created deployment.apps "nationalparks" created service "nationalparks" created --> Success
要创建公开应用程序
nationalparks
的路由,请使用以下命令:$ oc create route edge nationalparks --service=nationalparks
输出示例
route.route.openshift.io/parksmap created
要检索创建的应用程序路由,请输入以下命令:
$ oc get route
输出示例
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD nationalparks nationalparks-user-getting-started.apps.cluster.example.com nationalparks 8080-tcp edge None parksmap parksmap-user-getting-started.apps.cluster.example.com parksmap 8080-tcp edge None
其他资源