Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

479
Views
Kubernetes volume mount set up Type check failed

I am unable to deploy an application in kubernetes , this is the deployment yaml.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - name: test
        image: openjdk:14
        ports:
        - containerPort: 8080
        volumeMounts: 
        - name: testing
          mountPath: "/usr/src/myapp/docker.jar"
        workingDir: "/usr/src/myapp"
        command: ["java"]
        args: ["-jar", "docker.jar"]        
      volumes: 
      - hostPath: 
          path: /home/user/docker.jar
          type: File
        name: testing

This is the error I receive, and I can verify the file does exist and in this folder. I tried removing the type but it only uploads an empty directory, it seems to not recognize that the file exists.

MountVolume.SetUp failed for volume "testing" : hostPath type check failed: /home/user/docker.jar is not a file
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

When you are starting minikube with default docker driver, you are creating Docker VM inside your machine.

Background

When you are using your VM your terminal looks like:

user@nameofyourhost:~$

But if you will ssh to your Minikube VM terminal looks like below:

docker@minikube:~$ 

In HostPath you have information:

A hostPath volume mounts a file or directory from the host node's filesystem into your Pod.

In minikube when you are using hostPath, node is considered not your machine but the Minikube VM which was created during minikube start

Tests

As I dont have exactly your files, Ive used nginx. Please remember that you should have proper permissions to directories you want to mount. I've used tmp as in nginx this directory have full access for everyone.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test
  labels:
    app: test
spec:
  replicas: 1
  selector:
    matchLabels:
      app: test
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
      - name: test
        image: nginx
        ports:
        - containerPort: 8080
        volumeMounts:
        - name: testing
          mountPath: "/tmp/docker.jar"   #this is path to the file
      volumes:
      - hostPath:
          path: <path to docker.jar file> #should be on Minikube VM
          type: File
        name: testing

When you create docker.jar on VM.

user@nameOfMyVM:~$ pwd
/home/user
user@nameOfMyVM:~$ ls
docker.jar

When you will chage in hostpath.path to /home/user/docker.jar it will return warning

Warning  FailedMount  4s (x4 over 7s)  kubelet            MountVolume.SetUp failed for volume "testing" : hostPath type check failed: /home/sekreta/docker.jar is not a file`

As Kubernetes didn't find this file.

But when you will create this file inside Minikube VM

$ minikube ssh
docker@minikube:~$ pwd
/home/docker
docker@minikube:~$ ls
docker.jar

and change in deployment hostPath.path to /home/docker/docker.jar pod will be created.

$ kubectl get po
NAME                   READY   STATUS    RESTARTS   AGE
test-c68d959c6-kb275   1/1     Running   0          13s

File can be found in directory set in YAML, which is tmp.

$ kubectl exec -ti test-c68d959c6-kb275 -- bin/bash
root@test-c68d959c6-kb275:/# cd /tmp
root@test-c68d959c6-kb275:/tmp# ls
docker.jar

Conclusion

When you are using HostPath on Minikube you need to remember that filesystem is not your Machine but Minikube VM which was created during minikube start.

over 4 years ago · Santiago Trujillo Report

0

If you running on multi-node system, be sure the hostpath is accessible on the node that pods deployed to.

I also encountered this very similar issue on one master & one-worker node setup using helm chart.

Helm deployed all pods to worker node, and hostPath were not accessible from worker node even though deployment is done from master node. Copy and verify hostpath on worker node resolved is type of error for me.

over 4 years ago · Santiago Trujillo Report

0

If you verified that the file/directory exists on the Minikube VM (minikube ssh ls -la /home/user) then you are not deploying on the minikube k8s context as you are expecting.

Check what's your currently used context, with kubectx --current.

Then set the Minikube one via kubectx minikube or kubectl use-context minikube.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!