展示 HN:图表预览 – 在每个 PR 上为 Helm 图表提供预览环境
我是一名软件工程师,意外地成为了我们团队的Kubernetes专家,并最终成为每个Helm图表PR的瓶颈。
我开发了Chart Preview,这样审查者就可以在不等待我的情况下查看Helm图表的更改。
几年前,我们团队需要为一个现有产品实现高可用性,这意味着要在Kubernetes和OpenShift上进行部署。我花了几个月的时间学习Kubernetes、Helm及其相关生态系统。之后,Kubernetes在团队中基本上成了“我的事”。
后来,我们为该产品发布了公共Helm图表,客户开始提交PR。这些PR往往会搁置几个月——并不是因为更改不好,而是因为测试它们意味着需要手动启动一个Kubernetes集群,使用提议的更改部署图表,运行测试场景,并与产品和QA协调验证。由于我是一位能够可靠地设置这些环境的人,因此一切都得等我。
我一直在想:如果PR本身就能展示更改的效果,那会怎么样?如果审查者只需点击一个链接就能看到它被部署,那又会怎么样?
这个想法变成了Chart Preview。
Chart Preview在你打开PR时将你的Helm图表部署到一个真实的Kubernetes集群中,为该PR提供一个独特的预览URL,并在PR关闭时自动清理所有内容。
我开始时是解决我个人遇到的问题,而不是一开始就调查整个市场。在我构建更多功能时,我查看了现有的预览工具,注意到虽然有针对容器应用程序的良好预览解决方案,但Helm特定的工作流程引入了不同的挑战——图表依赖关系、分层值文件和有特定结构的图表。这促使我将Chart Preview的重点放在Helm原生上,而不是将容器预览工作流程适配到Helm。
在底层,它是用Go语言构建的,使用Helm v3 SDK。架构是一个API服务器,工作进程从PostgreSQL队列中提取任务——没有Kubernetes操作员,只有服务直接与Kubernetes API通信。每个预览在其自己的命名空间中运行,具有拒绝所有的网络策略、资源配额和限制范围。GitHub集成通过GitHub应用程序进行检查运行和Webhook,GitLab则通过REST API支持。
在这个过程中遇到了一些有趣的挑战。将预览主机名注入Ingress资源而不破坏清单需要几次迭代。Helm卸载并不总是能清理所有内容,因此删除整个命名空间被证明是最安全的后备方案。处理对同一PR的快速推送需要构建编号,以确保最新的推送始终胜出。尽管Helm SDK功能强大,但文档不足——我花了很多时间阅读Helm的源代码。
我已经用Grafana、podinfo和WordPress等真实图表构建和测试了几个月,以验证工作流程。虽然还处于早期阶段,但它确实有效,现在我正在尝试了解其他团队是否也有我曾经遇到的痛点。
你可以通过在这里安装GitHub应用程序来尝试它:
<a href="https://github.com/apps/chart-preview" rel="nofollow">https://github.com/apps/chart-preview</a>
我希望能收到一些反馈:
这是否解决了你们团队的真实问题,还是共享的预发布环境“足够好”?
还有什么缺失的功能会让你真正使用它?
是否有Helm图表不适用?(集群范围的资源是故意被阻止的。)
欢迎就实现方面的问题进行咨询。
查看原文
I’m a software engineer who accidentally became my team’s Kubernetes person — and eventually the bottleneck for every Helm chart PR.<p>I built Chart Preview so reviewers could see Helm chart changes running without waiting on me.<p>A few years ago, my team needed to implement HA for an existing product, which meant deploying on Kubernetes and OpenShift. I spent months learning Kubernetes, Helm, and the surrounding ecosystem. After that, Kubernetes largely became “my thing” on the team.<p>We later published public Helm charts for the product, and customers started submitting PRs. Those PRs would often sit for months — not because the changes were bad, but because testing them meant manually spinning up a Kubernetes cluster, deploying the chart with the proposed changes, running through test scenarios, and coordinating verification with product and QA. Since I was the only one who could reliably set up those environments, everything waited on me.<p>I kept thinking: what if the PR itself showed the changes working? What if reviewers could just click a link and see it deployed?<p>That idea became Chart Preview.<p>Chart Preview deploys your Helm chart to a real Kubernetes cluster when you open a PR, provides a unique preview URL for that PR, and cleans everything up automatically when the PR closes.<p>I started by solving a problem I was personally hitting, rather than surveying the whole market upfront. As I built more of it, I looked at existing preview tools and noticed that while there are solid solutions for previewing container-based applications, Helm-specific workflows introduce different challenges — chart dependencies, layered values files, and opinionated chart structures. That pushed me to focus Chart Preview on being Helm-native first, rather than adapting a container preview workflow to fit Helm.<p>Under the hood, it’s built in Go using the Helm v3 SDK. The architecture is an API server with workers pulling jobs from a PostgreSQL queue — no Kubernetes operator, just services talking directly to the Kubernetes API. Each preview runs in its own namespace with deny-all NetworkPolicies, ResourceQuotas, and LimitRanges. GitHub integration is done via a GitHub App for check runs and webhooks, with GitLab supported via the REST API.<p>There were a few interesting challenges along the way. Injecting preview hostnames into Ingress resources without corrupting manifests took several iterations. Helm uninstall doesn’t always clean everything up, so deleting the entire namespace turned out to be the safest fallback. Handling rapid pushes to the same PR required build numbering so the latest push always wins. And while the Helm SDK is powerful, it’s under-documented — I spent a lot of time reading Helm’s source code.<p>I’ve been building and testing this for a few months using real charts like Grafana, podinfo, and WordPress to validate the workflow. It’s early, but it works, and now I’m trying to understand whether other teams have the same pain point I did.<p>You can try it by installing the GitHub App here:
<a href="https://github.com/apps/chart-preview" rel="nofollow">https://github.com/apps/chart-preview</a><p>I’d love feedback on a few things:<p>Does this solve a real problem for your team, or is shared staging “good enough”?<p>What’s missing that would make you actually use it?<p>Are there Helm charts this wouldn’t work for? (Cluster-scoped resources are intentionally blocked.)<p>Happy to answer questions about the implementation.