Kubernetes volume mounting

4/23/2020

I ' m trying to mount a directory to my pods but always it shows me an error "no file or directory found"

This is my yaml file used for the deployment :

apiVersion: apps/v1
kind: Deployment
metadata:
  name: myapp1-deployment
  labels:
    app: myapp
spec:
  replicas: 3
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      volumes:
       - name: test-mount-1
         persistentVolumeClaim:
           claimName: task-pv-claim-1
      containers:
      - name: myapp
        image: 192.168.11.168:5002/dev:0.0.1-SNAPSHOT-6f4b1db
        command: ["java -jar /jar/myapp1-0.0.1-SNAPSHOT.jar --spring.config.location=file:/etc/application.properties"]
        ports:
        - containerPort: 8080
        volumeMounts:
            - mountPath: "/etc/application.properties"
              #subPath: application.properties
              name: test-mount-1
       # hostNetwork: true

      imagePullSecrets:
        - name: regcred
      #volumes:
       # - name: test-mount

and this is the persistance volume config :

kind: PersistentVolume
apiVersion: v1
metadata:
  name: test-mount-1
  labels:
    type: local
    app: myapp
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteMany
  hostPath:
    path: "/mnt/share"

and this the claim volume config :

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim-1
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteMany
  resources:
    requests:
      storage: 5Gi

and this for the service config used for the deployment :

apiVersion: v1
kind: Service
metadata:
  name: myapp-service
spec:
  selector:
    app: myapp
  externalIPs:
   - 192.168.11.145
  ports:
    - protocol: TCP
      port: 8080
      nodePort: 31000
  type: LoadBalancer
status:
  loadBalancer:
    ingress:

If any one can help , I will be grateful and thanks .

-- mimo2000
kubernetes
linux
mount
volumes

1 Answer

4/23/2020

You haven't included your storage class in your question, but I'm assuming you're attempting local storage on a node. Might be a simple thing to check, but does the directory exist on the node where your pod is running? And is it writeable? Depending on how many worker nodes you have, it looks like your pod could be running on any node, and the pv isn't set to any particular node. You could use node affinity to ensure that your pod runs on the same node that contains the directory referenced in your pv, if that's the issue.

Edit, if it's nfs, you need to change your pv to include:

nfs: 
  path: /mnt/share 
  server: <nfs server node ip/fqdn>

Example here

-- Ruairios
Source: StackOverflow