OpenShift中的多个路由?

huangapple go评论128阅读模式
英文:

Multiple Routes in OpenShift?

问题

我需要为托管在OpenShift中的API拥有多个主机名。(例如:host1.mycompany.com,host2.mycompany.com,host3.mycompany.com)不幸的是,我找不到一种在OpenShift项目中配置多个路由的方法。

我找到的唯一资源建议在route.yaml中列出所有路由,但使用不同的metadata.name,但这不起作用。只有列出的最后一个路由起作用。

例如,如果我们在Openshift中输入以下route.yaml:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: releasename-route
spec:
  host: host1.mycompany.com
  port:
    targetPort: http
  to:
    kind: Service
    name: releasename-service
    weight: 100
  wildcardPolicy: none

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: releasename-altroute-1
spec:
  host: host2.mycompany.com
  port:
    targetPort: http
  to:
    kind: Service
    name: releasename-service
    weight: 100
  wildcardPolicy: none

最终在OpenShift中只会出现host2.mycompany.com这个路由。

我们无法使用"wildcardPolicy: subdomain",因为我们的公司受到了限制(我们只需要这三个主机名,而不是所有子域名...)

在OpenShift中如何设置这个呢?

英文:

I need to have multiple hostnames for an API being hosted in OpenShift. (e.g. host1.mycompany.com, host2.mycompany.com, host3.mycompany.com) Unfortunately I can't find a way to configure multiple routes for an OpenShift project.

The only resources I've found say to list all the routes in route.yaml, with different metadata.name but this doesn't work. Only the last listed route works.

For example if we enter the following route.yaml in Openshift:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: releasename-route
spec:
  host: host1.mycompany.com
  port:
    targetPort: http
  to:
    kind: Service
    name: releasename-service
    weight: 100
  wildcardPolicy: none
apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: releasename-altroute-1
spec:
  host: host2.mycompany.com
  port:
    targetPort: http
  to:
    kind: Service
    name: releasename-service
    weight: 100
  wildcardPolicy: none

the only route that ends up in Openshift is host2.mycompany.com

We can't use "wildcardPolicy: subdomain" because our company has that restricted (and we only need the three hostnames, not all the subdomains...)

How can we set this up in OpenShift?

答案1

得分: 2

如果您创建多个路由,它绝对可以正常工作。

在您的YAML清单中,您使用了错误的语法。如果要在单个文件中包含多个YAML文档,它们需要用YAML文档分隔符---分开:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: releasename-route
spec:
  host: host1.mycompany.com
  port:
    targetPort: http
  to:
    kind: Service
    name: releasename-service
    weight: 100
  wildcardPolicy: none
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: releasename-altroute-1
spec:
  host: host2.mycompany.com
  port:
    targetPort: http
  to:
    kind: Service
    name: releasename-service
    weight: 100
  wildcardPolicy: none

或者,只需将它们保留在不同的文件中,并分别应用它们,或者将它们放入一个目录中,然后使用kubectl apply应用该目录:

$ tree routes
routes
├── route1.yaml
└── route2.yaml
$ kubectl apply -f routes
route.route.openshift.io/route1 created
route.route.openshift.io/route2 created
英文:

If you create multiple routes it absolutely works.

You're using erroneous syntax in your YAML manifest. If you want to include multiple YAML documents in a single file, they need to be separated by the YAML document separator, ---:

apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: releasename-route
spec:
  host: host1.mycompany.com
  port:
    targetPort: http
  to:
    kind: Service
    name: releasename-service
    weight: 100
  wildcardPolicy: none
---
apiVersion: route.openshift.io/v1
kind: Route
metadata:
  name: releasename-altroute-1
spec:
  host: host2.mycompany.com
  port:
    targetPort: http
  to:
    kind: Service
    name: releasename-service
    weight: 100
  wildcardPolicy: none

Alternately, just keep them in different files and apply them separately, or put them in a directory and apply the directory using kubectl apply:

$ tree routes
routes
├── route1.yaml
└── route2.yaml
$ kubectl apply -f routes
route.route.openshift.io/route1 created
route.route.openshift.io/route2 created

huangapple
  • 本文由 发表于 2023年6月9日 03:48:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76435256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定