Igor Rabkin
Igor Rabkin

Reputation: 95

Can't enable images deletion from a private docker registry

all!! I'm deploying private registry within K8S cluster with following yaml file:

kind: PersistentVolume
apiVersion: v1
metadata:
  name: registry
  labels:
    type: local
spec:
  capacity:
    storage: 4Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/data/registry/"

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: registry-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 4Gi
---

apiVersion: v1
kind: Service
metadata:
  name: registry
  labels:
    app: registry
spec:
  ports:
    - port: 5000
      targetPort: 5000
      nodePort: 30400
      name: registry
  selector:
    app: registry
    tier: registry
  type: NodePort
---

apiVersion: v1
kind: Service
metadata:
  name: registry-ui
  labels:
    app: registry
spec:
  ports:
    - port: 8080
      targetPort: 8080
      name: registry
  selector:
    app: registry
    tier: registry
  type: NodePort
---

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  name: registry
  labels:
    app: registry
spec:
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: registry
        tier: registry
    spec:
      containers:
      - image: registry:2
        name: registry
        volumeMounts:
        - name: docker
          mountPath: /var/run/docker.sock
        - name: registry-persistent-storage
          mountPath: /var/lib/registry
        ports:
        - containerPort: 5000
          name: registry

      - name: registryui
        image: hyper/docker-registry-web:latest
        ports:
        - containerPort: 8080
        env:
        - name: REGISTRY_URL
          value: http://localhost:5000/v2
        - name: REGISTRY_NAME
          value: cluster-registry
      volumes:
      - name: docker
        hostPath:
          path: /var/run/docker.sock
      - name: registry-persistent-storage
        persistentVolumeClaim:
          claimName: registry-claim

I'm just wondering that there is no option to delete docker images after pushing them to the local registry. I found the way how it suppose to work here: https://github.com/byrnedo/docker-reg-tool. I can list docker images inside local repository, see all tags via command line, but unable delete them. After reading the docker registry documentation, I've found that registry docker need to be run with following env: REGISTRY_STORAGE_DELETE_ENABLED=true. I tried to add this variable into yaml file:

.........
    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: registry
      labels:
        app: registry
    spec:
      strategy:
        type: Recreate
      template:
        metadata:
          labels:
            app: registry
            tier: registry
        spec:
          containers:
          - image: registry:2
            name: registry
            volumeMounts:
            - name: docker
              mountPath: /var/run/docker.sock
            - name: registry-persistent-storage
              mountPath: /var/lib/registry
            ports:
            - containerPort: 5000
              name: registry
            env:
            - name: REGISTRY_STORAGE_DELETE_ENABLED
              value: true

But applying this yaml file with command kubectl apply -f manifests/registry.yaml return following error message:

Deployment in version "v1beta1" cannot be handled as a Deployment: v1beta1.Deployment.Spec: v1beta1.DeploymentSpec.Template: v1.PodTemplateSpec.Spec: v1.PodSpec.Containers: []v1.Container: v1.Container.Env: []v1.EnvVar: v1.EnvVar.Value: ReadString: expects " or n, but found t, error found in #10 byte of ...|,"value":true}],"ima|..., bigger context ...|"name":"REGISTRY_STORAGE_DELETE_ENABLED","value":true}],"image":"registry:2","name":"registry","port|...

After I find another suggestion:

The registry accepts configuration settings either via a file or via environment variables. So the environment variable REGISTRY_STORAGE_DELETE_ENABLED=true is equivalent to this in your config file:

storage:
  delete:
    enabled: true

I've tried this option as well in my yaml file but still no luck... Any suggestions how to enable docker images deletion in my yaml file are highly appreciated.

Upvotes: 1

Views: 871

Answers (1)

BMitch
BMitch

Reputation: 263617

The value of true in yaml is parsed into a boolean data type and the syntax calls for a string. You'll need to explicitly quote it:

value: "true"

Upvotes: 2

Related Questions