After spending a couple of hours I found that the relative path is not supported as a mounted path in Kubernetes. I found the reference here mountpath should be absolute if it is yes then why it doesn't have that capability of the relative path could anyone please explain a bit deeper?
Example code:
apiVersion: v1
kind: Pod
metadata:
name: task-pv-pod
spec:
volumes:
- name: task-pv-storage
hostPath:
# directory location on host
# path: "./code" # this is not supporting
path: "/var/www/html/kubernetes/code" # this is supporting
# this field is optional
type: DirectoryOrCreate
containers:
- name: task-pv-container
image: nginx
ports:
- containerPort: 80
name: "http-server"
volumeMounts:
- mountPath: "/usr/share/nginx/html"
name: task-pv-storage
Under the code
directory in the above code example, I just have an index.html
page
Screenshot of the project structure:
If I use path: "./code"
then the error shows like this:
Error response from daemon: create ./code: "./code" includes invalid
characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed.
If you intended to pass a host directory, use absolute path.
Thanks in advance!!