我需要使用一個使用 k8s 入口的開放埠基于 URL 為 gitlab、nexus 和 jupyterhub 提供服務。
如果創建入口的時候路徑寫成“/”,可以正常作業,但是如果這樣寫“/nexus”,在重定向程序中就會出現問題。
你們中有人解決過同樣的問題嗎?請幫忙。

我的 ingress.yaml 如下
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /$2
creationTimestamp: "2022-04-06T05:56:40Z"
generation: 7
name: nexus-ing
namespace: nexus
resourceVersion: "119075924"
selfLink: /apis/extensions/v1beta1/namespaces/nexus/ingresses/nexus-ing
uid: 4b4f97e4-225e-4faa-aba3-6af73f69c21d
spec:
ingressClassName: nginx
rules:
- http:
paths:
- backend:
serviceName: nexus-service
servicePort: 8081
path: /nexus(/|$)(.*)
pathType: ImplementationSpecific
status:
loadBalancer:
ingress:
- ip: 172.30.1.87
uj5u.com熱心網友回復:
這是nexus本身的問題。你的入口按預期作業,你不能從這方面做更多的事情。
這里的問題是nexus 網頁,即index.html,以這樣一種方式請求資源,它正在尋找錯誤的地方。您可以通過打開網路選項卡并檢查缺少的靜態資料的請求 URL 來查看這一點。
要明白我的意思,讓我們檢查下面的 HTML 影像標簽。
<img id="1" src="./statics/some-image.svg" alt="some image" />
<img id="2" src="/statics/some-image.svg" alt="some image" />
您可以看到第一個使用相對路徑,并且可以與您的配置一起使用,因為請求 URL 將相對于瀏覽器中的位置,然后連接部分被入口控制器剝離。
但是,第二個是使用絕對路徑,因此請求 URL 中不會包含 nexus 部分,并且入口控制器將無法將其路由到正確的服務。
這是剝離路徑前綴時的常見問題。只有在正確配置了您在剝離前綴時所服務的應用程式時,它才能完全作業。
在您的情況下,這意味著檢查服務的檔案,如果您有任何影響它的方法。
基于主機名而不是路徑進行路由可能更直接。即 nexus.myhost.com。為此,您需要一個域并將相應的 A 記錄指向您的入口服務 IP / 使用通配符記錄。
uj5u.com熱心網友回復:
我自己解決了這個問題
- 我編輯了我的電腦主機檔案
172.30.1.87 nexus.k8s.io
172.30.1.87 gitlab.k8s.io
- 我在同一個服務命??名空間中編輯了每個 Ingress
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
namespace: nexus
spec:
ingressClassName: nginx
rules:
- host: nexus.k8s.io
http:
paths:
- backend:
serviceName: nexus-service
servicePort: 8081
path: /
status:
loadBalancer:
ingress:
- ip: 172.30.1.87
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
name: gitlab-ingress
namespace: gitlab
spec:
ingressClassName: nginx
rules:
- host: gitlab.k8s.io
http:
paths:
- backend:
serviceName: gitlab-webservice
servicePort: 8181
path: /
status:
loadBalancer:
ingress:
- ip: 172.30.1.87
- 連接測驗入口主機名 入口控制器節點埠


轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/457714.html
