<p>I m running my Angular 6 application as a Kubernetes pod/container. In this Angular app, I try to access a JSON config-object, to load my environment variables.</p>

<p>I have used volume to read the config map and volume mount to create a config json file.</p>

<p>My service is throwing a <code>503</code> error IF I include the volume creation code in my yaml file.</p>

<p>The pods are in running mode when seen in logs.</p>

<p>Code snippet of my deployment yaml file:</p>

<pre><code>  apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "client-onboard.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "client-onboard.name" . }}
    helm.sh/chart: {{ include "client-onboard.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "client-onboard.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "client-onboard.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
    spec:
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          volumeMounts:
          - name: env-vars
            mountPath: usr/share/nginx/html/config/env-vars.json
      volumes:
        - name: env-vars
          configMap:
            name: {{ .Chart.Name }}-configmap
          ports:
            - name: http
              containerPort: 80
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: http
          readinessProbe:
            httpGet:
              path: /
              port: http
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
    {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
    {{- end }}
</code></pre>

<p>I am using nginx server for this.</p>

pulkit arora
<p><strong>For creating a file you need to use subPath.The value of the subPath must match the “key” of the ConfigMap. In the below example the key and subPath is config.yaml.</strong></p>

<pre><code>apiVersion: v1
kind: ConfigMap
metadata:
  name: sherlock-config
  namespace: default
data:
  config.yaml: |
    namespaces:
      - default
    labels:
      - "app"
      - "owner"
---
apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "ls /etc/config/" ]
      volumeMounts:
      - name: config-volume
        mountPath: /etc/config/config.yaml
        subPath: config.yaml
  volumes:
    - name: config-volume
      configMap:
        # Provide the name of the ConfigMap containing the files you want
        # to add to the container
        name: sherlock-config
  restartPolicy: Never
</code></pre>

<p>kubectl describe cm sherlock-config</p>

<pre><code>Name:         sherlock-config
Namespace:    default
Labels:       &lt;none&gt;
Annotations:  kubectl.kubernetes.io/last-applied-configuration:
                {"apiVersion":"v1","data":{"config.yaml":"namespaces:\n  - default\nlabels:\n  - \"app\"\n  - \"owner\"\n"},"kind":"ConfigMap","metadata":...

Data
====
config.yaml: &lt;------ This is the key
----
namespaces:
  - default
labels:
  - "app"
  - "owner"

Events:  &lt;none&gt;
</code></pre>
