2.10.3.6. config map の使用によるボリュームへのコンテンツの注入
config map を使用すると、ボリュームにコンテンツを挿入できます。
以下の例の ConfigMap カスタムリソース (CR) には、2 つの環境変数が含まれています。
apiVersion: v1
kind: ConfigMap
metadata:
name: special-config
namespace: default
data:
special.how: very
special.type: charm
以下の手順では、config map を使用してボリュームにコンテンツを挿入するためのオプションについて説明します。
手順
config map を使用してコンテンツをボリュームに注入するための最も基本的な方法は、キーがファイル名であり、ファイルの内容がキーの値になっているファイルでボリュームを設定する方法です。
apiVersion: v1 kind: Pod metadata: name: dapi-test-pod spec: securityContext: runAsNonRoot: true seccompProfile: type: RuntimeDefault containers: - name: test-container image: gcr.io/google_containers/busybox command: [ "/bin/sh", "-c", "cat", "/etc/config/special.how" ] volumeMounts: - name: config-volume mountPath: /etc/config securityContext: allowPrivilegeEscalation: false capabilities: drop: [ALL] volumes: - name: config-volume configMap: name: special-config restartPolicy: Never各項目の説明:
spec.volumes.configMap.nameキーを含むファイルを指定します。
この Pod が実行されると、cat コマンドの出力は以下のようになります。
very
設定マップキーが投影されるボリューム内のパスを制御することもできます。
apiVersion: v1 kind: Pod metadata: name: dapi-test-pod spec: securityContext: runAsNonRoot: true seccompProfile: type: RuntimeDefault containers: - name: test-container image: gcr.io/google_containers/busybox command: [ "/bin/sh", "-c", "cat", "/etc/config/path/to/special-key" ] volumeMounts: - name: config-volume mountPath: /etc/config securityContext: allowPrivilegeEscalation: false capabilities: drop: [ALL] volumes: - name: config-volume configMap: name: special-config items: - key: special.how path: path/to/special-key restartPolicy: Never各項目の説明:
spec.volumes.configMap.items.path- config map キーへのパスを指定します。
この Pod を実行すると、cat コマンドの出力は
非常にです。