我有一个在kubernetes上部署的Django应用程序。该容器还具有永久卷的装载,该永久卷包含一些操作所需的文件。我想进行一次检查,以确保每次Pod启动时文件都在其中并且可以在运行时访问。 Django文档建议不要在生产环境中运行检查(该应用程序在uwsgi中运行),并且由于这些文件仅在生产环境中可用,因此在单元测试时检查将失败。
在生产中执行检查的可接受流程是什么?
请您参考如下方法:
这是发布的社区Wiki答案,以提高可见性。随意扩展它。
您的用例可以从Kubernetes的 Angular 解决。您所要做的就是使用Startup probes:
The kubelet uses startup probes to know when a container application has started. If such a probe is configured, it disables liveness and readiness checks until it succeeds, making sure those probes don't interfere with the application startup. This can be used to adopt liveness checks on slow starting containers, avoiding them getting killed by the kubelet before they are up and running.
有了它,您可以使用 ExecAction,它将在容器内执行指定的命令。如果命令以状态代码0退出,则诊断将被认为是成功的。简单命令检查的一个示例可能是检查特定文件是否存在的命令:
exec:
command:
- stat
- /file_directory/file_name.txt
您也可以使用Shell脚本,但请记住:
Command is the command line to execute inside the container, the working directory for the command is root ('/') in the container's filesystem. The command is simply exec'd, it is not run inside a shell, so traditional shell instructions ('|', etc) won't work. To use a shell, you need to explicitly call out to that shell.




