Error pushing images to docker registry inside kubernetes and ingress

4/30/2019

I'm working on docker for desktop kubernertes installation and i want to deploy a docker registry behind ingress. I already deployed a registry and if I access to the catalog api using ingress it works. But when i try to do a push i have this error:

error parsing HTTP 404 response body: invalid character '<' looking for beginning of value: "<html>\r\n<head><title>404 Not Found</title></head>\r\n<body>\r\n<center><h1>404 Not Found</h1></center>\r\n<hr><center>nginx/1.15.11</center>\r\n</body>\r\n</html>\r\n"

This is the yaml I used fo the creation of volume, deployment and service

kind: PersistentVolume
apiVersion: v1
metadata:
  name: dev-registry-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/host_mnt/c/docker-registry/dev-registry"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: dev-registry-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: dev-registry
  namespace: default
spec:
  replicas: 1
  template:
    metadata:
      labels:
        app: dev-registry
    spec:
      containers:
        - name: dev-registry
          image: registry:2
          ports:
            - name: http-port
              containerPort: 5000
          volumeMounts:
            - name: docker-data
              mountPath: /var/lib/registry
      volumes:
        - name: docker-data
          persistentVolumeClaim:
            claimName: dev-registry-pv-claim
---
apiVersion: v1
kind: Service
metadata:
  name: dev-registry
spec:
  ports:
    - port: 5000
      targetPort: 5000   
  selector:
    app: dev-registry

and this is the ingress rule i have created

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: sudoku-ingress
  namespace: default
  annotations:
    ingress.kubernetes.io/rewrite-target: /
    nginx.ingress.kubernetes.io/proxy-body-size: "0"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
spec:
  rules:
    - host: dev-registry.sudoku.test.it
      http:
        paths:
          - backend:
              serviceName: dev-registry
              servicePort: 5000
            path: /

where dev-registry.sudoku.test.it point to the cluster ip of kubernetes. I already add the address in the insecure list of docker and if I make a get request to the url http://dev-registry.sudoku.test.it/v2/_catalog it responds correctly.

I also tried to expose the registry as a NodePort and in this case the push works correctl, so the problem is the ingress configuration. How have i to configure ingress?

I also try this https://github.com/kubernetes/ingress-nginx/tree/master/docs/examples/docker-registry but changing only the registry address it doesn't work. Any idea?

-- Luca
docker-registry
kubernetes

1 Answer

4/30/2019

The container daemon is running outside of kubernetes. Therefore it can not use the kubernetes service to access the registry. You can either use a NodePort, as you did, or you can use a regular, externally resolveable hostname that points to your ingress. (Of course you could add a host entry to the hosts.txt file as well, but I discourage that since it can cause hard to diagnose problems, if someone is not aware of that configuration.)

Another option is to use an external docker registry of course.

-- Thomas
Source: StackOverflow