
2025年上班族AI副業指南:下班后賺錢輕松月入過萬
“那一刻,我第一次體會到什么叫‘Lua 插件的熱升級’——它熱得像巖漿,把整條流量通路都燒穿了。”
以上畫面,來自 2025 年 7 月 14 日,某跨境電商大促前最后一次封板演練。主角就是本文的主角——Kong Gateway 3.8。
如果你正準備從 3.7.x 甚至 3.6.x 直接躍遷到 3.8,建議先泡一杯咖啡,再把我這篇踩坑日記當恐怖片看——因為今晚的鬼,可能明晚就爬到你家網關。
目標版本:Kong 3.8.1.1(2025-04-10 發布)
升級動機:
kong.telemetry.log
能把 trace 直接對接 OpenTelemetry; 環境:
預演劇本:
看起來穩如老狗,對吧?
00:11 —— Ansible 把最后一個節點升級到 3.8,Kong 進程優雅重啟,status 接口 200。
00:12 —— Nginx error.log 突然像機槍掃射:
2025/06/14 00:12:41 [error] 42#0: *154437 lua entry thread aborted: runtime error: .../kong/plugins/custom-auth/handler.lua:89: attempt to index local 'conf' (a nil value)
while sending to client, client: 10.244.5.21, server: kong, request: "GET /api/order/123 HTTP/2.0", upstream: "http://10.244.9.77:8080", host: "mall.example.com"
緊接著,Prometheus 的 kong_http_status{code="502"}
從 0 飆到 8000+ qps。
custom-auth
插件在 init_worker
階段會讀取 Redis 集群地址,而在 3.8 中 Kong 對 Redis 配置校驗更嚴格,redis.timeout
與 redis.connect_timeout
不一致會直接拒絕加載插件。 當時我們想:回滾!但悲劇的是——
store_metadata
等,直接 pg_dump
回去會導致舊版本 Kong 啟動時 schema 校驗失敗; 于是群里出現一句絕望名言:
“升上去是英雄,想下來是狗熊。”
凌晨 1:00,我們決定徹底放棄“滾動升級”,啟用藍綠:
deck 在 1.29 之后支持 --rbac-resources-only
和 --select-tag
,我們把“藍綠”玩出了花:
# 1. 從藍集群(3.7)dump 出干凈的配置
deck dump --kong-addr https://blue-admin:8444 \
--headers "kong-admin-token:$TOKEN" \
--output-file blue-3.7.yaml \
--skip-consumers false
# 2. 把藍配置同步到綠集群(3.8)并強制覆蓋
deck diff --kong-addr https://green-admin:8444 \
--state blue-3.7.yaml \
--headers "kong-admin-token:$TOKEN"
deck sync --kong-addr https://green-admin:8444 \
--state blue-3.7.yaml \
--headers "kong-admin-token:$TOKEN"
從 dump 到 ALB 切流,全程 120 秒,SLA 掉到 99.92% 后馬上回升到 99.99%。
redis.timeout
與 redis.connect_timeout
,否則 3.8 啟動即崩潰。 schema.lua
里加 legacy = true
標記,讓 3.7 和 3.8 都能識別。 spec/03-plugins
寫單元測試,斷言插件重載后 worker 不崩潰。 我們把當晚的腳本抽象成了 GitHub Actions workflow(已脫敏):
name: blue-green-upgrade
on:
workflow_dispatch:
inputs:
version:
description: 'target Kong version'
required: true
default: '3.8.1.1'
jobs:
build-green:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: build green AMI
run: |
packer build -var kong_version=${{ github.event.inputs.version }} kong-green.pkr.hcl
- name: terraform apply green
run: |
terraform apply -auto-approve -var="green_version=${{ github.event.inputs.version }}"
- name: wait for healthy
run: |
until curl -f https://green-admin:8444/status/ready; do sleep 5; done
- name: deck sync config
run: |
deck sync --kong-addr https://green-admin:8444 --state prod.yaml
- name: switch ALB
run: |
aws elbv2 modify-target-groups \
--target-group-arn $BLUE_TG_ARN \
--health-check-path "/status/unready"
aws elbv2 modify-listener --listener-arn $ALB_LISTENER \
--default-actions Type=forward,TargetGroupArn=$GREEN_TG_ARN
kong_nginx_timers{state="running"}
< 1000 才允許下一步; kong_datastore_reachable
必須為 1。 p99_latency > 500 ms
或 rate(nginx_http_requests_total{code=~"5.."}[1m]) > 100
,直接切回藍集群。 Wasm 插件緩存路徑變動
3.8 在 /usr/local/kong/wasmtime-cache
新增文件鎖,如果你用 tmpfs,記得加 size=1G,mode=1777
,否則緩存寫爆直接 500。
AI Gateway 計數器 License 陷阱
3.8 引入 /license/report
的新字段 ai_requests
,每調一次 LLM 就寫一次表;壓測時把 PG 寫滿,IO util 飆 90%。解決:把 ai_requests_reporting = off
寫進 kong.conf。
OpenSSL 3.2 Security Level 2
升級后所有 1024-bit RSA 證書直接拒絕握手,測試環境踩坑無數。提前用 openssl s_client -connect
掃一遍上游證書。
deck dump --all-workspaces
并加密存 S3。 當你把以上三件事做成肌肉記憶,下一次“3.9 → 3.10”的凌晨,你就能在 Slack 里淡定地打出一句:
“流量已切綠,Prometheus 全綠,我去睡了,各位晚安。”