concourse / concourse

Concourse is a container-based continuous thing-doer written in Go.
https://concourse-ci.org
Apache License 2.0
7.4k stars 847 forks source link

Spike: Can we take a rootfs.tgz and run it in K8s without uploading it to a registry #3757

Open chenbh opened 5 years ago

chenbh commented 5 years ago

One of the ways Concourse creates containers is directly from a rootfs.tgz. If we want to consider https://github.com/concourse/rfcs/pull/22 we would need a way to get k8s to create and run our image without having to upload it to a registry

chenbh commented 5 years ago

Turns out it wasn't hard at all. It just involves init containers and mounting the docker socket of the host (node) to the container. We can then use the docker CLI from inside the container to communicate with the daemon running on the node.

Notes:

apiVersion: batch/v1
kind: Job
metadata:
  name: offline-images
spec:
  template:
    spec:
      initContainers:
      - name: upload-it
        image: gcr.io/cf-concourse-production/uploader
        command: [ "docker", "import", "/rootfs.tgz", "local-image" ]
        # command: [ "docker", "image", "load", "-i", "/image.tgz" ]
        volumeMounts:
        - name: dockersock
          mountPath: /var/run/docker.sock

      containers:
      - name: use-it
        image: local-image
        imagePullPolicy: IfNotPresent
        command: [ "sh", "-c", "ls -l /boo" ]

      restartPolicy: Never
      volumes:
      - name: dockersock
        hostPath:
          path: /var/run/docker.sock

Further exploration

What about other k8s container engines (https://kubedex.com/kubernetes-container-runtimes/)?

chenbh commented 5 years ago

Figure out how image caching in k8s work, how long do they last? Do we have to clear cache manually?

Should be built in: https://kubernetes.io/docs/concepts/cluster-administration/kubelet-garbage-collection/