Monday, May 9, 2022

A simple nginx deployment on IBM Cloud Code Engine

HTML files as configmap in Code Engine
Over the weekend I deployed nginx on IBM Cloud Code Engine. It's nothing fancy or earth-moving. But I wanted to note down and share the steps with you on how to deploy this HTTP server and serve few static HTML pages. All is based on using the command line interface (CLI) and is done with few commands.

HTML pages as configmap

In preparation to the nginx deployment, I looked into how to serve the few HTML pages. I found that with Code Engine I can create so-called configmaps and later make them available as mounted files. Thus, I can first compose a new configmap with the individual HTML pages, then mount the configmap and thereby make those files available to nginx.

For my experiment, I used two HTML files with their content shown in the screenshot above. After logging in to IBM Cloud and selecting the Code Engine project, the files serve as input for the new configmap "html-files" as part of "configmap create":

ibmcloud ce configmap create -n html-files -f index.html -f foobar.html

Mount configmap as nginx directory

Next, and already as final step, I created a Code Engine app "nginx-app" from the official nginx container image on Dockerhub. The configmap with the files is mounted to "/usr/share/nginx/html". And I need to tell Code Engine that nginx is using port 80.

ibmcloud ce app create --name nginx-app --image nginx --mount-cm /usr/share/nginx/html=html-files --port 80

Index page served by nginx on Code Engine


The above shows the index page served by nginx. I use a custom domain for the Code Engine app and even made the app available under a subpath "abc". But that is part of another blog post.

By editing the HTML file, then updating the configmap, it is possible to change the content delivered by my deployed nginx server.

If you have feedback, suggestions, or questions about this post, please reach out to me on Twitter (@data_henrik) or LinkedIn.