0

I have created a simple spring cloud task project, which will generate a file and add to local folder. I am using SCDF(Spring cloud data flow) and kubernetes for deployment. I need to generate file to Persistent Volume. I have deployed it using SCDF to kubernetes. But it is showing error in kubernetes as Error: Error response from daemon: invalid volume specification: '/home/:/': invalid mount config for type "bind": invalid specification: destination can't be '/' I have tested in my local it is working fine. In local kubernetes and SCDF have this problem.

This is the java code for creating simple cloud task

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.task.configuration.EnableTask;

@SpringBootApplication
@EnableTask
public class SpringCloudTaskExampleApplication {

    public static void main(String[] args) {
        SpringApplication.run(SpringCloudTaskExampleApplication.class, args);
        copyFiles();
    }
    
    public static void copyFiles() {
        String sfilePath = "/home";
        File musicFile = new File("/home/music.txt"); 
        try {
            musicFile.createNewFile();
            //To check File is created or not.
            System.out.println(Files.list(Paths.get("/home/")).collect(Collectors.toList()));
            
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

Docker file

FROM openjdk:11
EXPOSE 8092
VOLUME ["/home"]
ADD target/spring-cloud-task-example-0.0.1-SNAPSHOT.jar taskexample.jar
ENTRYPOINT ["java","-jar","taskexample.jar"]

PV deployment file

apiVersion: v1
kind: PersistentVolume
metadata:
  name: task-pv-volume
  labels:
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 1000M
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/home/"

PVC deployment file

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: task-pv-claim
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1000M

And I have added SCDF Deployment Platform property

volume : [{name: testhostpath, persistentVolumeClaim: { claimName: 'task-pv-claim'}}]
volume-mounts: [{name: 'testhostpath', mountPath: '/'}]

I need to mount the PV to task and store it. Can anyone help with this problem.

  • Hello, welcome to Stack Overflow! Maybe you should [read this](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors/285557#285557), and then edit your question. – Diego Borba Aug 11 '23 at 17:49
  • 1
    I have solved this problem by removing `VOLUME ["/home"]` from Dockerfile. – ThunderBoy Aug 24 '23 at 05:03

0 Answers0