Reputation: 1155
I am getting an error mounting a config file, can anyone assist?
With subPath on volumeMounts I get the error:
Error: stat /var/config/openhim-console.json: no such file or directory.
I can read this file.
Without subPath on volumeMounts I get this error:
Warning Failed 13s kubelet, ip-10-0-65-230.eu-central-1.compute.internal Error: failed to start container "openhim-console": Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/var/config/openhim-console.json\\\" to rootfs \\\"/var/lib/docker/overlay2/7408e2aa7e93b3c42ca4c2320681f61ae4bd4b02208364eee8da5f51d587ed21/merged\\\" at \\\"/var/lib/docker/overlay2/7408e2aa7e93b3c42ca4c2320681f61ae4bd4b02208364eee8da5f51d587ed21/merged/usr/share/nginx/html/config/default.json\\\" caused \\\"not a directory\\\"\""
: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type
Warning BackOff 2s kubelet, ip-10-0-65-230.eu-central-1.compute.internal Back-off restarting failed container
Here is the deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: openhim-console-deployment
spec:
replicas: 1
selector:
matchLabels:
component: openhim-console
template:
metadata:
labels:
component: openhim-console
spec:
volumes:
- name: console-config
hostPath:
path: /var/config/openhim-console.json
containers:
- name: openhim-console
image: jembi/openhim-console:1.13.rc
ports:
- containerPort: 80
volumeMounts:
- name: console-config
mountPath: /usr/share/nginx/html/config/default.json
subPath: default.json
env:
- name: NODE_ENV
value: development
Upvotes: 1
Views: 2640
Reputation: 5494
Probably hostPath
should hold a path
rather than your file path: /var/config/openhim-console.json
as you're mounting a volume, not a file.
If you are, the type
should be specified as File
.
See also docs#hostpath
Upvotes: 2
Reputation: 11341
You should either use:
volumes:
- name: host-file
hostPath:
path: /var/log/waagent.log
type: File
or
volumes:
- name: test-volume
hostPath:
path: /data
# Directory is the default, so this field is optional.
type: Directory
Example:
apiVersion: v1
kind: Pod
metadata:
name: test-pd
spec:
containers:
- image: k8s.gcr.io/test-webserver
name: test-container
volumeMounts:
- mountPath: /test-pd
name: test-volume
- mountPath: /var/log/lala/aaa.log
name: host-file
volumes:
- name: test-volume
hostPath:
path: /data
# this field is optional
type: Directory
- name: host-file
hostPath:
path: /var/log/waagent.log
type: File
subpath is generally used when you need to mount only one path inside the container instead of the root.
You can find more details in the docs.
Upvotes: 0