You want to provide a configuration file to a container at runtime. Does this set of Kubernetes tools and steps accomplish this?
Solution: Mount the configuration file directly into the appropriate pod and container using the .spec.containers.configMounts key.
Answer(s): B
Explanation:
The solution given is not a valid way to provide a configuration file to a container at runtime using Kubernetes tools and steps. The reason is that there is no such key as .spec.containers.configMounts in the PodSpec. The correct key to use is .spec.containers.volumeMounts, which specifies the volumes to mount into the container's filesystem. To use a ConfigMap as a volume source, one needs to create a ConfigMap object that contains the configuration file as a key-value pair, and then reference it in the .spec.volumes section of the PodSpec. A ConfigMap is a Kubernetes API object that lets you store configuration data for other objects to use. For example, to provide a nginx.conf file to a nginx container, one can do the following steps:
Create a ConfigMap from the nginx.conf file:
kubectl create configmap nginx-config --from-file=nginx.conf
Create a Pod that mounts the ConfigMap as a volume and uses it as the configuration file for the nginx container:
apiVersion: v1
kind: Pod metadata:
name: nginx-pod spec:
containers:
- name: nginx image: nginx volumeMounts:
- name: config-volume mountPath: /etc/nginx/nginx.conf subPath: nginx.conf volumes:
- name: config-volume configMap:
name: nginx-config
Reference:
Configure a Pod to Use a Volume for Storage | Kubernetes
Configure a Pod to Use a ConfigMap | Kubernetes
ConfigMaps | Kubernetes
Reveal Solution Next Question