Created
January 8, 2020 22:28
-
-
Save mohclips/ad2f1b880320eb25038a50d9b7ed18f4 to your computer and use it in GitHub Desktop.
k8s configmap example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
kind: ConfigMap | |
apiVersion: v1 | |
metadata: | |
name: example-configmap | |
data: | |
# Configuration values can be set as key-value properties | |
# use '|' bar to add new line to each line, otherwise its missed out | |
database: | | |
mongodb | |
database_uri: | | |
mongodb://localhost:27017 | |
# Or set as complete file contents (even JSON!) | |
keys: | | |
image.public.key=771 | |
rsa.public.key=42 | |
some.other.key=123 | |
--- | |
kind: Pod | |
apiVersion: v1 | |
metadata: | |
name: pod-using-configmap | |
spec: | |
# Add the ConfigMap as a volume to the Pod | |
volumes: | |
# `name` here must match the name | |
# specified in the volume mount | |
- name: example-configmap-volume | |
# Populate the volume with config map data | |
configMap: | |
# `name` here must match the name | |
# specified in the ConfigMap's YAML | |
name: example-configmap | |
containers: | |
- name: container-configmap | |
image: alpine | |
# keep the container up - so we can login to it | |
command: ["sh", "-c", "tail -f /dev/null"] | |
# Mount the volume that contains the configuration data | |
# into your container filesystem | |
volumeMounts: | |
# `name` here must match the name | |
# from the volumes section of this pod | |
- name: example-configmap-volume | |
# this is where the config files are created in the container | |
mountPath: /etc/config | |
# now you can exec into the container and look at the files | |
# microk8s.kubectl exec -it pod-using-configmap sh | |
#/ # cd /etc/config/ | |
#/etc/config # cat keys | |
#image.public.key=771 | |
#rsa.public.key=42 | |
#some.other.key=123 | |
# this is an updated version of https://itnext.io/learn-how-to-configure-your-kubernetes-apps-using-the-configmap-object-d8f30f99abeb | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment