16

I have packed the software to a container. I need to put the container to cluster by Azure Container Service. The software have outputs of an directory /src/data/, I want to access the content of the whole directory.

After searching, I have to solution.

  1. use Blob Storage on azure, but then after searching, I can't find the executable method.
  2. use Persistent Volume, but all the official documentation of azure and pages I found is about Persistent Volume itself, not about how to inspect it.

I need to access and manage my output directory on Azure cluster. In other words, I need a savior.

zedong
  • 393
  • 2
  • 5
  • 15
  • 2
    You need a saviour? But are you [holding out for a hero?](https://www.youtube.com/watch?v=bWcASV2sey0) A PersistentVolume is, in part, an abstraction layer between the pod definition and a storage medium. You don't inspect the PV, you inspect the underlying storage medium. Unless you mean `kubectl describe persistentvolume NAME`. – ProgrammingLlama Mar 28 '18 at 08:02
  • 1
    [This documentation](https://learn.microsoft.com/en-us/azure/aks/azure-files-dynamic-pv) shows how to use AzureFile as the backing storage for a PersistentVolume. – ProgrammingLlama Mar 28 '18 at 08:03
  • I have tried this documentation, but I had not connect the container and the AzureFile. I will have another try now. – zedong Mar 28 '18 at 08:09
  • Make sure you create a share with that name on the Azure portal (go to the Storage Account, click "Files", click "+ File Share" in the toolbar). – ProgrammingLlama Mar 28 '18 at 08:10
  • The example [here](https://github.com/kubernetes/examples/blob/master/staging/volumes/azure_file/azure.yaml) may help with accessing using the AzureFile volume type in the first place. – ProgrammingLlama Mar 28 '18 at 08:13
  • @张泽栋 Did above tips helped ? Did you manage to solve problem ? – Malgorzata Mar 08 '21 at 14:23

1 Answers1

20

As I've explained here and here, in general, if you can interact with the cluster using kubectl, you can create a pod/container, mount the PVC inside, and use the container's tools to, e.g., ls the contents. If you need more advanced editing tools, replace the container image busybox with a custom one.

Create the inspector pod

cat <<EOF | kubectl apply -f -
apiVersion: v1
kind: Pod
metadata:
  name: pvc-inspector
spec:
  containers:
  - image: busybox
    name: pvc-inspector
    command: ["tail"]
    args: ["-f", "/dev/null"]
    volumeMounts:
    - mountPath: /pvc
      name: pvc-mount
  volumes:
  - name: pvc-mount
    persistentVolumeClaim:
      claimName: YOUR_CLAIM_NAME_HERE
EOF

Inspect the contents

kubectl exec -it pvc-inspector -- sh
$ ls /pvc

Clean Up

kubectl delete pod pvc-inspector
sauerburger
  • 4,569
  • 4
  • 31
  • 42
  • This works for me ! . The context was to inspect files in a PVC for a CronJob. Because once the CronJob executes the pod can no longer be accessed (and hence any files on the associated PVC) they was need to find a way to access these files. – Golide Jul 21 '22 at 12:47