I really dont understand this issue. In my pod.yaml i set the persistentVolumeClaim . i copied on my lastapplication declaration with PVC & PV.
i've checked that the files are in the right place !
on my Deployment file i've just set the port and the spec for the containers.
apiVersion: v1
kind: Pod
metadata:
name: ds-mg-cas-pod
namespace: ds-svc
spec:
containers:
- name: karaf
image: docker-all.xxxx.net/library/ds-mg-cas:latest
env:
- name: JAVA_APP_CONFIGS
value: "/apps/ds-cas-webapp/context"
- name: JAVA_EXTRA_PARAMS
value: "-Djava.security.auth.login.config=./config/jaas.config -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6402"
volumeMounts:
- name: ds-cas-config
mountPath: "/apps/ds-cas-webapp/context"
volumes:
- name: ds-cas-config
persistentVolumeClaim:
claimName: ds-cas-pvc
the PersistentVolume & PersistenteVolumeClaim
kind: PersistentVolume
apiVersion: v1
metadata:
name: ds-cas-pv
namespace: ds-svc
labels:
type: local
spec:
storageClassName: generic
capacity:
storage: 5Mi
accessModes:
- ReadWriteOnce
hostPath:
path: "/apps/ds-cas-webapp/context"
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: ds-cas-pvc
namespace: ds-svc
spec:
storageClassName: generic
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 2Mi
The error i get when i run the pod
java.io.FileNotFoundException: ./config/truststore.jks (No such file or directory)
I run the same image manually with docker. i didn't had an error. My question is where i can made a mistake because i really dont see :(
i set everything
the mountpoints
the ports
the variable
the docker command that i used to run the container :
docker run --name ds-mg-cas-manually
-e JAVA_APP=/apps/ds-cas-webapp/cas.war
-e JAVA_APP_CONFIGS=/apps/ds-cas-webapp/context
-e JAVA_EXTRA_PARAMS="-Djava.security.auth.login.config=./config/jaas.config -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=6402"
-p 8443:8443
-p 6402:640
-d
-v /apps/ds-cas-webapp/context:/apps/ds-cas-webapp/context
docker-all.attanea.net/library/ds-mg-cas
/bin/sh -c
Your PersistentVolumeClaim is probably bound to the wrong PersistentVolume.
PersistentVolumes exist cluster-wide, only PersistentVolumeClaims are attached to a namespace:
$ kubectl api-resources
NAME SHORTNAMES APIGROUP NAMESPACED KIND
persistentvolumeclaims pvc true PersistentVolumeClaim
persistentvolumes pv false PersistentVolume
Related
In order to test if I can get self written software deployed in amazon using docker images,
I have a test eks cluster.
I have written a small test script that reads and writes a file to see if I understand how to deploy. I have successfully deployed it in minikube, using three replica's. The replica's all use a shared directory on my local file system, and in minikube that is mounted into the pods with a volume
The next step was to deploy that in the eks cluster. However, I cannot get it working in eks. The problem is that the pods don't see the contents of the mounted directory.
This does not completely surprise me, since in minikube I had to create a mount first to a local directory on the server. I have not done something similar on the eks server.
My question is what I should do to make this working (if possible at all).
I use this yaml file to create a pod in eks:
apiVersion: v1
kind: PersistentVolume
metadata:
name: "pv-volume"
spec:
storageClassName: local-storage
capacity:
storage: "1Gi"
accessModes:
- "ReadWriteOnce"
hostPath:
path: /data/k8s
type: DirectoryOrCreate
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: "pv-claim"
spec:
storageClassName: local-storage
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: "500M"
---
apiVersion: v1
kind: Pod
metadata:
name: ruudtest
spec:
containers:
- name: ruud
image: MYIMAGE
volumeMounts:
- name: cmount
mountPath: "/config"
volumes:
- name: cmount
persistentVolumeClaim:
claimName: pv-claim
So what I expect is that I have a local directory, /data/k8s, that is visible in the pods as path /config.
When I apply this yaml, I get a pod that gives an error message that makes clear the data in the /data/k8s directory is not visible to the pod.
Kubectl gives me this info after creation of the volume and claim
[rdgon#NL013-PPDAPP015 probeer]$ kubectl get pv,pvc
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE
persistentvolume/pv-volume 1Gi RWO Retain Available 15s
persistentvolume/pvc-156edfef-d272-4df6-ae16-09b12e1c2f03 1Gi RWO Delete Bound default/pv-claim gp2 9s
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE
persistentvolumeclaim/pv-claim Bound pvc-156edfef-d272-4df6-ae16-09b12e1c2f03 1Gi RWO gp2 15s
Which seems to indicate everything is OK. But it seems that the filesystem of the master node, on which I run the yaml file to create the volume, is not the location where the pods look when they access the /config dir.
On EKS, there's no storage class named 'local-storage' by default.
There is only a 'gp2' storage class, which is also used when you don't specify a storageClassName.
The 'gp2' storage class creates a dedicated EBS volume and attaches it your Kubernetes Node when required, so it doesn't use a local folder. You also don't need to create the pv manually, just the pvc:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: "pv-claim"
spec:
storageClassName: gp2
accessModes:
- "ReadWriteOnce"
resources:
requests:
storage: "500M"
---
apiVersion: v1
kind: Pod
metadata:
name: ruudtest
spec:
containers:
- name: ruud
image: MYIMAGE
volumeMounts:
- name: cmount
mountPath: "/config"
volumes:
- name: cmount
persistentVolumeClaim:
claimName: pv-claim
If you want a folder on the Node itself, you can use a 'hostPath' volume, and you don't need a pv or pvc for that:
apiVersion: v1
kind: Pod
metadata:
name: ruudtest
spec:
containers:
- name: ruud
image: MYIMAGE
volumeMounts:
- name: cmount
mountPath: "/config"
volumes:
- name: cmount
hostPath:
path: /data/k8s
This is a bad idea, since the data will be lost if another node starts up, and your pod is moved to the new node.
If it's for configuration only, you can also use a configMap, and put the files directly in your kubernetes manifest files.
apiVersion: v1
kind: ConfigMap
metadata:
name: ruud-config
data:
ruud.properties: |
my ruud.properties file content...
---
apiVersion: v1
kind: Pod
metadata:
name: ruudtest
spec:
containers:
- name: ruud
image: MYIMAGE
volumeMounts:
- name: cmount
mountPath: "/config"
volumes:
- name: cmount
configMap:
name: ruud-config
Please check whether the pv got created and its "bound" to PVC by running below commands
kubectl get pv
kubectl get pvc
Which will give information whether the objects are created properly
The local path you refer to is not valid. Try:
apiVersion: v1
kind: Pod
metadata:
name: ruudtest
spec:
containers:
- name: ruud
image: MYIMAGE
volumeMounts:
- name: cmount
mountPath: /config
volumes:
- name: cmount
hostPath:
path: /data/k8s
type: DirectoryOrCreate # <-- You need this since the directory may not exist on the node.
I have a PVC like below:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: raw-block-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Block
resources:
requests:
storage: 1Gi
storageClassName: csi-rbd-sc
It is provisioned by ceph-csi plugin. As you can see, it will perform as a block device in a Pod. And the Pod definition is like this:
---
apiVersion: v1
kind: Pod
metadata:
name: pod-with-raw-block-volume
spec:
containers:
- name: fc-container
image: nginx
volumeDevices:
- name: data
devicePath: /dev/xvda
volumes:
- name: data
persistentVolumeClaim:
claimName: raw-block-pvc
I can find it at /dev/xvda.
But when I try to mount it on a dir by mount /dev/xvda /mnt, it failed and showed following:
mount: /mnt: cannot mount /dev/xvda read-only.
Could anyone tell me what is the reason?
When you claim volumeMode as block in pvc , that's a raw block device, /dev/xvda is block device same as your linux hard disk. You can't mount one raw block device, it's not formatted , no file system on it.
If you want to attache storage to directory, you cloud claim filesystem volumemode.
here is a sample, more detail you could visit https://docs.ceph.com/en/latest/rbd/rbd-kubernetes/
$ cat <<EOF > pvc.yaml
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: rbd-pvc
spec:
accessModes:
- ReadWriteOnce
volumeMode: Filesystem
resources:
requests:
storage: 1Gi
storageClassName: csi-rbd-sc
EOF
$ kubectl apply -f pvc.yaml
$ cat <<EOF > pod.yaml
---
apiVersion: v1
kind: Pod
metadata:
name: csi-rbd-demo-pod
spec:
containers:
- name: web-server
image: nginx
volumeMounts:
- name: mypvc
mountPath: /var/lib/www/html
volumes:
- name: mypvc
persistentVolumeClaim:
claimName: rbd-pvc
readOnly: false
EOF
$ kubectl apply -f pod.yaml
I have 2 pods, one that is writing files to a persistent volume and the other one supposedly reads those files to make some calculations.
The first pod writes the files successfully and when I display the content of the persistent volume using print(os.listdir(persistent_volume_path)) I get all the expected files. However, the same command on the second pod shows an empty directory. (The mountPath directory /data is created but empty.)
This is the TFJob yaml file:
apiVersion: kubeflow.org/v1
kind: TFJob
metadata:
name: pod1
namespace: my-namespace
spec:
cleanPodPolicy: None
tfReplicaSpecs:
Worker:
replicas: 1
restartPolicy: Never
template:
spec:
containers:
- name: tensorflow
image: my-image:latest
imagePullPolicy: Always
command:
- "python"
- "./program1.py"
- "--data_path=./dataset.csv"
- "--persistent_volume_path=/data"
volumeMounts:
- mountPath: "/data"
name: my-pv
volumes:
- name: my-pv
persistentVolumeClaim:
claimName: my-pvc
(respectively pod2 and program2.py for the second pod)
And this is the volume configuration:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
namespace: my-namespace
labels:
type: local
app: tfjob
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
apiVersion: v1
kind: PersistentVolume
metadata:
name: my-pv
namespace: my-namespace
labels:
type: local
app: tfjob
spec:
storageClassName: manual
capacity:
storage: 10Gi
accessModes:
- ReadWriteOnce
hostPath:
path: "/data"
Does anyone have any idea where's the problem exactly and how to fix it?
When two pods should access a shared Persistent Volume with access mode ReadWriteOnce, concurrently - then the two pods must be running on the same node since the volume can only be mounted on a single node at a time with this access mode.
To achieve this, some form of Pod Affinity must be applied, such that they are scheduled to the same node.
Is there any way to connect to a volume attached to a Kubernetes cluster and explore the content inside it.
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
i want to use local volume that is mounted on my node on path: /mnts/drive.
so i created a storageclass (as shown in documentation for local storageclass),
and created a PVC and a simple pod which uses that volume.
so these are the configurations used:
kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
name: local-fast
provisioner: kubernetes.io/no-provisioner
volumeBindingMode: WaitForFirstConsumer
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysampleclaim
spec:
storageClassName: local-fast
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 3Gi
---
apiVersion: v1
kind: Pod
metadata:
name: mysamplepod
spec:
containers:
- name: frontend
image: nginx:1.13
volumeMounts:
- mountPath: "/var/www/html"
name: myvolume
volumes:
- name: myvolume
persistentVolumeClaim:
claimName: mysampleclaim
and when i try to create this yaml file gives me an error, don't know what i am missing:
Unable to mount volumes for pod "mysamplepod_default(169efc06-3141-11e8-8e58-02d4a61b9de4)": timeout expired list of unattached/unmounted volumes=[myvolume]
If you want to use local volume that is mounted on the node on /mnts/drive path, you just need to use hostPath volume in your pod:
A hostPath volume mounts a file or directory from the host node’s
filesystem into your pod.
The final pod.yaml is:
apiVersion: v1
kind: Pod
metadata:
name: mysamplepod
spec:
containers:
- name: frontend
image: nginx:1.13
volumeMounts:
- mountPath: "/var/www/html"
name: myvolume
volumes:
- name: myvolume
hostPath:
# directory location on host
path: /mnts/drive