-1

I have this Spring Boot application which need some files, directories from my host and in kubernetes runtime to resolve those placeholders.

Now, i tried to mount volume directly in the pod from my host directory location, but is monted empty dir I also tried to mount a configMap object with the path of that directory in my volume mounted, but when i go inside the pod, directory/file name is there, but when i want to see what is inside it throws: Not a directory or file

Is there a way to achive what i want to do? To mount some files/directories in my pod container and make them availlable so can resolve Placeholders at runtime?

Placeholders aren't resolving usint these approches, so.. i'm asking for an advice, some help of what to do:

ConfigMap object:

apiVersion: v1
kind: ConfigMap
metadata:
  name: gateway-configmap
data:
  PLACEHOLDER_VALUE: /root/my-projectDirectory
  PLACEHOLDER_LOGS: /root/my-projectDirectory/logs

PV AND PVC:

apiVersion: v1
kind: PersistentVolume
metadata:
  name: gateway-pv
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /root/my-projectDirectory
    type: Directory


---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gateway-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: gateway-pv-logs
spec:
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: /root/my-projectDirectory/logs
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: gateway-pv-logs-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi

Deployment and Service of my Spring Boot app:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: gateway-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gateway
  template:
    metadata:
      labels:
        app: gateway
    spec:
      containers:
        - name: gateway-pod
          image: gateway
          imagePullPolicy: IfNotPresent
          env:
            - name: PLACEHOLDER_VALUE
              value: 'PLACEHOLDER_VALUE'
            - name: PLACEHOLDER_LOGS
              value: 'PLACEHOLDER_LOGS'
          volumeMounts:
            - mountPath: /PLACEHOLDER_LOGS
              name: gateway-volume
            - mountPath: /PLACEHOLDER_VALUE
              name: gateway-pv-logs
      volumes:
        - name: gateway-volume
          persistentVolumeClaim:
            claimName: gateway-pvc
        - name: gateway-pv-logs
          persistentVolumeClaim:
            claimName: gateway-pv-logs-pvc
---
apiVersion: v1
kind: Service
metadata:
  name: gateway-service
spec:
  selector:
    app: gateway
  ports:
    - protocol: 'TCP'
      port: 9000
      targetPort: 9000
  type: NodePort
todododo
  • 1
  • 2
  • The remote cluster intrinsically can't reach back to your local system for anything. A usual setup is to send logs to stdout and not a file, at which point there are standard ways to collect the `kubectl logs` output. What are the other local files? Are they reasonably static data you can embed in a ConfigMap? Or would it make more sense to run this application fully locally without Kubernetes, or even with just a JVM and no container technology at all? – David Maze Aug 20 '23 at 12:29
  • I need to add support for Kubernetes and later on for deployments... Now those local files are static data files from which my application need to read on, i can resolve this with a configMap or smething like... create configMap --from file, something? And another question, we can't do anything? I mean, to mount somehow, in the minikube cluster, for example, you can go with winSCP in a virtual machine and mount directories on that vm, we can do something in the lines with Kubernetes cluster and being availlable for other pods? – todododo Aug 20 '23 at 14:17
  • In docker, isn't the same thing? VM cluster, and then containers VM, so VM in VM in a machine, but we can mount directories/files in Docker cluster then make them availlable for containers – todododo Aug 20 '23 at 14:20
  • You're presumably using Kubernetes instead of plain Docker because you have more than one machine (or dozens or hundreds). If you can publish the data into a ConfigMap then you can use that, but the cluster cannot call back to your local system to get at the files that only live there. – David Maze Aug 20 '23 at 17:06
  • Ok ok, but how to publish data in configMap and use that data? In a volume, or what...? – todododo Aug 20 '23 at 18:04

0 Answers0