Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions cloudflare-worker/WORKERS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Deployment Summary
### Worker URL
https://lab17.error10556.workers.dev

### Main routes
- `/` - the main endpoint, increments counter
- `/counter` - returns `{"count": <number of main page requests>}`
- `/health` - returns `{"status": "ok"}`
- `/edge` - returns information about the Cloudflare deployment used for this request

### Configuration used
I added the `APP_NAME` env. variable (`lab17`) and the `KV` key-value storage binding. This allows to keep the `count`
persistent.

# Evidence
### Screenshot of Cloudflare dashboard
![Dashboard](/cloudflare-worker/screenshots/dashboard.png)

### Example `/edge` JSON response
```bash
curl https://lab17.error10556.workers.dev/edge | jq
```
```json
{
"colo": "ARN",
"country": "FI",
"city": "Helsinki",
"asn": 56971,
"httpProtocol": "HTTP/2",
"tlsVersion": "TLSv1.3"
}
```
It shows a Finnish location because my proxy is located there.

### Example log or metrics screenshot
![Metrics](/cloudflare-worker/screenshots/metrics.png)

Logs in **Observability**:
![Logs](/cloudflare-worker/screenshots/logs.png)

# Kubernetes vs Cloudflare Workers Comparison

| Aspect | Kubernetes | Cloudflare Workers |
|--------|------------|--------------------|
| Setup complexity | Very difficult | Easy |
| Deployment speed | Depends on network & hardware | Fast |
| Global distribution | No | Automatic |
| Cost (for small apps) | Usually overpriced | Free |
| State/persistence model | Persistent Volume Claims, StatefulSets | KV storage |
| Control/flexibility | Great | Can be insufficient |
| Best use case | Large deployments | Small projects |

# When to Use Each
### Scenarios favoring Kubernetes
- Large deployments
- Powerful dedicated clusters
- Large professional teams
- Systems of containers

### Scenarios favoring Workers
- Need for global deployment
- TypeScript, JavaScript, Python projects
- Simple apps

### Your recommendation
If I had to choose between the two, I would go with Kubernetes.

Sure, Kubernetes is often overrated by system administrators. Many projects actually don't need that level of
complexity, and are better off deploying with docker-compose.

But still, Cloudflare workers are a bit too dependent on the Cloudflare infrastructure and ecosystem. This is especially
apparent in Russia.

So I choose digital freedom (k8s).

# Reflection
### What felt easier than Kubernetes?
Literally every step was easier for Workers, except maybe setting up `minikube`, which was very easy. No need to learn
arbitrary config schemas and package everything in containers.

### What felt more constrained?
Kubernetes gives more freedom in what kind of program we are actually running. K8s allows to deploy any container and
set them up in any way we need, whereas Workers makes you follow its project structure.

### What changed because Workers is not a Docker host?
Cannot deploy arbitrary containers.
12 changes: 12 additions & 0 deletions cloudflare-worker/edge-api/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
167 changes: 167 additions & 0 deletions cloudflare-worker/edge-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# wrangler project

.dev.vars*
!.dev.vars.example
.env*
!.env.example
.wrangler/
6 changes: 6 additions & 0 deletions cloudflare-worker/edge-api/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 140,
"singleQuote": true,
"semi": true,
"useTabs": true
}
5 changes: 5 additions & 0 deletions cloudflare-worker/edge-api/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"wrangler.json": "jsonc"
}
}
Loading
Loading