How to access volume mount with python script?

10/21/2019

I have been trying to use something along these lines to access a file in a volume mount:

with open('./log/file.json', 'w+') as f:
    f.write(json.dumps(output, sort_keys=True, indent=4))

but it is not working. Are there any ideas? In my deployment file, I have this:

volumeMounts:
- mountPath: /logs
  name: wag-log
-- Chlei
kubernetes
python
yaml

1 Answer

10/21/2019

You've defined a volumeMount with the mountPath set to /logs, which would mount a volume into the /logs directory. In your Python code you're writing at the path ./log/file.json, which is not in /logs.

Try to write a log to the directory you mounted, for example:

with open('/logs/file.json', 'w+') as f:
    f.write(json.dumps(output, sort_keys=True, indent=4))
-- Mikhail Golubitsky
Source: StackOverflow