In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
How to use Helm to update applications that use ConfigMap, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
Helm's little cool techs allows you to update applications that use ConfigMap simply and quickly. Change the contents of the configuration file at any time, and the application will be updated in real time according to the changes.
Helm makes the administration of Kubernetes applications effortless. Helm Charts makes it easier to install and upgrade Kubernetes applications. This article discusses one of Helm's great tricks: how to use Helm to update applications that use ConfigMap easily and quickly.
Update deployment
The example in the figure above is a configuration file for deployment. Let's assume that it is used to run the application. You can specify the pod template under the spec.template section. Now, if you want to update your application, you must change the content from this spec.template section. This means that after the container image changes, the deployment will be updated, but the spec.replicas will not change.
Update deployments using ConfigMap
Some applications require specific configuration files and values, and we do not recommend packaging these configuration files or configuration values into a container image, because if you do so, the container image must be recreated each time the configuration file changes. Kubernetes, on the other hand, provides a good way to manage profiles / values-- using ConfigMap resources.
There are two ways to expose ConfigMap data to a pod:
Env vars
Volume mounts
Next we will focus on exposing the volume mount of ConfigMap.
I created a very simple chart as an example to discuss this problem. In this chart, I have a configuration file for ConfigMap as follows:
As you can see, the name of ConfigMap is nginx-cm, and a file called default.conf is reading its data. This default.conf is a nginx configuration file.
Now I want to use this ConfigMap nginx-cm for my application. So I will expose it through the Volume Mounts in the configuration file of my application's deployment.
As in the example above, we need to add ConfigMap under the [volumes] section and give it a unique name (config-volume, as shown in the example). Then, we need to add this volume to the volume mount under the [containers] section. The volumeMounts.mountPath field is the exact location of the configuration files in the container that are available to the container.
So, using these configuration files, we can run applications that use the contents of the nginx configuration file provided by ConfigMap.
Next we need to change the nginx configuration file. After changing this configuration file, don't forget to update the ConfigMap accordingly, otherwise applications that use this ConfigMap will not use the updated content.
Of course, we can also use the kubectl update command to update ConfigMap. In theory, again, we should update the deployment next. So, can the kubectl update command be used to update the deployment?
When I tried to do this, I received the following message:
This is because the spec.template part of the deployment has not changed even after the ConfigMap resource has been updated. Even if the data portion of the ConfigMap changes, this does not cause any change in the deployment of the spec.template. One solution to this is to delete all pod managed by this deployment, and then the deployment creates a new pod, which uses the updated configMap.
But I don't like this approach very much, because you have to delete all pod manually, which is why I started looking for a better solution, which is the Helm tip in this article.
Https://github.com/kubernetes/helm/blob/master/docs/charts_tips_and_tricks.md#automatically-roll-deployments-when-configmaps-or-secrets-change
As you can see in the comments, you can provide the path to the configmap file and pass it to the sha256 sum function. In this way, each time the configmap file changes, the comments section is updated accordingly, which in turn updates the spec.template part of the deployment. I find this very good, because in this way, you can change the contents of your configuration file frequently. Because of this trick, Helm ensures that your application will always reflect these changes in a timely manner.
This is the answer to the question about how to use Helm to update applications that use ConfigMap. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.