如何确定.helmignore文件忽略了哪些文件

37次阅读
没有评论

问题描述

在安装本地Helm chart时遇到了一个错误Error: UPGRADE FAILED: create: failed to create: Request entity too large: limit is 3145728。通过搜索其他SO/Stack Exchange问题,发现这通常是由于错误地包含了不必要的文件导致的。解决这个问题的方法是将这些文件添加到.helmignore文件中。
用户的chart有一个.helmignore文件,应该在chart中排除所有不必要的文件,但是用户仍然遇到了错误。因此,用户认为自己的.helmignore条目可能没有正确地定位到应该排除的文件。
用户尝试使用--debug标志运行它们(没有显示更有趣的内容):

upgrade.go:139: [debug] preparing upgrade for chartnameupgrade.go:520: [debug] copying values from chartname (v11) to new release.upgrade.go:147: [debug] performing update for chartnameupgrade.go:319: [debug] creating upgraded release for chartnameError: UPGRADE FAILED: create: failed to create: Request entity too large: limit is 3145728helm.go:88: [debug] Request entity too large: limit is 3145728ffffcreate: failed to createhelm.sh/helm/v3/pkg/storage/driver.(*Secrets).Create        helm.sh/helm/v3/pkg/storage/driver/secrets.go:164helm.sh/helm/v3/pkg/storage.(*Storage).Create        helm.sh/helm/v3/pkg/storage/storage.go:69helm.sh/helm/v3/pkg/action.(*Upgrade).performUpgrade        helm.sh/helm/v3/pkg/action/upgrade.go:320helm.sh/helm/v3/pkg/action.(*Upgrade).RunWithContext        helm.sh/helm/v3/pkg/action/upgrade.go:148main.newUpgradeCmd.func2        helm.sh/helm/v3/cmd/helm/upgrade.go:200github.com/spf13/cobra.(*Command).execute        github.com/spf13/cobra@v1.2.1/command.go:856github.com/spf13/cobra.(*Command).ExecuteC        github.com/spf13/cobra@v1.2.1/command.go:974github.com/spf13/cobra.(*Command).Execute        github.com/spf13/cobra@v1.2.1/command.go:902main.main        helm.sh/helm/v3/cmd/helm/helm.go:87runtime.main        runtime/proc.go:255runtime.goexit        runtime/asm_arm64.s:1133UPGRADE FAILEDmain.newUpgradeCmd.func2        helm.sh/helm/v3/cmd/helm/upgrade.go:202github.com/spf13/cobra.(*Command).execute        github.com/spf13/cobra@v1.2.1/command.go:856github.com/spf13/cobra.(*Command).ExecuteC        github.com/spf13/cobra@v1.2.1/command.go:974github.com/spf13/cobra.(*Command).Execute        github.com/spf13/cobra@v1.2.1/command.go:902main.main        helm.sh/helm/v3/cmd/helm/helm.go:87runtime.main        runtime/proc.go:255runtime.goexit        runtime/asm_arm64.s:1133

用户还尝试使用--dry-run标志运行它,chart成功了。所以现在用户不确定如何找出是哪些文件导致了chart变大。
用户想知道如何确定在运行helm installhelm upgrade时实际被忽略(或包含)的文件。

解决方案

请注意以下操作注意版本差异及修改前做好备份。

方案1

用户可以通过在本地渲染chart并使用tree命令以人类可读的格式打印出子目录及其大小,来确定被忽略的文件。
以下是一个示例命令:

helm template . --output-dir=file-size-testtree --du -h file-size-test

这将产生类似于以下的输出:

[340M]  testing123└── [340M]  chart_name    ├── [ 91K]  charts    │   ├── [ 58K]  sub-chart    │   │   └── [ 58K]  templates    │   │       ├── [1.3K]  deployment.yaml    │   │       ├── [ 411]  config.yaml    │   │       ├── [ 579]  service.yaml    │   │       └── [ 359]  serviceaccount.yaml<truncated>    └── [340M]  templates        ├── [ 68M]  deployment.yaml        ├── [136M]  config1.yaml        ├── [136M]  config2.yaml        └── [1.3K]  ingress.yaml

通过上面的示例,用户发现问题似乎是由于巨大的config1.yamlconfig2.yaml文件导致的。
虽然这并没有完全回答如何找到被忽略的文件的问题,但至少指出了可能没有被忽略的文件。

方案2

使用脚本或工具来管理容器的启动顺序可能会增加复杂性,并且需要确保容器A和容器B之间的依赖关系正确设置。
另一种方法是编写脚本或使用工具来控制容器的运行顺序。你可以使用docker run命令来手动控制容器的启动顺序,或者使用一些第三方工具来管理容器的依赖关系。

示例:

以下是一个简单的bash脚本示例,可以在容器A启动后启动容器B:

#!/bin/bash
# 启动容器A
docker run -d --name container_a your_image_a
# 等待容器A完全启动
while ! docker exec container_a echo "Container A is ready"; do
  sleep 1
done
# 启动容器B
docker run -d --name container_b your_image_b

在这个示例中,我们首先使用docker run命令启动容器A,并将其命名为container_a。然后,使用一个循环来等待容器A完全启动(这里是通过在容器内运行echo命令来测试)。一旦容器A就绪,我们再使用docker run命令启动容器B,并将其命名为container_b

正文完