Repository navigation
Add a sample that runs a cluster on Kubernetes - #8274
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8274 +/- ##
==========================================
- Coverage 67.61% 67.61% -0.01%
==========================================
Files 871 871
Lines 220304 220317 +13
Branches 32941 32941
==========================================
+ Hits 148959 148961 +2
- Misses 51847 51859 +12
+ Partials 19498 19497 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
cec265d to
15a195d
Compare
ee562f1 to
e0392fd
Compare
e0392fd to
428b36f
Compare
There was a problem hiding this comment.
Superseded by the review of
5566ada2.
This review, of 428b36fa
💬 Approved with comments — The code changes look correct. Key and bucket loading, the --cluster-addr join, compiled-binary guards and do-storage handling all hold up. One WARNING: the sample README says workflows is an error in a cluster, but the code accepts it.
Findings: 1 warning (1 is an inline comment on the diff)
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
🔧 Fix with your agent
Paste the following into your coding agent to investigate and fix these issues.
Fix the following code review issues found in pull request #8274.
Before making changes, review each issue and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g., the fix would require disproportionate changes
for minimal ROI, or the finding is factually incorrect), explain why
- If you need to clarify something before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
## WARNING (1)
### [Documentation] README says any wrangler field outside the list is an error in a cluster, but `workflows` is accepted (wrangler.rs check_experimental only rejects kv_namespaces and queues).
- **File:** samples/kubernetes/README.md:131
📝 Documentation: ⚠️ 1 warning
The sample README says workflows is an error in a cluster, but the code accepts it.
Recommendation: 📝 Minor Comments
- [WARNING] README says any wrangler field outside the list is an error in a cluster, but
workflowsis accepted (wrangler.rs check_experimental only rejects kv_namespaces and queues). (samples/kubernetes/README.md:131)
View full review
samples/kubernetes/README.md:131-133lists the wrangler fields allowed in a cluster and says "Any other field is an error".workflowsis missing from that list.check_experimentalinsrc/workerd/server/cli/wrangler.rs:546-558rejects onlykv_namespacesandqueuesfor--cluster-addr, soworkflowsis accepted. The PR description says the same.
✅ All other checks passed
🔒 Security: ✅ LGTM
No security issues found. Taking the cluster key from an environment variable or a mounted file keeps the secret out of configs, images and compiled binaries. The key file is size-limited and must be a regular file.
📖 AGENTS.md: ✅ LGTM
The updates to src/workerd/server/AGENTS.md raise no issues.
📋 Code Quality: ✅ LGTM
No problems found in the code:
- Joining a cluster without
--experimental: the join still reaches the server's refusal. - Filling in the key and bucket from the environment: the code rejects setting both key variables, a blank key, and a key file that is not a regular file, is over 4096 bytes or is not UTF-8. It checks that the path is a regular file before opening it, so a FIFO or device is never opened.
- Compiled binaries:
run_compiledrefuses--cluster-addrwhen no cluster was compiled in, andcompilenever reads the environment. - Overriding storage with
--directory-path:.wrangler/state/workerdis no longer created beside the config. - Build wiring:
test_compile_datacovers the sample files that the tests embed.
⚡ Performance: ✅ LGTM
No performance concerns.
Reviewed commit: 428b36fa
428b36f to
2a83a4c
Compare
97c28f3 to
6b060de
Compare
6b060de to
5566ada
Compare
This sample runs a Wrangler project on three workerd pods in cluster mode, with no Cap'n Proto config. Kubernetes rolls out new versions of the app image, and each pod hands off its Durable Objects to the other pods before it stops. The sample works on many Kubernetes clusters, but it requires a load balancer implementation that can provision Services of type `LoadBalancer`. Managed Kubernetes services and k3s provide one; a kind cluster needs cloud-provider-kind. The sample doesn't use a real object storage bucket. A single RustFS instance in the cluster emulates an S3 bucket. For production use, the README recommends a real bucket, such as R2, S3, or Cloud Storage, and describes how to configure one. The sample consists of the following: * `app/` is a Wrangler project that sets `no_bundle`. It returns `hello world` on `/` and runs a Durable Object counter on `/counter/NAME`. The response shows which pod accepted the request and which pod runs the object. The Dockerfile copies the project into `docker.io/cloudflare/workerd`. `WORKERD_IMAGE` selects a different workerd image, such as a pinned release or one built from source. * In `kubernetes.yaml`, each pod joins the cluster with `--cluster-addr=$(POD_IP):7000` and keeps its state on an `emptyDir` volume with `--data-dir=/data`. The cluster key is a Secret that's mounted as a file, and the readiness probe is `/ready` on the cluster port. `WORKERD_SHUTDOWN_DELAY_MS` keeps a terminating pod serving for 20 seconds while a cloud load balancer might still send it requests, and `WORKERD_CLUSTER_STOP_TIMEOUT_MS` limits its handoff to 8 seconds. Rollouts hand off one pod at a time, a PodDisruptionBudget limits drains, and a NetworkPolicy lets only the workerd pods connect to the cluster port. The pods meet the "restricted" Pod Security Standard and have read-only root file systems. * The app's Service is of type `LoadBalancer` on port 80, so the README sends requests from outside the cluster. On a cloud provider, the load balancer's address is public, and the README cautions about this. * The demo bucket is a RustFS StatefulSet with one pod and a persistent volume. A Job creates the bucket with `curl --aws-sigv4`. RustFS and the workerd pods share credentials from a Secret, and a NetworkPolicy lets only the workerd pods and the Job connect to RustFS. * The README covers running the sample, a load test during a rollout that counts failed requests and skipped or repeated counts, cleanup, building an image for another project, the Wrangler fields that a cluster supports, using a real bucket, keeping versions compatible during a rollout, and the limitations of cluster mode. When a Wrangler config file is missing, the error message now names the `wrangler.json`, `wrangler.jsonc`, or `wrangler.toml` file next to the given path, if one exists. The CLI test translates the sample app the same way that its pods do. On k3s, the README's rollout test through the load balancer served 2,699 requests with no failed requests and no skipped or repeated counts.
5566ada to
ee682fa
Compare
There was a problem hiding this comment.
Superseded by the review of
ee682fa3.
This review, of 5566ada2
✅ Approved — The earlier README issue about workflows is fixed. I found no new problems in the Rust change, the tests, the manifests or the sample app.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
Pods run as non-root with all capabilities dropped and read-only root filesystems. Credentials and the cluster key come from Secrets. NetworkPolicies limit access to the cluster port and to RustFS. The Rust change only adds a hint to a CLI error message.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md concerns.
📋 Code Quality: ✅ LGTM
The missing_config hint, the new tests in wrangler-test.rs that translate the sample app, and the Bazel wiring for the embedded sample files all look correct.
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
The README's list of supported Wrangler fields now includes workflows. It says that only kv_namespaces and queues are errors, which matches check_experimental in wrangler.rs.
Reviewed commit: 5566ada2
There was a problem hiding this comment.
✅ Approved — The earlier README issue about workflows is fixed. I found no new problems in the Rust change, the tests, the manifests or the sample app.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
Pods run as non-root with all capabilities dropped and read-only root filesystems. Credentials and the cluster key come from Secrets. NetworkPolicies limit access to the cluster port and to RustFS. The Rust change only adds a hint to a CLI error message.
📖 AGENTS.md: ✅ LGTM
No AGENTS.md concerns.
📋 Code Quality: ✅ LGTM
The missing_config hint, the new tests in wrangler-test.rs that translate the sample app, and the Bazel wiring for the embedded sample files all look correct.
⚡ Performance: ✅ LGTM
No performance concerns.
📝 Documentation: ✅ LGTM
The README's list of supported Wrangler fields now includes workflows. It says that only kv_namespaces and queues are errors, which matches check_experimental in wrangler.rs.
Reviewed commit: ee682fa3 — same changes as 5566ada2, so this is that commit's review (no new review was run; line numbers are as of 5566ada2)
This sample runs a Wrangler project on three workerd pods in cluster
mode, with no Cap'n Proto config. Kubernetes rolls out new versions of
the app image, and each pod hands off its Durable Objects to the other
pods before it stops.
The sample works on many Kubernetes clusters, but it requires a load
balancer implementation that can provision Services of type
LoadBalancer. Managed Kubernetes services and k3s provide one; a kindcluster needs cloud-provider-kind.
The sample doesn't use a real object storage bucket. A single RustFS
instance in the cluster emulates an S3 bucket. For production use, the
README recommends a real bucket, such as R2, S3, or Cloud Storage, and
describes how to configure one.
The sample consists of the following:
app/is a Wrangler project that setsno_bundle. It returnshello worldon/and runs a Durable Object counter on/counter/NAME. The response shows which pod accepted the requestand which pod runs the object. The Dockerfile copies the project into
docker.io/cloudflare/workerd.WORKERD_IMAGEselects a differentworkerd image, such as a pinned release or one built from source.
kubernetes.yaml, each pod joins the cluster with--cluster-addr=$(POD_IP):7000and keeps its state on anemptyDirvolume with
--data-dir=/data. The cluster key is a Secret that'smounted as a file, and the readiness probe is
/readyon the clusterport.
WORKERD_SHUTDOWN_DELAY_MSkeeps a terminating pod serving for20 seconds while a cloud load balancer might still send it requests,
and
WORKERD_CLUSTER_STOP_TIMEOUT_MSlimits its handoff to8 seconds. Rollouts hand off one pod at a time, a PodDisruptionBudget
limits drains, and a NetworkPolicy lets only the workerd pods connect
to the cluster port. The pods meet the "restricted" Pod Security
Standard and have read-only root file systems.
LoadBalanceron port 80, so the READMEsends requests from outside the cluster. On a cloud provider, the
load balancer's address is public, and the README cautions about
this.
volume. A Job creates the bucket with
curl --aws-sigv4. RustFS andthe workerd pods share credentials from a Secret, and a NetworkPolicy
lets only the workerd pods and the Job connect to RustFS.
that counts failed requests and skipped or repeated counts, cleanup,
building an image for another project, the Wrangler fields that a
cluster supports, using a real bucket, keeping versions compatible
during a rollout, and the limitations of cluster mode.
When a Wrangler config file is missing, the error message now names the
wrangler.json,wrangler.jsonc, orwrangler.tomlfile next to thegiven path, if one exists. The CLI test translates the sample app the
same way that its pods do.
On k3s, the README's rollout test through the load balancer served
2,699 requests with no failed requests and no skipped or repeated
counts.