What is the best way to inject a file into a Pod?

5/11/2020

What is the best way to inject a file into a Pod? I did it using a configMap but now I have an xml file that is bigger than 1MB so need to find some other way. The file is available in the git repository.

-- AdamU
configmap
kubernetes
kubernetes-pod

2 Answers

5/11/2020

You can store it in a volume and mount that volume into the pod.

-- Arghya Sadhu
Source: StackOverflow

5/11/2020

As @Arghya Sadhu mentioned

You can store it in a volume and mount that volume into the pod.


There was storage called gitRepo which might be the best solution for you, but as now it's deprecated.

Warning: The gitRepo volume type is deprecated. To provision a container with a git repo, mount an EmptyDir into an InitContainer that clones the repo using git, then mount the EmptyDir into the Pod’s container.

emptyDir

An emptyDir volume is first created when a Pod is assigned to a Node, and exists as long as that Pod is running on that node. As the name says, it is initially empty. Containers in the Pod can all read and write the same files in the emptyDir volume, though that volume can be mounted at the same or different paths in each Container. When a Pod is removed from a node for any reason, the data in the emptyDir is deleted forever.

Note: A Container crashing does NOT remove a Pod from a node, so the data in an emptyDir volume is safe across Container crashes.

Some uses for an emptyDir are:

  • scratch space, such as for a disk-based merge sort
  • checkpointing a long computation for recovery from crashes
  • holding files that a content-manager Container fetches while a webserver Container serves the data

By default, emptyDir volumes are stored on whatever medium is backing the node - that might be disk or SSD or network storage, depending on your environment. However, you can set the emptyDir.medium field to "Memory" to tell Kubernetes to mount a tmpfs (RAM-backed filesystem) for you instead. While tmpfs is very fast, be aware that unlike disks, tmpfs is cleared on node reboot and any files you write will count against your Container’s memory limit.

Example Pod

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /cache
      name: cache-volume
  volumes:
  - name: cache-volume
    emptyDir: {}

Check this stackoverflow answer, as it might be the solution you're looking for.


If you want to read more about storage in kubernetes take a look here:

-- jt97
Source: StackOverflow