Monday, April 15, 2019

Use ConfigMap To Store Http.conf For Http Service Pod


    Lots of applications would have http service ie apache or nginx as the frontend. We often deploy pods of apache or nginx for it.  Take apache httpd as example, we often need to update httpd.conf for rewrite, redirect.....etc. It is ok to build a new docker image to achieve that ,but not efficient .  ConfigMap of K8S can store text and binary files in K8S, can be mounted in the pod. So we can leverage that to update httpd.conf without rebuilding the docker images. We can use same concept for all other config files of different apps ie nginx, ords...etc


  • Prepare for Dockerfile and your customized httpd.conf file . Example can be found on github repo
  • Once new docker image is built , we need to store httpd.conf into configmap via kubectl 
kubectl create configmap httpdconfig --from-file=httpd.conf 
  • Prepare for deployment yaml to mount configmap in the pod. Partial yaml file is like
            - name: httpd-config
                 name: httpdconfig
           - name: httpd
             image: httpd-configmap:v3
             imagePullPolicy: IfNotPresent
                - name: httpd-config
                  mountPath: /mnt/k8s
                - containerPort: 80

  • Kubectl command of updating httpd.conf  after we have new version of httpd.conf
kubectl create configmap httpdconfig --from-file=httpd.conf  -o yaml --dry-run | kubectl replace -f -
  • Bounce the http pod to let new pod  read the new configmap
  • It is the same concept and process for any other apps which have config files ie ORDS, Nginx.....etc
  • Configmap supports binary file as well ie wallets  see other note