Ingress for Nexus Docker repository hosted on Kubernetes

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

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top