The goal is to orchestrate both production and local development environments using Kubernetes. The problem is that hostPath
doesn't work with relative path values. This results in slightly differing configuration files on each developer's machine to accommodate for the different project locations (i.e. "/my/absolute/path/to/the/project"
):
apiVersion: v1 kind: Service metadata: name: some-service labels: app: app spec: type: LoadBalancer ports: - port: 80 selector: app: app --- apiVersion: apps/v1 kind: Deployment metadata: name: some-deploy spec: selector: matchLabels: app: app replicas: 1 template: metadata: labels: app: app spec: containers: - name: app image: nginx:1.13.12-alpine ports: - containerPort: 80 volumeMounts: - name: vol_example mountPath: /var/www/html volumes: - name: vol_example hostPath: path: "/my/absolute/path/to/the/project" type: Directory
How can relative paths be used in Kubernetes config files? Variable replacements (such as $(PWD)/project
) have been tried, but didn't seem to work. If config variables can work with volumes, this might help but unsure of how to achieve this.
Relative paths make use of two special symbols, a dot (.) and a double-dot (..), which translate into the current directory and the parent directory. Double dots are used for moving up in the hierarchy. A single dot represents the current directory itself.
An absolute path is defined as specifying the location of a file or directory from the root directory(/). In other words,we can say that an absolute path is a complete path from start of actual file system from / directory. Relative path is defined as the path related to the present working directly(pwd).
The mount path is always the destination inside the Pod a volume gets mounted to. I think the documentation is pretty clear on what hostPath does: A hostPath volume mounts a file or directory from the host node's filesystem into your Pod.
Yes. The current working directory is a property of the process.
As mentioned here kubectl
will never support variable substitution.
You can create a helm chart for your app (yaml). It supports yaml template variables (among various other features). So you'll be able to pass hostPath
parameter based on development or production.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With