Communitygithub.com

lguidolin/cloud-delivery-aks

專門用於部署至 Kubernetes 或 Azure Kubernetes Service (AKS)、設定雲端機密、安排漸進式部署/金絲雀部署、每 PR 臨時環境或 K8s 健康檢查。關鍵字 — Kubernetes、AKS、Key Vault、Argo Rollouts、Flagger、金絲雀、藍綠部署、liveness、readiness、PodDisruptionBudget、HPA、回滾、GHCR。

cloud-delivery-aks 是什麼?

這是一個專門針對 Azure Kubernetes Service (AKS) 的雲端交付技能,為 Kubernetes/Azure 應用程式提供安全且可驗證的部署機制。它結合了不可變映像檔、內容摘要標記和逐環境提升(預覽→暫存→正式環境),確保每次部署的內容都是已經過驗證的。技能的核心規則包括:每 PR 建立獨立的臨時 K8s 命名空間進行測試,並在合併/關閉後自動銷毀;透過 liveness、readiness、startup 探針、滾動更新策略、PodDisruptionBudget 和 HPA 進行 Kubernetes 健康檢查閘控;支援 Argo Rollouts 或 Flagger 的金絲雀/藍綠部署,並結合 SLO 指標自動中止失敗的發行。回滾被視為一等級操作,只需重新部署先前成功的摘要即可。此技能設計為「堆疊特定」,僅在任務涉及 k8s/AKS 時載入,因此無雲端部署的專案(例如僅本機的 Docker Compose)永遠不會看到其內容。它支援的主要平台包括 Claude Code、Codex 等 AI 代理工具,並依賴 GitHub Actions、Azure Key Vault 和 Git 樹狀結構比對來確保提升的安全性。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lguidolin/agent-skills/tree/main/skills/cloud-delivery-aks

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

在 AKS 上的雲端交付

概觀

Kubernetes/Azure 的交付機制。在 AKS 上實作部署安全性與驗證閘道。專為堆疊設計—此技能僅在任務涉及 k8s/AKS 時載入,因此無雲端部署的專案(例如僅本機的 Docker Compose)永遠不會看到此內容。

交付規則

  • 本機開發執行完整堆疊,透過 Docker Compose,一個指令,全面涵蓋 — 這是一級需求。
  • 映像檔在 CI 中建置 → 推送至 GHCR,以內容摘要識別,然後不經修改地提升預覽 → 暫存 → 正式環境。絕不為每個環境重新建置。
  • 每 PR 的臨時預覽環境。 每個 PR 在 AKS 上部署至其獨立的命名空間以供審查,合併/關閉時銷毀。 這是整合測試的溫床;建立與銷毀成本低廉。
  • Kubernetes 健康檢查閘控。 每個工作負載都定義 liveness、readiness 和 startup 探針(連接到 observability-and-slos 中的端點)、具有有限 maxUnavailable/maxSurge 的滾動更新策略,以及 PodDisruptionBudget。使用 HPA 進行負載管理。
  • 逐步交付至正式環境。 透過 Argo Rollouts / Flagger 進行金絲雀或藍綠部署,搭配自動化指標分析並連結至 SLO;失敗的金絲雀自動中止。
  • 回滾是一級操作且經過演練。 不可變、以摘要定址的映像檔使回滾成為重新部署先前良好摘要的操作(kubectl rollout undo / abort the rollout)。在風險變更上線前進行驗證。
  • 遷移是獨立、有序的管線步驟,可安全擴展(參見 zero-downtime-migrations),在依賴遷移的程式碼之前執行 — 絕不與需要新綱要的 Pod 捆綁在一起。
  • CI 是閘道: lint、型別檢查、合約檢查、測試、安全掃描在每次變更時執行,並在 enforced 模式下阻止合併。CI 同時建置映像檔並發布其來源證明,然後不經修改地提升該摘要。
  • 開發/正式環境一致性與從環境取得設定。 來自 Azure Key Vault 的機密(透過 Secrets Store CSI 驅動程式或 sealed secrets)— 絕不放在映像檔或已提交的 .env 檔案中。連接埠/設定來自環境變數。僅開發工具(pgTAP、測試執行器)絕不進入正式環境映像檔。

管線

層級觸發器環境摘要
預覽PR 開啟 / 同步臨時命名空間 preview-<app>-pr-<N>在此建置,標記為 sha-<pr-head>
暫存合併至 main持久命名空間 staging將預覽摘要重新標記為 sha-<merge>
正式環境發布版本發布 + 核准命名空間 production發布提交之父 commit 的摘要

為何使用父 commit。 release-please 的發布提交僅變更 CHANGELOG.md 與 manifest,因此其樹狀結構並非暫存環境所浸泡過的內容—無論預覽為發布 PR 本身建置了什麼,都從未提升過預覽階段。其父 commit 是最後一個功能合併,正是暫存環境一直在驗證的內容,只要 release-please 將其發布分支保持在 main 的頂端(其預設行為)。從 Git 而非叢集即時狀態推導摘要,可保持提升的可重現性。

重新標記安全性。 Squash 合併會產生不同的提交 SHA,並且如果 main 在 PR 開啟期間移動過,則會產生不同的樹狀結構。兩個防護措施:

  • 要求 "合併前分支必須為最新" — 這是必要狀態檢查規則的子集 — 因此 squash 樹狀結構透過建構與 PR 頭部樹狀結構相等。此防護需要分支保護,因此僅存在於 enforced 模式中;處於 advisory 模式的專案將以下樹狀結構比較作為其唯一的防護,並應預期重新建置路徑是常規而非例外。
  • 驗證而非假設:比較 git rev-parse <merge>^{tree} 與 PR 頭部樹狀結構。相等 → 重新標記。不相等 → 在合併 SHA 上重新建置。這並非交付規則所禁止的逐環境重新建置:樹狀結構不相等表示內容本身與預覽階段驗證的內容不同,因此沒有可提升的成品可重複使用—而重新建置的映像檔以全新候選者的身份進入暫存環境,而非提升。請注意,當採取此路徑時會失去什麼:該映像檔從未在預覽環境中審查過,因此「已出貨的映像檔即是已審查的映像檔」對它不成立。暫存環境變成了它的第一個驗證,而非第二個。

重新標記是一個指標操作——無需重新建置,無需拉取:

docker buildx imagetools create -t "$REPO:sha-$MERGE_SHA" "$REPO@sha256:$DIGEST"

證明會綁定到 PR 頭部 SHA,因此在部署記錄中記錄頭部→合併的映射;映像檔設定無法在不重新建置的情況下編輯。

核准閘道 — 一個屬性,兩種機制:

模式機制
enforcedGitHub 環境 production 搭配必要審查者
advisory一個 workflow_dispatch 提升任務;執行它就是決策

快速參考

關注點機制
機密Key Vault → CSI 驅動程式;定期輪換;絕不放在映像檔中
健康檢查liveness + readiness + startup 探針;readiness 檢查真實依賴項
安全部署金絲雀/藍綠部署,受 SLO 閘控,失敗時自動中止
回滾重新部署先前良好的摘要;在風險變更前演練
每 PR 環境隔離命名空間,合併時銷毀
綱要獨立的順序步驟,可安全擴展,在程式碼之前
提升重新標記摘要;絕不為每個環境重新建置
核准環境審查者(enforced)或手動分派(advisory)

為何此處被隔離: 所有 Azure/k8s 特定內容都位於此處,由堆疊特定觸發器驅動。僅本機或不同雲端的專案會使用自己的交付技能;原則(不可變成品、可逆 + 漸進式部署、解耦的遷移)來自 resilience-and-deploy-safety。

完整理由:憲法第 XIX 條,收錄於 engineering-constitution/references/engineering-constitution.md。

Individual skills in this repo

This repo contains 18 individual skills — each has its own dedicated page.

lguidolin/change-hygiene-and-code-craft

Use when writing or refactoring code, structuring a commit or PR, or deciding whether to abstract duplication. Symptoms — mixing reorg with logic changes, a PR doing several things at once, a file growing large, the second copy of similar code, or unsure whether to DRY something up.

lguidolin/commit-history-rewrite

Use when an existing repository has messy commit history that needs to conform to conventional commits before adopting release-please, or when intermediate WIP/fixup/merge commits need to be cleaned up.

lguidolin/conventional-commits-and-releases

Use when committing, writing a commit message, opening a PR that will be squash-merged, or configuring automated versioning/changelogs. Keywords — conventional commits, release-please, semver, feat/fix/chore, breaking change, changelog.

lguidolin/defense-in-depth-security

Use when handling untrusted input, secrets, authentication/authorization, or dependencies — or threat-modeling a new surface. Keywords — STRIDE, threat model, least privilege, secrets management, supply chain, dependency scanning, input validation, audit log, defense in depth.

lguidolin/designing-before-building

Use when starting a feature, fixing a non-trivial bug, or about to write implementation code — before any code exists. Symptoms you need this: "this is simple, I'll just code it", reaching for the editor before a design is approved, or an idea that hasn't been turned into a spec and plan.

lguidolin/engineering-constitution

Use when starting work in a project that follows the engineering constitution, orienting to its rules, or deciding which engineering practice applies to a task — spec writing, commits, testing, security, deploys, database, or UI work.

lguidolin/graphql-contract-testing

Use when writing a GraphQL query/mutation that the UI and a test will share, or building route/schema contract or smoke tests. Symptoms — copying a query into a test, a test asserting on query text, schema change that didn't break the UI build, or RLS/permission drift. Keywords — graphql-codegen, typed document, contract test, route smoke test.

lguidolin/init-repo-CI

Use when setting up a new repository with conventional commits, release-please, and CI automation, or when retrofitting an existing repository that lacks automated versioning and PR validation workflows.

lguidolin/interface-craft-and-accessibility

Use when building or styling UI — components, layouts, forms, design tokens — or making accessibility decisions. Keywords — a11y, WCAG, keyboard navigation, focus state, contrast, design system, minimalist UI, component reuse, ARIA, semantic HTML.

lguidolin/merge-gates-and-automation

Use when setting up or changing CI, pre-push hooks, or a task runner, or deciding what must pass before merge. Symptoms — tempted to put authoritative checks only in a local hook, skip CI, bypass with --no-verify, or unsure what gates a merge vs. runs locally.

lguidolin/observability-and-slos

Use when adding logging, metrics, tracing, health checks, SLOs, or alerting — or when building a service surface that needs to be operable and debuggable. Keywords — structured logs, OpenTelemetry, correlation id, RED metrics, liveness, readiness, SLI, SLO, error budget, alerting.

lguidolin/performance-and-scale

Use when working on hot paths, list endpoints, pagination, data-access in loops, or public interfaces/schemas. Symptoms — unbounded queries, N+1 access, no latency budget, optimizing without measuring, or changing an interface many consumers depend on. Keywords — pagination, N+1, Hyrum's Law, performance budget, bundle size.

lguidolin/postgres-postgraphile-rls-and-sql

Use when writing PostgreSQL, PostGraphile config, Row-Level Security policies, SQL schema files, or working on the Browser→App→PostGraphile→Postgres data path. Keywords — RLS, SECURITY DEFINER, search_path, pgSettings, grants, roles, GraphQL depth limit, query cost, statement_timeout, SQL file organization.

lguidolin/recording-decisions

Use when a design or architecture decision has been made and needs to be captured — writing a decision record or ADR, updating a decision index, noting a deferred idea, or superseding a past decision. Keywords — ADR, decision record, rationale, rejected alternatives, dependency index.

lguidolin/resilience-and-deploy-safety

Use when planning a deploy, designing a rollback, or responding to an incident or writing a postmortem. Keywords — deploy safety, rollback, immutable artifact, progressive delivery, canary, blast radius, incident response, blameless postmortem, error budget.

lguidolin/ship-it

Use when the user wants to ship work — push, PR, archive decision records, merge, and clean up. Handles the full lifecycle from committing final changes through post-merge cleanup including converting specs/plans to compact decision records.

lguidolin/tests-as-a-control

Use when writing or modifying tests, when a test breaks during a refactor, or when testing permission/role rules. Symptoms — tempted to edit a test to make it pass, testing only the happy path, a deny-test that started passing, flaky tests, or unsure what to assert.

lguidolin/zero-downtime-migrations

Use when changing a database schema where data must survive the change — adding/removing/renaming columns, constraints, indexes, or backfilling. Symptoms — a destructive migration bundled with a code deploy, a NOT NULL column with a backfill, a table-locking UPDATE, or a rename. Keywords — expand/contract, parallel change, backfill, NOT VALID, CREATE INDEX CONCURRENTLY, graphile-migrate.

相關技能