Warm tip: This article is reproduced from serverfault.com, please click

Ingress for Nexus Docker repository hosted on Kubernetes

发布于 2020-11-01 20:21:59

I just deploy a nexus repository to a kubernetes cluster. This nexus have 3 docker repository. One proxy of docker hub, one private and one that group both previous.

I use haproxy as ingress controller. Is it possible to deploy an ingress that match the configuration describe here ? Nexus3: Push to Docker Group Repo

My goal is to have only one url to push and pull to docker repository.

Questioner
Scandinave
Viewed
0
Scandinave 2020-12-03 16:59:04

I post here my solution. I use custom annotation to achieve rooting to correct endpoint base on the requested url.

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: nexus-ingress-docker
  annotations:
    kubernetes.io/ingress.class: nginx
    nginx.org/client-max-body-size: "1G"
    nginx.org/proxy-buffering: "off"
    nginx.org/server-snippets: |
      location ~ ^/(v1|v2)/[^/]+/?[^/]+/blobs/ {
        if ($request_method ~* (POST|PUT|DELETE|PATCH|HEAD) ) {
            rewrite ^/(.*)$ /repository/docker-private/$1 last;
        }
        rewrite ^/(.*)$ /repository/docker-public/$1 last;
      }

      location ~ ^/(v1|v2)/ {
        if ($request_method ~* (POST|PUT|DELETE|PATCH) ) {
            rewrite ^/(.*)$ /repository/docker-private/$1 last;
        }
        rewrite ^/(.*)$ /repository/docker-public/$1 last;
      }
    nginx.org/location-snippets: |
      proxy_set_header X-Forwarded-Proto https;


spec:
  ingressClassName: nginx
  rules:
    - host: my-host
      http:
        paths:
          - backend:
              service:
                name: nexus
                port:
                  name: nexus
            path: /
            pathType: Prefix

And the service :

apiVersion: v1
kind: Service
metadata:
  name: nexus
  labels:
    app: nexus
spec:
  type: ClusterIP
  ports:
    - port: 8081
      name: nexus
    - port: 8082
      name: docker-private
    - port: 8083
      name: docker-public
  selector:
    app: nexus