The cluster pulls the site's images; CI only rolls them out

Images from GHCR instead of builds on the node, a deploy account that can do two verbs on two objects, and a preprod namespace beside production

The node stopped building the site from a working directory and started pulling the images CI publishes. The deploy account can touch two named deployments and nothing else, and preprod got its own namespace and database.

At first the site reached the cluster the simple way: a script copied a working directory to the node, and the images were built there. That path is fragile. What runs is whatever was on a laptop at the time, and nothing connects it to a commit. Meanwhile the site's CI was already publishing images to GHCR on every push to main, and nothing was pulling them.

Pull, don't build

Both deployments, web and api, now pull their images from GHCR. The packages are private, so the cluster holds a pull secret for the registry. The old copy-and-build script stays only as a documented fallback, and its header now says so.

A deploy account that can do almost nothing

The deploy job in the site's CI needs to talk to the cluster. The obvious credential to hand it is the cluster administrator's, which would put a key that can do anything into GitHub's secret storage in order to perform two verbs on two objects.

Instead, the cluster has a dedicated ServiceAccount:

  • get, patch and watch on the two deployments, by name. That is
  • exactly what a rollout needs.

  • Read access to the ReplicaSets and Pods behind them, so a stuck rollout
  • can say why. An image that cannot be pulled is the likely failure, and it is invisible without this.

  • A Role, not a ClusterRole, so the credential cannot see outside its
  • namespace.

    The credential is generated by a script the owner runs, and goes from the terminal into GitHub and nowhere else.

    Preprod beside production

    The next step added a preprod namespace that tracks main, with the same two deployments and:

  • its own CouchDB and volume, because the database name is fixed in the
  • application. Sharing a server would have meant changing the application to express an infrastructure decision, and would have left preprod holding a credential that can write production's data.

  • a mail sink, so nothing preprod sends reaches a real inbox.
  • a noindex header, so search engines leave it alone, and access
  • limited to the owner.

    Its API configuration is generated from the application's schema rather than copied from production. Since then, a merge to main lands on preprod, and only a release tag reaches production.

    Tagged: infrastructure, kubernetes, rbac, deploy

    Area: oci-free

    Related notes

    עברית