Pre-populating Local SSD disk in GCP Kubernetes for readonly multipods usage

9/7/2018

What is the best way to preload large files into a local PersistentVolume SSD before it gets used by Kubernetes pods?

The goal is to have multiple pods (could be multiple instances of the same pod, or different), share the same local SSD drive in a read-only mode. The drive would need to be initialized somehow with a large dataset.

Google Local SSD docs describes the Running the local volume static provisioner, but that approach only creates a PersistedVolume, but does not initialize it.

-- Yurik
google-kubernetes-engine
kubernetes

1 Answer

9/7/2018

Basically, you can add an init container to your pod that initializes the SSD: add data, etc.

apiVersion: v1
kind: Pod
metadata:
  name: "test-ssd"
spec:
  initContainers:
  - name: "init"
    image: "ubuntu:14.04"
    command: ["/bin/init_my_ssd.ssh"]
    volumeMounts:
    - mountPath: "/test-ssd/"
      name: "test-ssd:
  containers:
  - name: "shell"
    image: "ubuntu:14.04"
    command: ["/bin/sh", "-c"]
    args: ["echo 'hello world' > /test-ssd/test.txt && sleep 1 && cat /test-ssd/test.txt"]
    volumeMounts:
    - mountPath: "/test-ssd/"
      name: "test-ssd"
  volumes:
  - name: "test-ssd"
    hostPath:
      path: "/mnt/disks/ssd0"
  nodeSelector:
    cloud.google.com/gke-local-ssd: "true"
-- Rico
Source: StackOverflow