schemaVersion: 1.0 # A parent stack that stands up a single-node Kubernetes cluster on one machine # somebody created by hand, and deploys client stacks onto it. # # This is the same machine the vm-compose example uses, declared the same way. The # difference is one extra resource — `k3s-cluster` — and the template type. Everything # above the kubeconfig (the Deployment, the Service, cloudExtras, probes, the Caddy # edge, the helm operators) is the ordinary Kubernetes path, unchanged. # # `fs` + `passphrase` keep this runnable with no cloud account at all. Swap in # `s3-bucket`/`gcp-bucket` + a KMS secrets provider once more than one person deploys it. provisioner: type: pulumi config: state-storage: type: fs config: path: ${git:root}/.sc/state secrets-provider: type: passphrase config: passPhrase: ${secret:SC_STATE_PASSPHRASE} templates: # Deploys onto the k3s cluster below. It names the cluster resource rather than # carrying a kubeconfig, which is the whole reason this template type exists next to # `kubernetes-cloudrun`: a cluster SC provisions has no kubeconfig until it has been # provisioned, so the value can only arrive as a parent-stack output. Same shape as # `gcp-gke-autopilot`'s `gkeClusterResource`. k3s-run: type: k3s-cloudrun config: k3sClusterResource: ru-cluster # Required, and there is no alternative on this path: a kubelet can only PULL an # image. The vm-compose path can push one over SSH with `imageDelivery: ssh-tar`; # Kubernetes cannot. Point this at a registry the machine can actually reach — in # a closed network that means a mirror or your own registry, not Docker Hub. dockerRegistryURL: registry.example.ru/mycompany dockerRegistryUsername: ${secret:RU_REGISTRY_USERNAME} dockerRegistryPassword: ${secret:RU_REGISTRY_PASSWORD} # Optional. Whether connections from CLIENTS are HTTPS, whoever terminated them. # It adds `import hsts` to the generated site entry and hands Caddy the # HTTP→HTTPS redirect. `clientTls: false` is the honest setting while you are # still reaching the cluster on a host port with no certificate. # # It does NOT make the cluster serve TLS — see `originTls` below. The old spelling # of this field was `useSSL`, which read as if it did; `useSSL` still works and # means exactly this. clientTls: true # Optional, and OFF unless stated. Whether this edge TERMINATES TLS itself: the # generated Caddy site address becomes `https://`, which is what arms # Caddy's automatic HTTPS and therefore ACME. Leave it unset when something in # front terminates — Cloudflare's proxy, or a cloud load balancer — which is the # usual arrangement. A single stack can still override this in its own # client.yaml with `lbConfig.originTls`. # # Not the same field as the `vm` resource's `ingress.originTls` below, which # answers the same question for a machine's own Caddy and defaults ON. # originTls: true resources: resources: staging: template: k3s-run resources: # The machine. Identical to the vm-compose example — see # ../../vm-compose/byo-host/server.yaml for the full annotation of every field, # including why `hostKey` is the one optional field whose absence has a real cost. cluster-vm: type: vm config: provider: byo hosts: - address: 203.0.113.10 user: ubuntu port: 22 privateKey: ${secret:CLUSTER_VM_DEPLOY_KEY} hostKey: "203.0.113.10 ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEXAMPLEEXAMPLEEXAMPLEEXAMPLEEXAMPLE00" # One machine, so no `role:` and no node-to-node address — the role is # inferred, and a single-node cluster has nothing to address. With more than # one machine, `role:` becomes required on every host and the pool needs a # node-to-node address. The multi-node shape: # # hosts: # - address: 203.0.113.10 # what YOU and SC reach it on # privateAddress: 10.0.0.10 # what its SIBLINGS reach it on # role: k3s-server # user: ubuntu # privateKey: ${secret:CLUSTER_VM_DEPLOY_KEY} # - address: 203.0.113.11 # privateAddress: 10.0.0.11 # role: k3s-agent # user: ubuntu # privateKey: ${secret:CLUSTER_VM_DEPLOY_KEY} # - address: 203.0.113.12 # privateAddress: 10.0.0.12 # role: k3s-agent # user: ubuntu # privateKey: ${secret:CLUSTER_VM_DEPLOY_KEY} # # `role:` is all-or-none across the pool — SC will not guess which of # several machines runs etcd, and the guess decides whether a machine # joins the cluster at all. Mixing `compose` with a `k3s-*` role in one vm # resource is refused: one machine has one port 443. # # A multi-node pool REQUIRES a node-to-node address, and the refusal when # it has none is deliberate rather than a convenience. SC passes that # address to k3s as `--node-ip`; without one k3s advertises whichever # address the machine's default route carries, which on a single-NIC VPS is # the PUBLIC one — and then etcd peer traffic (the cluster's whole state, # every Secret) and flannel's unencrypted VXLAN overlay cross the public # internet, on a `byo` host where SC has no firewall to write a rule in. # That deploy SUCCEEDS: three nodes `Ready`, nothing in the output saying # the overlay is exposed. Hence a refusal and not a warning. # # There are two ways to give it one, and they are alternatives: # # * `privateAddress:` per host (above) — correct wherever the hosting # provides a private network. Cheaper and faster than an overlay, and # already trusted by that cloud's firewall. # * `mesh: {enable: true}` on this resource — for machines that share no # private network, which is most cheap VPS hosting, and for machines in # different clouds entirely. SC builds a WireGuard overlay across the # pool and addresses every node on it, so no `privateAddress:` is # needed anywhere. The mesh wins where both are declared. # # mesh: # enable: true # # cidr: 10.88.0.0/24 # default; machine i gets host address i+1, so # # # host 0/1/2 are always .1/.2/.3. Override only # # # on a collision with your own ranges — changing # # # it later re-addresses every node. # # port: 51820 # default; UDP, and open to the internet by # # # design: a peer's endpoint is its public # # # address, and WireGuard answers nothing at all # # # to a packet that does not authenticate. # # Each machine's private key is generated ON that machine and never leaves # it, so no key enters the Pulumi state or a preview diff. The interface is # `sc-mesh`, not `wg0` — a byo machine may already have a hand-written # `wg0`, and SC taking that name would cut your own access to the box. # # A compose fleet (../../vm-compose/byo-host/) needs neither: it has no # node-to-node traffic at all. # Deliberately absent here: `ingress`. # # On the vm-compose path, `ingress.enable: true` runs a Caddy container that # holds ports 80 and 443 for every stack on the machine. A k3s node wants # those same ports for its own ingress. One machine has one 443, so pick one # owner: # # * No `ingress` (this file) — k3s owns 80/443. The cluster's own # LoadBalancer implementation (klipper-lb, k3s's `servicelb`) is left # enabled and binds them on the node. # * `ingress.enable: true` — the compose Caddy owns them, and SC then # disables `servicelb` automatically, because a `LoadBalancer` Service # that can never get a port would otherwise sit `` forever with # nothing saying why. # # You do not have to remember which: the `k3s-cluster` resource reads the # machine's ingress setting and adjusts. This comment is about which # arrangement you want, not about having to coordinate it by hand. ru-cluster: type: k3s-cluster config: # The machine, or machines, to install on. Named, not described — the same # split every other SC cluster resource uses. The resource is provisioned # after the vm resource it names, and reads the host facts from its output. vmResource: cluster-vm # How many of the pool's machines run the control plane. Default 1. # # `servers: 1` + N agents uses **sqlite** and has no etcd at all, which is # why it is the default: it is the simplest thing that works, and losing # the server loses the control plane but not the running workloads. # # `servers: 3` opts into embedded etcd and real HA. It must be ODD and no # larger than the host count — two members tolerate zero failures, so they # are strictly worse than one, and four tolerate the same one as three # while costing a machine. etcd is also latency-sensitive: across # availability zones in one region (~1ms) is the intended topology; # across regions or hosters (10-80ms) flaps raft heartbeats and triggers # repeated leader elections. # servers: 3 # Pinned on purpose. k3s's installer resolves a RELEASE CHANNEL at install # time, so leaving this to the default would mean the control-plane version # depends on the day the deploy ran. SC pins a known version instead; set # this to move it deliberately. # version: v1.36.5+k3s1 # The address the EXPORTED kubeconfig points at. Defaults to the machine's # own address, which is correct for a byo host with a public IP. # # Set it to a DNS name if the machine's address can change, or to an # internal address if the deploys run inside the same network — the # kubeconfig has to work from wherever `sc deploy` runs, which for CI is the # runner and not the machine. Whatever you put here is added to the API # server's certificate SANs automatically. # endpoint: k8s.example.ru # Extra names/addresses in the API server certificate. The endpoint and the # machine's address are always included; add anything else you will reach # the cluster by (a second DNS name, a VPN address, a load balancer). # tlsSans: # - k8s-internal.example.ru # - 10.0.0.10 # Bundled components to leave out. SC's default is `traefik`: the Caddy edge # SC already knows how to run is the ingress on every other cloud, and two # ingress controllers on one node is a port fight. # # Setting this REPLACES the default rather than adding to it — an explicit # empty list means "disable nothing", which is how you get Traefik back. # Valid entries: traefik, servicelb, local-storage, metrics-server. # disable: # - traefik # Passed through to `k3s server` verbatim. For things SC has no opinion # about; a flag SC manages itself (--tls-san, --disable, --write-kubeconfig*) # is refused here rather than silently fighting. # extraServerArgs: # - --kube-apiserver-arg=v=2 # The in-cluster Caddy edge — the `kubernetes-caddy` resource the # managed-Kubernetes clouds run — on the cluster above. A client stack points # at it through the template's `caddyResource`. # # `kubeconfig` is where this used to be impossible. The field takes a literal # kubeconfig, and a cluster SC provisions in this same stack has none until it # has been provisioned — so the only route was: provision, read the kubeconfig # out of the stack outputs by hand, paste it into a secret, provision again. # Two runs with a cluster-admin credential going through a human in between. # # `${resource:.}` resolves it in one pass. The value is a # Pulumi Output, not a string substitution — it does not exist until the # sibling has been provisioned in this very update — and the reference is what # creates the dependency edge, so `ru-cluster` is provisioned first. The # spelling is the same one a CLIENT stack uses to read a parent resource's # output; `k3s-cluster` publishes `kubeconfig` and `endpoint`, and a reference # to anything else is refused by name with the list of what it does publish. # A malformed reference is refused by the config reader, where you can still # see your own file; an unresolvable one at provision time. Neither is ever # treated as a literal kubeconfig. # # The kubeconfig stays marked secret through the whole hop — it is a # cluster-admin credential, and an unmarked one is cleartext in the Pulumi # checkpoint. # ru-edge: # type: kubernetes-caddy # config: # kubeconfig: ${resource:ru-cluster.kubeconfig} # replicas: 3 # # CIDRs whose X-Forwarded-For this edge trusts. Cloudflare publishes # # theirs; without this the edge reports the load balancer as every # # client. Only takes effect from the release that fixed the dead # # branch which discarded it on every non-GKE cluster. # trustedProxies: # - 173.245.48.0/20 # # One shared certificate store for every replica, so the edge issues # # ONE certificate instead of one per pod, and any replica can answer # # any replica's ACME challenge. The same block as the vm resource's # # `ingress.acmeStorage`, rendered by the same code; the three # # credentials arrive as secret env vars and the Caddyfile holds only # # `{$SC_ACME_S3_*}` placeholders. # acmeStorage: # bucket: mycompany-acme # endpoint: https://storage.yandexcloud.net # region: ru-central1 # accessKey: ${secret:ACME_S3_ACCESS_KEY} # secretKey: ${secret:ACME_S3_SECRET_KEY} # # Exactly 32 bytes. Encrypts certificates and the ACME account key # # at rest in the bucket. # encryptionKey: ${secret:ACME_S3_ENCRYPTION_KEY} # # The alternative front door, and what this example leaves in place: the node # itself. Leave `ingress` off the vm resource (as above), let k3s keep 80/443, # and expose a workload with `cloudExtras.serviceType: LoadBalancer` — # klipper-lb binds the node's ports — or reach it on a node port while # smoking. A compose-side Caddy on the same machine is the third option, and # is what the vm-compose example does.