自动重定向:HTTP 重定向到 HTTPS
在 Ingress YAML 中配置如下注解:
ingress.cloud.tencent.com/auto-rewrite: "true"
配置该注解之后,转发路径中的所有 HTTPS 监听器中存在的七层转发规则都将被对应到 HTTP 监听器中作为重定向规则。域名与路径都保持一致。
手动重定向
手动重定向需要增加一个 annotation ,修改一个 annotation:
- 增加的 annotation:
ingress.cloud.tencent.com/rewrite-support: "true"
- 修改的 annotation:
{
"host": "<domain>",
"path": "<path>",
"backend": {
"serviceName": "<service name="">",
"servicePort": "<service port="">"
}
}
{
"host": "<domain>",
"path": "<path>",
"backend": {
"serviceName": "<service name="">",
"servicePort": "<service port="">"
},
"rewrite": {
"port": "<rewrite-port>",
"host": "<rewrite-domain>",
"path": "<rewrite-path>"
}
}
示例
某服务之前通过 121.4.25.44/path2
进行访问,在发布新版本之后,期望通过 121.4.25.44/v2/path2
进行访问。可以进行如下修改:
- 增加一条 annotation:
ingress.cloud.tencent.com/rewrite-support: "true"
- 修改原 annotation:
kubernetes.io/ingress.http-rules: '
[{
"path": "/path1",
"backend": {
"serviceName": "path1",
"servicePort": "80"
}
},
{
"path": "/path2",
"backend": {
"serviceName": "path2",
"servicePort": "80"
}
},
{
"path": "/v1/path1",
"rewrite": {
"port": 80,
"path": "/path1"
}
},
{
"path": "/v2/path2",
"rewrite": {
"port": 80,
"path": "/path2"
}
}
]'
修改后的 YAML:
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
description: test
ingress.cloud.tencent.com/rewrite-support: "true"
kubernetes.io/ingress.class: qcloud
kubernetes.io/ingress.http-rules: '[{"path":"/path1","backend":{"serviceName":"path1","servicePort":"80"}},{"path":"/path2","backend":{"serviceName":"path2","servicePort":"80"}},{"path":"/v1/path1","rewrite":{"port":80,"path":"/path1"}},{"path":"/v2/path2","rewrite":{"port":80,"path":"/path2"}}]'
kubernetes.io/ingress.https-rules: "null"
kubernetes.io/ingress.rule-mix: "true"
name: test
namespace: default
spec:
rules:
- http:
paths:
- backend:
serviceName: path1
servicePort: 80
path: /path1
pathType: ImplementationSpecific
- http:
paths:
- backend:
serviceName: path2
servicePort: 80
path: /path2
pathType: ImplementationSpecific
status:
loadBalancer:
ingress:
- ip: 121.4.25.44
完整 Ingress Annotation 说明请参见 Ingress Annotation 说明 文档。
本页内容是否解决了您的问题?