英文:
Using Helm For Deploying Spring Boot Microservice to K8s
问题
我们已经构建了几个微服务(MS),并将它们部署到我们公司的K8s集群中。
对于当前的部署,我们的任何一个微服务都会被构建为一个Docker镜像,并且使用以下步骤手动部署;这种方式运行良好:
- 创建Configmap
- 安装Service.yaml
- 安装Deployment.yaml
- 安装Ingress.yaml
我现在正在研究Helm v3,以简化和封装这些部署过程。我已经阅读了很多关于Helm v3的文档,但在吸收整个文档以及Go和SPRIG之前,我仍然没有找到一些简单问题的答案,希望在这里得到答案,以免发现它不能满足我们的需求。
我们的Spring微服务有5个单独的application.properties文件,针对我们的5个环境分别设置。这些属性文件是简单的多行key=value格式,其中一些注释以*#*开头。
# 基于环境的值
key1=value1
key2=value2
使用helm create命令,我在根目录下安装了一个名为*./deploy的chart,它自动创建了./templates和一个values.yaml*文件。
问题是,我需要在Chart的*./deploy目录之外访问application.properties*文件。
我希望能够在我的configmap.yaml的Data部分中从Helm中引用这两个文件。
- ./src/main/resource/dev/application.properties
- ./src/main/resources/logback.xml
而且我希望保持这些文件的当前格式,而不是将它们重写为JSON/YAML格式。
Helm v3是否允许这样做?
英文:
We have build a few Microservices (MS) which have been deployed to our company's K8s clusters.
For current deployment, any one of our MSs will be built as a Docker image and they deployed manually using the following steps; and it works fine:
- Create Configmap
- Installing a Service.yaml
- Installing a Deployment.yaml
- Installing an Ingress.yaml
I'm now looking at Helm v3 to simplify and encapsulate these deployments. I've read a lot of the Helm v3 documentation, but I still haven't found the answer to some simple questions and I hope to get an answer here before absorbing the entire doc along with Go and SPRIG and then finding out it won't fit our needs.
Our Spring MS has 5 separate application.properties files that are specific to each of our 5 environments. These properties files are simple multi-line key=value format with some comments preceded by #.
# environment based values
key1=value1
key2=value2
Using helm create, I installed a chart called ./deploy in the root directory which auto-created ./templates and a values.yaml.
The problem is that I need to access the application.properties files outside of the Chart's ./deploy directory.
From helm, I'd like to reference these 2 files from within my configmap.yaml's Data: section.
- ./src/main/resource/dev/application.properties
- ./src/main/resources/logback.xml
And I want to keep these files in their current format, not rewrite them to JSON/YAML format.
Does Helm v3 allow this?
答案1
得分: 1
将这个作为答案,因为评论区没有足够的空间!
请查看我上面分享的12因素应用程序链接,特别是配置部分... 那里的解释不是很好,但其背后的思想是构建一个容器,并在任何环境中部署该容器,而无需修改它,同时还能够在不创建新版本的情况下更改配置(如果配置嵌入在容器中,则无法完成后者)。例如,这允许在不发布新版本的情况下更改数据库连接池大小(或任何其他配置参数)。从安全角度来看,这也是很好的,因为您可能不希望在较低的环境(开发/测试/等等)中运行容器时使用生产配置(密码、API密钥等)。这种方法类似于持续交付原则中的构建一次,随处部署。
我假设当您在本地运行应用程序时,您只需要访问一组配置,因此您可以将其保存在一个单独的文件中(例如application.dev.properties),并在helm环境变量中保存在环境之间变化的参数。我知道您提到您不想这样做,但这在现在被认为是一种良好的实践(将来可能会有不同看法...)。
我还认为实事求是很重要,如果在您的情况下,您不觉得有必要将配置放在容器之外,那就不要这样做,可能使用我提供的建议来更改命令行参数以选择配置文件会很好。同时,记住12因素应用程序的方法,以防您在将来发现需要它。
英文:
Putting this as answer as there's no enough space on the comments!
Check the 12 factor app link I shared above, in particular the section on configuration... The explanation there is not great but the idea is behind is to build one container and deploy that container in any environment without having to modify it plus to have the ability to change the configuration without the need to create a new release (the latter cannot be done if the config is baked in the container). This allows, for example, to change a DB connection pool size without a release (or any other config parameter). It's also good from a security point of view as you might not want the container running in your lower environments (dev/test/whatnot) having production configuration (passwords, api keys, etc). This approach is similar to the Continuous Delivery principle of build once, deploy anywhere.
I assume that when you run the app locally, you only need access to one set of configuration, so you can keep that in a separate file (e.g. application.dev.properties), and have the parameters that change between environments in helm environment variables. I know you mentioned you don't want to do this, but this is considered a good practice nowadays (might be considered otherwise in the future...).
I also think it's important to be pragmatic, if in your case you don't feel the need to have the configuration outside of the container, then don't do it, and probably using the suggestion I gave to change a command line parameter to pick the config file works well. At the same time, keep in mind the 12 factor-app approach in case you find out you do need it in the future.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论