Search code examples
dockerkubernetesnexushaproxy-ingress

Ingress for Nexus Docker repository hosted on Kubernetes


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.


Solution

  • 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