mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 04:06:34 +09:00
## What this PR does Stacked on #4508 (VMs in a cozyplane VPC). This layer runs a whole tenant Kubernetes cluster inside a VPC: the control plane, its etcd and the worker VMs. The `Kubernetes` cluster and each of its `KubernetesNodes` pools set the same `network: {name: <VPC catalog name>}`. A VPC refuses cluster-internal destinations, so the workers, the tenant's own pods and the konnectivity agents all need an apiserver address inside the VPC. The platform side keeps working unchanged: it reaches VPC pods by their fabric IPs and through ClusterIPs that resolve to them. That covers Kamaji, CAPI, kccm, the cluster autoscaler, the chart's Jobs, the ingress passthrough, and the `super-admin.svc` kubeconfig Flux installs the tenant addons with. **Control plane.** `network.name` on the `Kubernetes` cluster does three things: - puts the apiserver pods in the VPC (`deployment.podAdditionalMetadata`); - attaches their Service to it (`network.serviceAnnotations`), so that inside the VPC the resolver answers the Service's name with a VIP from the VPC's own range; - stamps the cluster's own etcd through the `annotations` key of `cozy-lib.etcd.cluster`. etcd-operator copies that annotation onto the member Pods and both etcd Services, so the apiserver reaches its DataStore entirely inside the VPC. **Advertise address.** Kamaji's `advertiseAddress` is what the tenant's `kubernetes` endpoints and the konnectivity agents dial, and its CRD requires an IP. The right IP is the apiserver Service's VIP, which only a pod inside the VPC can learn. In VPC mode each pool's talos-reconcile Job starts a short-lived probe pod in the VPC. The probe resolves the Service's FQDN and writes the answer to its termination message. The Job reads that back with a namespaced pod `get`, patches `advertiseAddress` (Kamaji adds it to the apiserver certificate itself), and uses the VIP for the workers' `extraHostEntries` in place of the ClusterIP. This happens before the pool's TalosConfigTemplate is applied, so Kamaji's one rollout runs while the cluster has no workers yet. The Job's Role gains `create` on pods plus `get`/`delete` on the probe pod by name, in VPC mode only. **Workers.** Each pool stamps `sdn.cozystack.io/vpc` on its worker VM template, only when set, because the KubevirtMachineTemplate is content-hash named. **Route table.** A pool can also name a cozyplane RouteTable with `routeTable` (a DNS-1123 name, empty by default), the same contract as `vm-instance`'s value in #4508. When it is set, the pool renders `sdn.cozystack.io/route-table: <routeTable>` on its worker VM template next to `sdn.cozystack.io/vpc`, and setting or changing it rolls the pool's workers, as `network` does. Empty renders nothing, which leaves the VPC's default table in effect. The render fails with `routeTable` on a cluster that does not serve `sdn.cozystack.io`, on `substrate: proxmox`, or without `network.name`. The control plane keeps the VPC's default table. **Guards**, all unit-tested. The cluster refuses `network.name`: - where `sdn.cozystack.io` is not served; - on the proxmox substrate; - on the tenant's shared DataStore; - on a running cluster outside that VPC, in either direction, because etcd-operator never re-stamps a running member. A pool refuses a network that differs from its control plane's, again in either direction, checked against the live apiserver Service. Design notes: - **The probe is interim.** A request for cozyplane to report an attached Service's VIP on the Service itself (`sdn.cozystack.io/vpc-ip`, the same annotation the CNI stamps on pods) is going to upstream. Once it ships, the Job reads the annotation and the probe goes away. - **The rejected alternative is a LoadBalancer.** Publishing the apiserver Service and reaching it through the VPC gateway's NAT spends a published address per cluster and makes NAT a dependency of the control path. Not verified on a live stand yet: - the probe's resolution through the VPC resolver; - worker bootstrap and konnectivity through the VIP; - etcd member peering inside the VPC; - OIDC mode, where the apiserver dials Keycloak's internal URL from inside the VPC. ### Screenshots Not a UI change. ### Downstream repositories Walked the trigger map against the diff. terraform-provider-cozystack models app fields by hand, so the new `network` (both apps) and `routeTable` (KubernetesNodes) fields need its schema, model and expand/flatten; that is cozystack/terraform-provider-cozystack#90. The website's reference pages for kubernetes and kubernetes-nodes are regenerated from their READMEs on release, and both apps are in the website's app lists, so no follow-up is needed there. Nothing else in the map is touched. - [ ] No downstream repository is affected by this change - [ ] [cozystack/website](https://github.com/cozystack/website) - follow-up: - [x] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: cozystack/terraform-provider-cozystack#90 - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [ ] [cozystack/community](https://github.com/cozystack/community) - follow-up: ### Release note ```release-note feat(kubernetes): on the cozyplane networking variant, a tenant Kubernetes cluster can run entirely inside a VPC — network.name puts its control plane, its own etcd and its worker VMs in the VirtualPrivateCloud ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Kubernetes clusters now use dedicated etcd by default, with configurable one- or three-member setups and storage options. Existing clusters using shared etcd retain their current configuration. * Clusters and worker pools can join a cozyplane VPC, subject to platform and compatibility requirements. Changing a worker pool’s network rolls its worker VMs. * Cluster status notes now identify the etcd configuration in use. * **Bug Fixes** * Enabled Kubernetes add-ons and supporting services can render independently of tenant-shared etcd availability. * Cluster cleanup now handles dedicated etcd resources. <!-- end of auto-generated comment: release notes by coderabbit.ai -->