Kubernetes: is it good practice to share the /tmp folder between containers

6/20/2018

In most situations, my web applications do not assume /tmp will exist between requests. However certain web application projects write to /tmp, and then read the results in the following request, which can cause issues if a web application is not served from a single container or server. If I am moving to Kubernetes, is it generally considered a good practice to share the /tmp directory between containers, or is it better to move toward assuming that /tmp will change from one call to another.

-- alberto56
kubernetes

1 Answer

6/21/2018

It isn't a good practice to share your /tmp folder between containers, but you can create a persistent volume with read-write-many permission:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv0003
spec:
  capacity:
    storage: 5Gi
  volumeMode: Filesystem
  accessModes:
    - ReadWriteMany
  persistentVolumeReclaimPolicy: Recycle
  storageClassName: slow
  mountOptions:
    - hard
    - nfsvers=4.1
  nfs:
    path: /tmp
    server: 172.17.0.2

and use it.

More information on how to use volumes you could find in documentation.

-- Nick Rak
Source: StackOverflow