英文:
How to mount hostpath on a pod with podname as a subdirectory
问题
我需要将hostpath
挂载到一个Pod上,但是这个hostpath
应该有一个与POD名称相关的子目录。我知道类似这样的操作可以在StatefulSets中使用,但由于某些限制,需要在部署中进行hostpath
挂载,其中根目录将具有podnames
作为子目录。这是否可以实现?
英文:
I have a use-case where I need to mount a hostpath
to a pod but that hostpath should have a subdirectory with PODNAME
, I know something like this can be used with statefulsets but due to some constraints a hostpath mount is needed in deployment where the root directory will have sub directories as podnames
.
Can this be achieved?
答案1
得分: 2
- name: pod_name
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
请随意参考我的 GitHub YAML:https://github.com/harsh4870/OCI-public-logging-uma-agent/blob/main/deployment.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: app
image:
env:- name: pod_name
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
volumeMounts: - mountPath: /app_logs
name: app-logs
subPathExpr: $(pod_name)
volumes:
- name: pod_name
- name: mydir
hostPath:
path: /var/log/app_logs
type: DirectoryOrCreate
这是完整文章,我使用了downwardAPI来记录日志:https://medium.com/@harsh.manvar111/oke-logging-with-uma-agent-in-oci-d6f55a8bcc02
英文:
You can use the downward API of Kubernetes as Environment variables :
- name: pod_name
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
Feel free to refer my GitHub YAML : https://github.com/harsh4870/OCI-public-logging-uma-agent/blob/main/deployment.yaml
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- name: app
image: <App image>
env:
- name: pod_name
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.name
volumeMounts:
- mountPath: /app_logs
name: app-logs
subPathExpr: $(pod_name)
volumes:
- name: mydir
hostPath:
path: /var/log/app_logs
type: DirectoryOrCreate
Here is full article i have used downwardAPI for logging : https://medium.com/@harsh.manvar111/oke-logging-with-uma-agent-in-oci-d6f55a8bcc02
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论