部署MongoDB数据库
- 创建项目
$ oc new-project multitiered-app
- 部署MongoDB
$ oc new-app mongodb-ephemeral -l app.openshift.io/runtime=mongodb, app.kubernetes.io/part-of=multi-tiered-app
部署应用后端
- 部署kiosk-backend模块。
$ oc new-app https://github.com/RedHatWorkshops/openshiftv4-odo-workshop-backend.git --name=kiosk-backend \
-l app.openshift.io/runtime=nodejs, app.kubernetes.io/part-of=multi-tiered-app
- 在kiosk-backend和mongodb之间建立关联。
$ oc annotate deployment/kiosk-backend app.openshift.io/connects-to=mongodb
- 修改kiosk-backend访问mongodb的配置参数。
$ oc patch deployment/kiosk-backend --type='json' -p='[{"op": "add", "path": "/spec/template/spec/containers/0/env", "value": [ { "name": "username", "valueFrom": { "secretKeyRef": { "name": "mongodb", "key": "database-user" } } },{ "name": "password", "valueFrom": { "secretKeyRef": { "name": "mongodb", "key": "database-password" } } },{ "name": "database_name", "valueFrom": { "secretKeyRef": { "name": "mongodb", "key": "database-name" } } },{ "name": "admin_password", "valueFrom": { "secretKeyRef": { "name": "mongodb", "key": "database-admin-password" } } } ] }]'
部署应用前端
- 部署前端应用kiosk-frontend。
$ oc new-app https://github.com/RedHatWorkshops/openshiftv4-odo-workshop.git --name=kiosk-frontend \
-l app.openshift.io/runtime=nodejs, app.kubernetes.io/part-of=multi-tiered-app \
-e COMPONENT_BACKEND_HOST=$(oc get svc kiosk-backend --template={{.spec.clusterIP}}) \
-e COMPONENT_BACKEND_PORT=$(oc get svc kiosk-backend -o=jsonpath='{ .spec.ports[?(@.name == "8080-tcp")].targetPort }')
- 在kiosk-frontend和kiosk-backend之间建立关联。
$ oc annotate deployment/kiosk-frontend app.openshift.io/connects-to=kiosk-backend
- 根据Service生成Route
$ oc expose svc kiosk-frontend
- 在OpenShift控制台查看部署的应用资源。
测试应用
访问上图中的Route链接,设置需要购买的数量,然后提交,可以看到订单记录。