OpenShift 4 - 基于URL的应用路由

OpenShift 4.x HOL教程汇总
说明:本文已经在OpenShift 4.6环境中验证

本文部署4个应用,我们将使用相同的域名和不同的路径来访问它们。
在这里插入图片描述

  1. 创建项目并部署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
  1. 查看应用的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
  1. 查看生成的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
  1. 获取统一的应用访问地址,然后根据它生成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"
  1. 查看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
  1. 根据URL访问4个应用。
$ curl ${HOLIDY_HOST}/adventure
$ curl ${HOLIDY_HOST}/cruise
$ curl ${HOLIDY_HOST}/package
$ curl ${HOLIDY_HOST}/short-break
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值