FRC
FRC

Reputation: 485

Kubernetes storing persistent files

What's the best way to store a persistent file in Kubernetes? I have a cert (.pfx) and I want to be passing to the application its path. From the looks of it it can't be stored in secrets. Was thinking about a volume but the question is how do I upload the file to it? And which type of volume to choose? Or is there any other efficient way?

Upvotes: 3

Views: 4017

Answers (2)

Abdullah Khan
Abdullah Khan

Reputation: 1

you can copy your ".pfx" file into local directory like "/home/certs/" and than mount this directory inside to your pod,check below yaml

kind: Pod
apiVersion: v1
metadata:
  name: secret-test-pod
spec:
  volumes:
  - name: localhostpath
    hostPath:
      path: /home/certs # path on local file system
      type: DirectoryOrCreate # create if not exist
  containers:
  - name: ...
    image: ...
    volumeMounts:
    - name: localhostpath
      mountPath: "/root/certs" # path inside pod or containers 

Upvotes: 0

Janos Lenart
Janos Lenart

Reputation: 27160

It's unclear from your question why you came to the conclusion that it can't be stored as a Secret. This is one of the main use cases for Secrets.

Step 1. Create a Secret from your file:

kubectl create secret generic mysecret --from-file=myfile=/tmp/my.pfx

Step 2. Mount the Secret volume into a Pod:

kind: Pod
apiVersion: v1
metadata:
  name: secret-test-pod
spec:
  volumes:
  - name: secret-volume
    secret:
      secretName: mysecret
  containers:
  - name: ...
    image: ...
    volumeMounts:
    - name: secret-volume
      mountPath: "/etc/secret-volume"

Your container should see a file at /etc/secret-volume/myfile

Upvotes: 12

Related Questions