一个入口名称具有多个规则
one ingress name having multiple rules
我想在一个入口名称下使用多个规则。
{
"kind": "Ingress",
"spec": {
"rules": [
{
"host": "gke-service-xyz.com",
"http": {
"paths": [
{
"path": "/",
"backend": {
"serviceName": "gke-service",
"servicePort": 8080
}
}
]
}
},
{
"host": "gke-service1-xyz.com",
"http": {
"paths": [
{
"path": "/",
"backend": {
"serviceName": "gke-service1",
"servicePort": 8081
}
}
]
}
}
]
},
"apiVersion": "extensions/v1beta1",
"metadata": {
"annotations": {
"kubernetes.io/ingress.class": "nginx",
"nginx.ingress.kubernetes.io/ssl-redirect": "false"
},
"name": "javaservice1-ingress"
},
"namespace": "abc-namespace"
}
YAML 代码
kind: Ingress
spec:
rules:
- host: gke-service-xyz.com
http:
paths:
- path: "/"
backend:
serviceName: gke-service
servicePort: 8080
- host: gke-service1-xyz.com
http:
paths:
- path: "/"
backend:
serviceName: gke-service1
servicePort: 8081
apiVersion: extensions/v1beta1
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
name: javaservice1-ingress
namespace: abc-namespace
这里的问题是第一个入口主机工作正常,但在获取第二个入口主机时无法正常工作,并且显示 503 服务暂时不可用。我希望两个主机都处于工作状态。有什么办法可以达到同样的目的吗?
- 入口名称:服务入口。
- gke-服务-xyz.com
- gke-service1-xyz.com
上面的点 1 和 2 是入口端点,两者都应该工作,但这里只有 1 个在工作。
以上两个 YAML 代码均无效。
试试这个 -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
name: staging-ingress
spec:
rules:
- host: gke-service-xyz.com
http:
paths:
- path: /(.*)
backend:
serviceName: gke-service
servicePort: 8080
- path: /api/(.*)
backend:
serviceName: gke-service1
servicePort: 8081
你问的问题是你只想拥有一个域并用它来路由到两个服务,因此你可以使用类似 URL 重写的东西
我想在一个入口名称下使用多个规则。
{
"kind": "Ingress",
"spec": {
"rules": [
{
"host": "gke-service-xyz.com",
"http": {
"paths": [
{
"path": "/",
"backend": {
"serviceName": "gke-service",
"servicePort": 8080
}
}
]
}
},
{
"host": "gke-service1-xyz.com",
"http": {
"paths": [
{
"path": "/",
"backend": {
"serviceName": "gke-service1",
"servicePort": 8081
}
}
]
}
}
]
},
"apiVersion": "extensions/v1beta1",
"metadata": {
"annotations": {
"kubernetes.io/ingress.class": "nginx",
"nginx.ingress.kubernetes.io/ssl-redirect": "false"
},
"name": "javaservice1-ingress"
},
"namespace": "abc-namespace"
}
YAML 代码
kind: Ingress
spec:
rules:
- host: gke-service-xyz.com
http:
paths:
- path: "/"
backend:
serviceName: gke-service
servicePort: 8080
- host: gke-service1-xyz.com
http:
paths:
- path: "/"
backend:
serviceName: gke-service1
servicePort: 8081
apiVersion: extensions/v1beta1
metadata:
annotations:
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/ssl-redirect: 'false'
name: javaservice1-ingress
namespace: abc-namespace
这里的问题是第一个入口主机工作正常,但在获取第二个入口主机时无法正常工作,并且显示 503 服务暂时不可用。我希望两个主机都处于工作状态。有什么办法可以达到同样的目的吗?
- 入口名称:服务入口。
- gke-服务-xyz.com
- gke-service1-xyz.com
上面的点 1 和 2 是入口端点,两者都应该工作,但这里只有 1 个在工作。 以上两个 YAML 代码均无效。
试试这个 -
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
kubernetes.io/ingress.class: nginx
name: staging-ingress
spec:
rules:
- host: gke-service-xyz.com
http:
paths:
- path: /(.*)
backend:
serviceName: gke-service
servicePort: 8080
- path: /api/(.*)
backend:
serviceName: gke-service1
servicePort: 8081
你问的问题是你只想拥有一个域并用它来路由到两个服务,因此你可以使用类似 URL 重写的东西