Reputation: 105
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
Upvotes: 2
Views: 2376
Reputation: 9845
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
.
Upvotes: 1
Reputation: 36
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.
Upvotes: 1
Reputation: 14112
When you are starting minikube with default docker
driver, you are creating Docker VM
inside your machine.
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
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
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
.
Upvotes: 3