Accessing PVC created by pod from Statefulset in another pod created by daemonset using azure disk

146 Views Asked by At

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.

0

There are 0 best solutions below