《OpenShift 4.x HOL教程汇总》
说明:本文已经在OpenShift 4.6环境中验证
本文部署4个应用,我们将使用相同的域名和不同的路径来访问它们。
- 创建项目并部署4个应用。
$ oc new-project myholiday
$ oc new-app https://github.com/liuxiaoyu-git/workshop4.git --context-dir=attendee/myholiday \
--name=short-holiday -l app.kubernetes.io/part-of=holidays HOLIDAY_TYPE=short-break
$ oc new-app https://github.com/liuxiaoyu-git/workshop4.git --context-dir=attendee/myholiday \
--name=package-holiday -l app.kubernetes.io/part-of=holidays HOLIDAY_TYPE=package
$ oc new-app https://github.com/liuxiaoyu-git/workshop4.git --context-dir=attendee/myholiday \
--name=cruise-holiday -l app.kubernetes.io/part-of=holidays HOLIDAY_TYPE=cruise
$ oc new-app https://github.com/liuxiaoyu-git/workshop4.git --context-dir=attendee/myholiday \
--name=adventure-holiday -l app.kubernetes.io/part-of=holidays HOLIDAY_TYPE=adventure
- 查看应用的build。
$ oc get build
NAME TYPE FROM STATUS STARTED DURATION
short-holiday-1 Source Git@71f1426 Complete 20 minutes ago 1m1s
package-holiday-1 Source Git@71f1426 Complete 20 minutes ago 1m4s
cruise-holiday-1 Source Git@71f1426 Complete 20 minutes ago 1m12s
adventure-holiday-1 Source Git@71f1426 Complete 20 minutes ago 1m6s
- 查看生成的Service。
$ oc get svc
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
adventure-holiday ClusterIP 172.30.42.48 <none> 8080/TCP 48m
cruise-holiday ClusterIP 172.30.135.169 <none> 8080/TCP 48m
package-holiday ClusterIP 172.30.119.103 <none> 8080/TCP 48m
short-holiday ClusterIP 172.30.135.218 <none> 8080/TCP 48m
- 获取统一的应用访问地址,然后根据它生成Route。
$ HOLIDY_HOST=$(oc project -q).apps.$(oc whoami --show-server | cut -d"." -f2- | cut -d":" -f1)
$ oc expose svc adventure-holiday --hostname="${HOLIDY_HOST}" --path="/adventure"
$ oc expose svc cruise-holiday --hostname="${HOLIDY_HOST}" --path="/cruise"
$ oc expose svc package-holiday --hostname="${HOLIDY_HOST}" --path="/package"
$ oc expose svc short-holiday --hostname="${HOLIDY_HOST}" --path="/short"
- 查看4个访问应用的Route。
$ oc get route
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
adventure-route myholiday.apps.cluster-shanxi-db26.shanxi-db26.sandbox1438.opentlc.com /adventure adventure-holiday <all> None
cruise-route myholiday.apps.cluster-shanxi-db26.shanxi-db26.sandbox1438.opentlc.com /cruise cruise-holiday <all> None
package-route myholiday.apps.cluster-shanxi-db26.shanxi-db26.sandbox1438.opentlc.com /package package-holiday <all> None
short-holiday-route myholiday.apps.cluster-shanxi-db26.shanxi-db26.sandbox1438.opentlc.com /short-break short-holiday <all> None
- 根据URL访问4个应用。
$ curl ${HOLIDY_HOST}/adventure
$ curl ${HOLIDY_HOST}/cruise
$ curl ${HOLIDY_HOST}/package
$ curl ${HOLIDY_HOST}/short-break