Skip to content

Instantly share code, notes, and snippets.

@cemtopkaya
Created September 25, 2024 22:09
Show Gist options
  • Save cemtopkaya/607c0bc8edc65ce252f9c5de405290cb to your computer and use it in GitHub Desktop.
Save cemtopkaya/607c0bc8edc65ce252f9c5de405290cb to your computer and use it in GitHub Desktop.
tmpfs İle init container desenine göre dosya paylaşımı
version: "3.8"
volumes:
cache_vol:
driver_opts:
type: tmpfs
device: tmpfs
services:
init-container:
image: busybox
entrypoint: ["sh", "-c", "echo 'some data' > /config_1/shared-file"]
volumes:
- cache_vol:/config_1
main-container:
image: busybox
entrypoint: ["sh", "-c", "cat /config_1/shared-file"]
volumes:
- cache_vol:/config_1
depends_on:
- init-container
@cemtopkaya
Copy link
Author

Eğer entrypoint: ["sh", "-c", "echo 'some data' > /config_1/shared-file && echo 'done'"] satırıyla init-container başlatılırsa ekran çıktısı şöyle olur ve anlarız ki init bitmiş main başlamış ve bitmiş.
image

@cemtopkaya
Copy link
Author

Kubernetes içinde koşabilen hali:

apiVersion: v1
kind: Pod
metadata:
  name: tmpfs-pod
spec:
  containers:
  - name: init-container
    image: busybox
    command: ["sh", "-c", "echo 'some data' > /config_1/shared-file && sleep 60"]
    volumeMounts:
    - name: cache-vol
      mountPath: /config_1

  - name: main-container
    image: busybox
    command: ["sh", "-c", "cat /config_1/shared-file"]
    volumeMounts:
    - name: cache-vol
      mountPath: /config_1

  volumes:
  - name: cache-vol
    emptyDir:
      medium: Memory  # emptyDir ile tmpfs kullanarak RAM üzerinde dosya saklanır

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment