【发布时间】:2021-07-23 03:48:56
【问题描述】:
我有 3 个入口指向同一个服务。在我的 kubernetes pod 中,我如何找到主机名以及来自哪个子域的请求。我在 golang 服务器中的后端代码。
当请求到达任何 pod 时,我想知道从哪个子域(x,y,x)请求到达 pod。目前在 golang 代码中,它提供主机名作为 pod ip 地址
kind: Ingress
metadata:
annotations:
ingress.kubernetes.io/browser-xss-filter: 'true'
ingress.kubernetes.io/force-hsts: 'true'
ingress.kubernetes.io/hsts-include-subdomains: 'true'
ingress.kubernetes.io/hsts-max-age: '315360000'
name: test
namespace: test
spec:
rules:
- host: http://x.test.com
http:
paths:
- backend:
serviceName: test-service
servicePort: 8080
path: /
- host: http://y.test.com
http:
paths:
- backend:
serviceName: test-service
servicePort: 8080
path: /
- host: http://z.test.com
http:
paths:
- backend:
serviceName: test-service
servicePort: 8080
path: /
func Subdomain( r *http.Request) {
host := r.URL.Host
host = strings.TrimSpace(host)
//Figure out if a subdomain exists in the host given.
host_parts := strings.Split(host, ".")
if len(host_parts) > 2 {
//The subdomain exists, we store it as the first element
//in a new array
subdomain := []string{host_parts[0]}
}
}
【问题讨论】:
标签: go kubernetes kubernetes-ingress gorilla