首页 > 解决方案 > 无法使用 Ingress SubPath 访问 GUI

问题描述

此问题也已发布到 Gitlab 论坛。 https://forum.gitlab.com/t/unable-to-access-the-gui-with-ingress-subpath/32269 我认为即使在 StackOverFlow 上也会被专家阅读,所以我会发布它。请允许重复发布。


我想在 AWS EKS 上构建 GitLab CE 并使用 Ingress 中设置的子路径访问 GUI。如果hostingress 设置为/,则可以正常访问,如果不是/,例如/gitlab无法访问。使用 Nginx 入口控制器。

我该如何解决?

先感谢您。

附上以下内容作为参考信息。

版本

Nginx-Ingress-Controller 设置

kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/mandatory.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/aws/service-l4.yaml
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/master/deploy/static/provider/aws/patch-configmap-l4.yaml

GitLab CE 部署/服务/ConfigMap yaml

apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: kompose --file docker-compose.yml convert
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: gitlab
  name: gitlab
spec:
  ports:
  - name: "12080"
    port: 12080
    targetPort: 80
  selector:
    io.kompose.service: gitlab
  type: ClusterIP
status:
  loadBalancer: {}
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: kompose --file docker-compose.yml convert
    kompose.version: 1.17.0 (a74acad)
  creationTimestamp: null
  labels:
    io.kompose.service: gitlab
  name: gitlab
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      creationTimestamp: null
      labels:
        io.kompose.service: gitlab
    spec:
      containers:
      - envFrom:
        - configMapRef:
            name: gitlab-deployment-env-config
        image: gitlab/gitlab-ce:latest
        name: gitlab
        ports:
        - containerPort: 80
        volumeMounts:
        - mountPath: /etc/gitlab
          name: gitlab-vol0
        - mountPath: /var/log/gitlab
          name: gitlab-vol1
        - mountPath: /var/opt/gitlab
          name: gitlab-vol2
        imagePullPolicy: Always
      restartPolicy: Always
      volumes:
      - name: gitlab-vol0
        hostPath:
          path: /data/gitlab/vol0
          type: DirectoryOrCreate
      - name: gitlab-vol1
        hostPath:
          path: /data/gitlab/vol1
          type: DirectoryOrCreate
      - name: gitlab-vol2
        hostPath:
          path: /data/gitlab/vol2
          type: DirectoryOrCreate
status: {}
apiVersion: v1
kind: ConfigMap
metadata:
  name: gitlab-deployment-env-config
data:
  GITLAB_OMNIBUS_CONFIG: |
    gitlab_rails['initial_root_password'] = "password"
    unicorn['worker_processes'] = 3
    postgresql['shared_buffers'] = "512MB"

入口 yaml

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: test-ingress
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
  rules:
    # host:
    - http:
        paths:
        - path: /gitlab(/|$)(.*)
          backend:
            serviceName: gitlab
            servicePort: 12080

这不起作用,但我将rewrite-target设置更改为/并更改path/Then you can access with GUI。

Nginx-Ingress-Controller 日志

210.148.59.67 - - [05/Dec/2019:00:44:31 +0000] "GET /gitlab HTTP/1.1" 302 158 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36" 515 0.037 [default-gitlab-12080] [] 10.0.32.140:80 158 0.040 302 0e252e1a2ac495d90790ec7d83546444

从浏览器访问/gitlab子路径时的行为

该 URL 将被重定向/gitlab/users/sign_in并显示404 Not Found在屏幕上。

这是您正在访问的 URL。

http://{{{AWS CLB DNSName}}}/gitlab

标签: nginxkubernetesgitlabnginx-ingressamazon-eks

解决方案


重定向作为应用程序的默认行为发生,然后您得到 404,因为您没有“/users/sign_in”的条目。因此,也许如果您为“/users/sign_in”添加另一个条目作为路径,它会起作用

作为解决该问题的另一种选择是在路径中使用 / 并使用主机:

spec:
  rules:
    - host: gitlab.example.com
      http:
        paths:
        - path: /
          backend:
            serviceName: gitlab
            servicePort: 12080

推荐阅读