1

I am new to the storage concepts in Kubernetes. I need to have some common persistent storage in the Kubernetes cluster but also to be able to write to it from outside of the cluster on-prem environment..

So my question is, Can we have some persistent storage (of a file system) in Kubernetes cluster that can be shared among different pods, and also applications from outside the Kubernetes cluster will be able to write to it? if yes, what is the proper architecture for it? how can I access that persistent storage from outside of the cluster?

if it's not possible, is there a better way to achieve my need to have some common database file system for podes in the cluster and applications outside the cluster?

Ohad
  • 1,563
  • 2
  • 20
  • 44

2 Answers2

1

Having a filesystem shared inside the cluster between multiple pods is doable with any persistent volume marked as ReadWriteMany, like a NFS. However for the NFS you will need to have a Kubernetes "addon" that manages its creation and deletion that is specific to your infrastructure.

I don't know how it will react if it is modified from outside the cluster but if what you need is just to have a database shared between the cluster an outsider application then it may be easier to have a regular database on a machine outside the cluster.

In fact you mostly want a distributed database on a kubernetes cluster for high availability, not performance, and most implementation seem to favor local storage with synchronization implemented inside the application (leader election and so on) over shared volumes.

If you want performances, you may take a look at sharding your database.

OreOP
  • 122
  • 1
  • 5
  • wouldn't it affect the performance if te database will not be part of the Kubernetes cluster? – Ohad Sep 13 '22 at 10:12
  • If you size your machine well and configure it correctly there is no reason it would be significantly slower than a DB in the cluster (but I am not a database expert so don't trust me blindly). Besides, the network part is out of the equation because you want to expose the DB both to insiders and outsiders of the cluster. – OreOP Sep 13 '22 at 10:25
0

Take look at NFS server/protocol.

You can use it as both inside the K8s cluster as nfs PersistentVolume and outside the cluster.

apiVersion: v1
kind: PersistentVolume
metadata:
  name: my-nfs-pv
spec:
  storageClassName: nfs
  accessModes:
  - ReadWriteMany
  capacity:
    storage: 10Gi
  persistentVolumeReclaimPolicy: Retain
  mountOptions: # https://linux.die.net/man/5/nfs
  - nfsvers=4.2
  - port=32049
  nfs:
    path: /exports
    server: your.nfs.server.host-or-ip
    readOnly: false

You can also use object-storage like MinIO (S3 protocol). More:

kinjelom
  • 6,105
  • 3
  • 35
  • 61
  • What do you mean by using it externally? Do you mean not as storage persistent of Kubernetes? – Ohad Sep 13 '22 at 10:10
  • yes, for example https://linuxize.com/post/how-to-mount-an-nfs-share-in-linux/ – kinjelom Sep 13 '22 at 10:57
  • Can you elaborate which approach is better for on-prem environment with my requirements to be able to write to that database also from outside the cluster? external database or internal? – Ohad Sep 13 '22 at 13:20
  • @Ohad Do you need database (relational, document,...), object-storage or network file system? Storage should be as close as possible to its main clients. – kinjelom Sep 14 '22 at 15:00
  • file system, @kinjelom – Ohad Sep 18 '22 at 07:59
  • external NFS Server @Ohad – kinjelom Sep 18 '22 at 20:44