Mounting Single File From Configuration Map In Kubernetes/Openshift Pod

 Background

Sometimes, we need to override a single file in a pod without having to build a new image.
There is a technique to do this, so this blog would serve to remind me of the steps involved doing just that.

1. Create A Configuration Map

First we need to copy the original file to the notepad. The steps are :

yudhi@Yudhis-MacBook-Pro ~ % oc project apifinance

Now using project "apifinance" on server "https://lb.osh.telkom.co.id:8443".

yudhi@Yudhis-MacBook-Pro ~ % oc get po

NAME                    READY     STATUS      RESTARTS   AGE

finance-2-chm5g         1/1       Running     0          211d

finance-3-build         0/1       Completed   0          248d

financeapi-46-8wmfh     1/1       Running     0          30d

proxy-finest-10-1btmq   1/1       Running     0          58d

yudhi@Yudhis-MacBook-Pro ~ % oc rsh proxy-finest-10-1btmq

sh-4.4$ cd /etc/httpd

sh-4.4$ ls

conf  conf.d  conf.modules.d  logs  modules  run  state

sh-4.4$ cd conf.d

sh-4.4$ ls

README autoindex.conf php.conf  ssl.conf  userdir.conf  welcome.conf

sh-4.4$ cat ssl.conf

#

# When we also provide SSL we have to listen to the 

# standard HTTPS port in addition.

#

Listen 0.0.0.0:8443 https


##

##  SSL Global Context

##

##  All SSL configuration in this context applies both to


Copy the ssl.conf file into the clipboard.

Next we need to create a configuration map. Enter the file name we need to override as the config map's key. And paste the clipboard content into the Value text box.



2. Mount the file from the configuration map into the original path.

Click on the link "Add Config Files"


Type the path of the file we want to override.


3. Edit the deployment yaml to add subpath


Edit the deployment yaml, and find this section :
 volumeMounts:
            - mountPath: /etc/httpd/conf.d/ssl.conf
              name: volume-38kso
And turn it into :
 volumeMounts:
            - mountPath: /etc/httpd/conf.d/ssl.conf
              name: volume-38kso
              subPath: ssl.conf


Thus these are the steps needed to mount a single file into an existing file in an existing directory in the pods. 

Comments

Popular posts from this blog

Long running process in Linux using PHP

Reverse Engineering Reptile Kernel module to Extract Authentication code

SAP System Copy Lessons Learned