如何用kubernetes docker镜像目录映射主机目录

问题描述 投票:-1回答:1

我需要将我的本地机器中的一个目录与我的kubernetes集群内运行的docker容器中存在的一个目录进行映射。谁能帮帮我?

host dir : /opt/dev/project1
kube image location: /var/logs
docker kubernetes volume docker-volume
1个回答
2
投票

你可以把你的主机目录挂载到kubernetes pod中,使用的是 主机路径

apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
  - image: k8s.gcr.io/test-webserver
    name: test-container
    volumeMounts:
    - mountPath: /var/logs
      name: test-volume
  volumes:
  - name: test-volume
    hostPath:
      # directory location on host
      path: /opt/dev/project1
      # this field is optional
      type: Directory
© www.soinside.com 2019 - 2024. All rights reserved.