0

I have app-1 pods created by StatefulSet and in that, I am creating PVC as well

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: app-1
spec:
  replicas: 3
  selector:
    matchLabels:
      app: app-1
  serviceName: "app-1"
  template:
    metadata:
      labels:
        app: app-1
    spec:
      containers:
      - name: app-1
        image: registry.k8s.io/nginx-slim:0.8
        resources:
          requests:
            cpu: 100m
            memory: 128Mi
          limits:
            cpu: 250m
            memory: 256Mi
        ports:
        - containerPort: 4567
        volumeMounts:
        - name: app-1-state-volume-claim
          mountPath: /app1Data
        - name: app-2-data-volume-claim
          mountPath: /app2Data
  volumeClaimTemplates:
  - metadata:
      name: app-1-state-volume-claim
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "managed-csi-premium"
      resources:
        requests:
          storage: 1Gi
  - metadata:
      name: app-2-data-volume-claim
    spec:
      accessModes: [ "ReadWriteOnce" ]
      storageClassName: "managed-csi-premium"
      resources:
        requests:
          storage: 1Gi

state of the app1 is maintained in PVC - app-1-state-volume-claim
app1 is also creating data for app2 in PVC - app-2-data-volume-claim

I want to access app-2-data-volume-claim in another pod deployment described below

apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: app-2
spec:
  selector:
    matchLabels:
      name: app-2
  template:
    metadata:
      labels:
        name: app-2
    spec:
      containers:
      - name: app-2
        image: quay.io/fluentd_elasticsearch/fluentd:v2.5.2
        resources:
          limits:
            memory: 200Mi
          requests:
            cpu: 100m
            memory: 200Mi
        volumeMounts:
        - name: app2Data
          mountPath: /app2Data
      volumes:
      - name: app2Data
        persistentVolumeClaim:
          claimName: app-2-data-volume-claim

This is failing with below output

persistentvolumeclaim "app-2-data-volume-claim" not found

How can I do that?
I cannot use Azure file share due to app-1 limitation.

Atul Takekar
  • 51
  • 13
  • With that setup, there will be a separate `app-2` PVC per replica of the StatefulSet, but one DasmonSet Pod for each node. Those numbers of pods and volumes don't match up. One pod writing to another's storage often isn't a best practice, and can lead to some unexpected race conditions; can the DaemonSet Pods make network calls to the StatsfulSet's Service instead? – David Maze Dec 02 '22 at 00:23
  • daemonset app should collect that data and store it in azure blob. One thing I can try is having both app1 container and app2 container in same pod running as a statefulset – Atul Takekar Dec 02 '22 at 19:49
  • In the question, the DaemonSet image is Fluentd. Is the volume content just log messages? In which case a better answer might be to not use a volume at all, send logs to stdout, and let the Fluentd DaemonSet pick them up from each node. If it's something else, why a DaemonSet? – David Maze Dec 02 '22 at 20:02
  • fluentd was just for test. app2 is python application that read the data saved by app1 and store it in blob store. There is no requirement to create app2 as daemonset – Atul Takekar Dec 03 '22 at 21:18

0 Answers0