Kubernetes

How do I edit a ConfigMap in kubectl?

Env files, or independent configuration files, are used in programming to hold settings, configurations, or parameters required to run the program. To achieve similar functionality in Kubernetes, we can also use ConfigMaps. ConfigMaps are helpful Kubernetes aspects that separate the configuration settings, allowing you to build light transferable images. ConfigMaps are beneficial for storing and exchanging unencrypted configuration data that is not complex. A ConfigMap is a collection of configuration parameters in the form of a dictionary. This collection is made up of string key-value pairs. These values are provided to your containers by Kubernetes. Like some other dictionaries, i.e., maps, hashes, etc., the key allows you to get and modify the configuration value. If you are using Kubernetes, you will want to keep your image as light and portable as possible. You must keep the configuration settings distinct from the application code to accomplish this. You can use ConfigMaps to add various configuration data to pods depending on the environment they are in. ConfigMap is identical to Secrets; ConfigMaps, on the other hand, are not ideal for storing sensitive information. They don’t have any encryption, and everyone who has access to the file can see everything in it. Kubernetes include secrets that can be used to store private data.Another factor to consider with ConfigMaps is file size, as we are striving to keep application settings ConfigMap files under 1MB. It is recommended to use different file mounts, databases, or local files for massive data sets. In this guide, we intend to learn the creation and editing of ConfigMaps in Kubernetes using kubectl.

Pre-requisites

Ensure you have minikube installed and configured before using kubectl to edit a ConfigMap on Ubuntu 20.04 LTS. For the completion of this comprehensive article, you should have sudo privileges.

Method to create ConfigMaps configuration file

To begin, you must first open a command-line terminal. You can do this operation by utilizing the shortcut key Ctrl+Alt+T or by scrolling between applications.

You must run the following written command in your console as immediately as your terminal window appears.

$ minikube start

To start with minikube, you have to pause for a few minutes after executing this program. You can also verify the minikube version exhibited after the command has been effectively executed.

Now we are ready to create ConfigMaps; for this purpose, we will use the touch command for file creation having. yaml extension.

The touch command is a basic yet important command in Linux systems that allows users to create files. It is one of the most basic terminal commands in Linux, and sysadmins frequently use it for a range of tasks. To execute the below-affixed command to create ConfigMaps configuration file.

$ touch configmap.yaml

There will be no output of this command on the terminal. The command will create a file in your home directory. You can verify it by going to the home directory of your Ubuntu 20.04 system. You can confirm that the file has been generated effectively.

Now we have to add some of the content in the file that we created earlier. The simplest approach to use ConfigMaps is to define them in YAML and mount them as a Volume. Create a YAML file with your ConfigMap’s key-value pairs. Here’s a sample ConfigMap with certain keys with single values and others with values that resemble a configuration style fragment.

You have to save the same content, and after saving it, you have to close the file. Now we are ready to create ConfigMaps in Kubernetes by utilizing the kubectl command. Execute the affixed command in the terminal shell of your Ubuntu 20.04 system.

$ kubectl create –f configmap.yaml

The output depicts the effective creation of the config map in Kubernetes.

Method to edit ConfigMaps in Kubernetes using kubectl

Now, if you want to edit the same file, check out the below-appended command in the shell of your Ubuntu 20.04 system.

$ kubectl edit configmap

Upon the execution of the above-cited command, the following output will appear. You can alter the file as per your work needs.

Conclusion

We have discussed the concept of a ConfigMap in Kubernetes in the article mentioned above. In addition, we expanded on how to use kubectl to form a ConfigMap. After reading this post, I am confident that you will have no doubts about changing and creating a ConfigMap in kubectl.

About the author

Kalsoom Bibi

Hello, I am a freelance writer and usually write for Linux and other technology related content