Kubernetes ConfigMap volume mounting¶
ConfigMap volume mounting is a method in Kubernetes for decoupling configuration artifacts from image content to maintain container portability.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]
Mechanism¶
A ConfigMap stores a series of configuration data as key-value pairs.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md] To make this data available to a container, it can be mounted as a volume.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md] The kubernetes kubelet is responsible for generating these files, retrieving the content from the ConfigMap source.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]
Configuration¶
To implement this, the Pod or Deployment definition must include two main specifications:
- Volumes: A volume of type
ConfigMapis defined in thespec.volumessection, referencing the name of the ConfigMap resource.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md] - VolumeMounts: The container specification includes a
volumeMountthat maps this volume to a specific directory path inside the container filesystem (e.g.,/config).^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]
Example¶
The following example demonstrates a Deployment mounting a ConfigMap named apollo-configservice-cm into the /apollo-configservice/config directory of the container.^[400-devops__06-Kubernetes__k8s-paas__06.在K8S中集成Apollo配置中心.md]
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: apollo-configservice
spec:
template:
spec:
volumes:
- name: configmap-volume
configMap:
name: apollo-configservice-cm
containers:
- name: apollo-configservice
image: harbor.od.com/infra/apollo-configservice:v1.5.1
volumeMounts:
- name: configmap-volume
mountPath: /apollo-configservice/config