Thursday, February 14, 2019

How To Put Binary or Text Config Files into K8s ConfigMap

Requirement:

  We often have all kind of config files for our Apps.  From binary wallet files to simple text config files, we need to store them somewhere where apps can access.  It is not a good idea to put these config files inside docker images or PV(persistent volume) as it would make the pod less portable and hard to scale and migrate. Fortunately from K8S v1.10 , Configmap would support both binary and text config files .  Here are some examples how we utilize configmap to achieve that. Mounted configmap are updated automatically. More details please refer kubernetes configmap doc

Solution:

We plan to create 2 configmaps . One for binary files like ewallet and one for text config files  like sysctl.conf, init.ora....

  • Use kubectl create configmap walletconfigmap --from-file=ewallet1 --from-file=ewallet2
  • Use kubectl create configmap textconfigmap --from-file=sysctl.conf  --from-file=jdbc.xml  --from-file=init.ora  
  • Use kubectl get configmap walletconfigmap -o yaml . You would see ewallet would be stored as binaryData

apiVersion: v1
items:
- apiVersion: v1
  binaryData:
    ewallet: sdfsweffewg.....
........
  • Mount wallet configmap as a volume in the pod with correct config file path . ie wallet file is on /etc/oracle/tde
  • Mount text configmap as a volume in the pod with correct config file path . ie text file is on /opt/oracle/dbs
volumes:
- name: wallet-volume
  configMap:
          name: walletconfigmap 
- name: textconfig-volume
   configMap:
          name: textconfigmap 

Under container section of yaml file
volumeMounts:
- name: wallet-volume
  mountPath: /etc/oracle/tde
- name: textconfig-volume
  mountPath: /opt/oracle/dbs

  • In this way, when we into the pod via kubectl exec -it  <pod name> /bin/bash , we would see ewallet1 ewallet2 in /etc/oracle/tde  and  sysctl.conf jdbc.xml and init.ora are in /opt/oracle/dbs.
  • If we do some updates on configmap , K8S will sync them periodically.

No comments: