Configure applications via configuration maps
Let’s learn how to configure applications via configuration maps on SPEKTRA Edge.
A configuration map allows you to decouple environment-specific configuration from your application images, so that your applications are easily portable.
You can map the application configuration to the particular containers under the application with the following steps:
- Create a configuration map
- Create an application with docker compose volumes service attribute
to describe the configuration to be mounted on the container
through the following two in-direction:
- Configuration map volume to map the configuration map to the application
- Host volume to mount the configuration to the host environment so that the application can mount the configuration to the particular container.
We’ll use the Nginx application and source the configuration file through the configuration map to demonstrate how to use the configuration map on SPEKTRA Edge.
What you need
To go through this page, you need the followings.
- an access to the SPEKTRA Edge dashboard
- an active project
- a device provisioned under the project
And also, the cuttle CLI command is necessary to complete this tutorial, which is used to access the Nginx application from the local machine for the verification purpose. However, it is not required for deploying applications on SPEKTRA Edge.
Note
The getting started guide will help you to set those requirements up. Please go through the guide in case if you miss some of those.Application files
compose.yaml
It’s a simple Nginx application with mapping the port 8000 with the configuration directory mounted through the volumes attributes.
services:
app:
image: nginx:alpine
ports:
- 8000:8000
volumes:
- /isodevice/data/nginx/conf.d:/etc/nginx/conf.d
/isodevice/data
We recommend to use the /isodevice/data directory as the host side of the volume mount entry point. It’s a persistent file system and will keep the mapped contents even through the power cycle.nginx.conf
Here is the Nginx configuration file, which will be mapped to the application through the SPEKTRA Edge configuration map.
It’s a simple configuration file, which make it listen on the port 8000, instead of port 80. Since we override the default configuration, we also sets the content root to the default Ngnix content directory with root directive.
server {
listen 8000;
root /usr/share/nginx/html;
}
Nginx beginner's guide
Please take a look at the Nginx beginner’s guide if you are not familier with the Nginx configuration file format.Deploy the application
Let’s deploy the application with the configuration map on SPEKTRA Edge.
Here is the steps to follow:
- Create a configuration map
- Create the application with two new resources:
- the configuration map volume to map the configuration map created above to the application
- the host volume to mount the configuration to the host environment for the load balancer container to mount the configuration file to.
Let’s do it.
Create a configuration map
Let’s create a configuration map to store the Nginx configuration file on SPEKTRA Edge.
First, select the Config maps option of the Applications pull-down menu.
Select Config maps option from the Applications pull-down menu.
Then, create a configuration map by pasting the nginx.conf file content in the data key value field with the default.conf as the data key name.
Create configuration map by pasting the nginx.conf content in the data key value field.
Make sure you set:
- nginx-conf as the configuration map name
- default.conf as the configuration data key name
Those names are important because it’s referenced by the other object in the later steps.
Create the application
With the Nginx configuration map ready, let’s deploy the application.
Here is what we’ll do:
- Paste the docker compose file content to the Docker Compose field
- Create a volume config map for the Nginx configuration file mapping
- Create a host volume to mount the above configuration map to the device
We’ll go over those points step-by-step below but first, let’s have a Deploy pod page ready by clicking the Deploy pod button on the Project overview page.
Click Deploy pod button on the Project overview page to deploy application.
Docker compose file
Let’s paste the docker compose file to the Docker Compose field of the Deploy pod page.
Docker compose section of the Deploy pod page.
Volume configuration map
The next is the volume configuration map, which maps the Nginx configuration file we created before to the application as a volume.
Volume config map section of the Deploy pod page.
Here is the key points to highlight:
- Select the correct configuration map
- projects/your-project/regions/us-west2/configMaps/nginx-conf for this example
- Specify the correct select key of the configuration map item
- default.conf in this example, as we specified as the key value name for the Nginx configuration file when we created the configuration map.
- Use default.conf for the path name of the select key
- This is the file name which will be shown in the container. Nginx expects this file name as the default Nginx configuration file.
Host volume
This is the last item to configure on the Deploy pod page.
It mounts the volume configuration map we create above to the host environment of the device. This file will be mounted to the Nginx load-balancer container through the docker compose file we explained before.
Host volume section of the Deploy pod page.
Again, there are a couple of things to make it right.
- the volume name should match the name of the volume configuration map we
created above
- nginx-conf in this example
- the Volume mount path should be matched to the one specified in the
docker compose
- /isodevice/data/nginx/conf.d in this example
Click to deploy
With all those configuration set, click the Deploy button on the Deploy pod page to deploy the application on your device.
Click Deploy button on Deploy pod page to deploy the application.
With a minute or so, you should be able to see the application running on your device, as below.
Running status shown on the application overview page.
Verify the application
Let’s verify the application by accessing it through the port forwarding.
Go to the application overview page by clicking the name of the app, Three tier web app in this example, on the Project overview page.
Click the name of the application on the Project overview page to go to the application overview page.
From there, copy the port forward command by clicking the Copy port forward as Cuttle command button on the application overview page.
Copy the port forward command to access the Nginx service on the application overview page.
Run the command on your local terminal window to make your application accessible from your browser.
cuttle devices forward-port \
projects/your-project/regions/us-west2/devices/pp-quick-202410-dmphwxuzhh8nyw \
8000 tcp://127.0.0.1:8000
Please note that the device name above will be different for your case.
Device name
The first argument of the port forward command above, which starts with projects/, is the device name on which the application is running. It contains both the project and the region name to differenciate from other devices.Point your browser to http://localhost:8000 and you should be able to see the page below.
The Nginx application accessed through http://localhost:8000.
Next step
Congratulations on configuring the Nginx application with the configuration map on SPEKTRA Edge.
Let’s go ahead and understand how to monitor and control applications as the next step.