---
slug: "mount-file-in-kubernetes-pod-via-config-map"
title: "Kubernetes の ConfigMap でファイルをマウントする"
description: "Kubernetes で、ローカルにあるファイルで ConfigMap を作り、Podにマウントさせる方法です。"
url: "https://www.ytyng.com/blog/mount-file-in-kubernetes-pod-via-config-map"
publish_date: "2023-03-11T01:01:57Z"
created: "2023-03-11T01:01:57Z"
updated: "2026-02-26T14:54:55.738Z"
categories: []
keywords: ""
featured_image_url: "https://media.ytyng.com/resize/20250708/98870d2a6f75491e80d2e247a67bd54f.png.webp?width=768"
has_video: true
has_music: true
video_urls: ["https://media.ytyng.net/ytyng-blog/274/featured-video-1.mp4", "https://media.ytyng.net/ytyng-blog/274/featured-video-2.mp4", "https://media.ytyng.net/ytyng-blog/274/featured-video-3.mp4"]
music_urls: ["https://media.ytyng.net/ytyng-blog/274/featured-music-274-3.mp3", "https://media.ytyng.net/ytyng-blog/274/featured-music-274-4.mp3"]
lang: "ja"
---

# Kubernetes の ConfigMap でファイルをマウントする

ローカルにあるファイルで ConfigMap を作り、Podにマウントさせる方法です。

ファイルから ConfigMap を作成する

```shell
kubectl -n my-namespace create configmap my-config-file --from-file=../my-config-file.conf
```

deployments でマウントする

```yaml
apiVersion: apps/v1
kind: Deployment
  namespace: torico
spec:
  ...
  template:
    spec:
      containers:
          volumeMounts:
            - name: my-config-file-volume
              mountPath: /app/config/my-config-file.conf
              subPath: my-config-file.conf
      volumes:
        - name: my-config-file-volume
          configMap:
            name: my-config-file
```

`my-config-file-volume` の中の `my-config-file.conf` というファイルのみ、
`/app/config/my-config-file.conf` としてマウントさせる
