Search code examples
kubernetesvolumeazure-aksazure-container-service

Explore Azure Kubernetes Volume Content


Is there any way to connect to a volume attached to a Kubernetes cluster and explore the content inside it.


Solution

  • First, create a PersistentVolumeClaim and Pod to mount the volume

    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
      name: my-claim
    spec:
      accessModes:
        - ReadWriteOnce
      volumeName: <the-volume-that-you-want-to-explore>
      resources:
        requests:
          storage: 3Gi
    ---
    apiVersion: v1
    kind: Pod
    metadata:
      name: volume-inspector
    spec:
      containers:
        - name: foo
          command: ["sleep","infinity"]
          image: ubuntu:latest
          volumeMounts:
          - mountPath: "/tmp/mount"
            name: data
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: my-claim
            readOnly: true
    

    Then exec into the Pod and start exploring

    $ kubectl exec -it volume-inspector bash
    root@volume-inspector:/# ls /tmp/mount