![](/img/trans.png)
[英]How do I use a MutatingWebhook to inject a container into a Kubernetes pod on creation?
[英]How do i get hostname in the kubernetes pod
我有 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]}
}
}
嘗試使用入口 controller 添加的X-Forwarded-Host
header
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.