The issue with your current setup is that you're mounting the directory (/mnt/extra-addons) but not copying the files themselves into the container. If you want the files from the host path to be available in the container, the hostPath approach should work as long as the files exist on the host machine at the specified location (/home/jenkins/minikube/odoo/odoo/addons).
Here are a few things to check and some potential fixes:
1. Check File Permissions
Ensure the directory /home/jenkins/minikube/odoo/odoo/addons and its contents have the correct permissions. The Kubernetes pod needs to have read/write access (as appropriate). You can run the following on your host to check permissions:
bashCopy codels -l /home/jenkins/minikube/odoo/odoo/addons
If permissions are incorrect, you can modify them:
bashCopy codesudo chmod -R 755 /home/jenkins/minikube/odoo/odoo/addons
2. Directory Exists in Host
Verify that the directory /home/jenkins/minikube/odoo/odoo/addons exists and contains the files you expect to be copied.
bashCopy codels /home/jenkins/minikube/odoo/odoo/addons
If the directory or files don’t exist, this will explain why nothing is being mounted inside the pod.
3. Pod Directory
Ensure that /mnt/extra-addons in the container is not already populated with other files or mounted volumes that may interfere with your hostPath volume. You can check inside the running pod by executing:
bashCopy codekubectl exec -it -- ls /mnt/extra-addons
4. Deployment Fix (Using emptyDir as an Alternative)
If your goal is to copy files from a directory into the pod rather than bind-mount a host directory, you might consider using an emptyDir volume and an init container to copy the files. This could work like:
yamlCopy codeapiVersion: apps/v1
kind: Deployment
metadata:
name: odoo
spec:
replicas: 1
selector:
matchLabels:
app: odoo
template:
metadata:
labels:
app: odoo
spec:
containers:
- name: odoo
image: "odoo:14"
volumeMounts:
- name: addons-volume
mountPath: /mnt/extra-addons
initContainers:
- name: copy-addons
image: busybox
command: ["sh", "-c", "cp -r /source/* /mnt/extra-addons"]
volumeMounts:
- name: addons-volume
mountPath: /mnt/extra-addons
- name: host-addons
mountPath: /source
volumes:
- name: addons-volume
emptyDir: {}
- name: host-addons
hostPath:
path: /home/jenkins/minikube/odoo/odoo/addons
type: Directory
In this approach:
- An initContainer copies the files from the host directory (/home/jenkins/minikube/odoo/odoo/addons) into the pod's addons-volume using emptyDir, ensuring the files are available when the Odoo container starts.
5. PersistentVolumeClaim (Optional Improvement)
If you want to persist files across pod restarts or across different nodes in a cluster, consider using a PersistentVolume and PersistentVolumeClaim instead of hostPath. This is more flexible and works better in a multi-node setup.
Let me know if you'd like help adjusting the solution further or if the files still don't appear!