mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-01 12:46:14 +09:00
feat(kubernetes): run tenant clusters inside a cozyplane VPC (#5337)
## 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 -->
This commit is contained in:
20 files changed
+905
-8
No files matched your search
Generated
+10
@@ -32,6 +32,9 @@ type ConfigSpec struct {
|
||||
// +kubebuilder:default:="kubevirt"
|
||||
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="substrate is immutable"
|
||||
Substrate string `json:"substrate"`
|
||||
// Runs the whole cluster inside a cozyplane VPC: the control plane, its etcd, and, through the same value on each KubernetesNodes pool, the worker VMs. Set it when the cluster is created; it cannot be changed afterwards. Requires the cozyplane networking variant, `substrate: kubevirt` and the cluster's own etcd.
|
||||
// +kubebuilder:default:={}
|
||||
Network Network `json:"network,omitempty"`
|
||||
// Proxmox substrate settings.
|
||||
// +kubebuilder:default:={}
|
||||
Proxmox Proxmox `json:"proxmox"`
|
||||
@@ -238,6 +241,13 @@ type MonitoringAgentsAddon struct {
|
||||
ValuesOverride k8sRuntime.RawExtension `json:"valuesOverride"`
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
// Name of the VirtualPrivateCloud (without the "virtualprivatecloud-" prefix) in this namespace
|
||||
// +kubebuilder:validation:MaxLength=63
|
||||
// +kubebuilder:validation:Pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?$"
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type OIDC struct {
|
||||
// Tenant-supplied AuthenticationConfiguration; consumed only when `mode: CustomConfig`.
|
||||
// +kubebuilder:default:={}
|
||||
|
||||
@@ -151,6 +151,7 @@ func (in *Config) DeepCopyObject() runtime.Object {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ConfigSpec) DeepCopyInto(out *ConfigSpec) {
|
||||
*out = *in
|
||||
out.Network = in.Network
|
||||
in.Proxmox.DeepCopyInto(&out.Proxmox)
|
||||
in.Addons.DeepCopyInto(&out.Addons)
|
||||
in.ControlPlane.DeepCopyInto(&out.ControlPlane)
|
||||
@@ -371,6 +372,21 @@ func (in *MonitoringAgentsAddon) DeepCopy() *MonitoringAgentsAddon {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Network) DeepCopyInto(out *Network) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Network.
|
||||
func (in *Network) DeepCopy() *Network {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Network)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *OIDC) DeepCopyInto(out *OIDC) {
|
||||
*out = *in
|
||||
|
||||
+15
@@ -22,6 +22,14 @@ type ConfigSpec struct {
|
||||
// +kubebuilder:default:=""
|
||||
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="cluster is immutable"
|
||||
Cluster string `json:"cluster"`
|
||||
// Joins this pool's worker VMs to a cozyplane VPC. Must match the parent Kubernetes cluster's `network`, which puts the control plane in the same VPC. Setting or changing it on an existing pool rolls every worker VM of the pool. Requires the cozyplane networking variant and `substrate: kubevirt`.
|
||||
// +kubebuilder:default:={}
|
||||
Network Network `json:"network,omitempty"`
|
||||
// Name of a cozyplane RouteTable in the VPC's namespace that routes this pool's worker VMs. Empty uses the VPC's default table. Requires `network.name` and the cozyplane networking variant. Like `network`, setting or changing it rolls every worker VM of the pool.
|
||||
// +kubebuilder:default:=""
|
||||
// +kubebuilder:validation:MaxLength=253
|
||||
// +kubebuilder:validation:Pattern="^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)?$"
|
||||
RouteTable string `json:"routeTable"`
|
||||
// StorageClass for the worker node system disk. When empty, CDI picks the class: the one annotated `storageclass.kubevirt.io/is-default-virt-class`, else the cluster default. Worker VMs live-migrate, so their disks need ReadWriteMany — the RWX access mode is supplied by the chosen StorageClass's CDI StorageProfile — and linstor-csi rejects RWX volumes that are not on a DRBD-backed StorageClass, so prefer a replicated/DRBD class. On an `osImage.builtin` pool this field also decides whether the pool renders at all: the chart refuses a pool whose class differs from its golden's, because across classes CDI either falls back to a host-assisted copy over the pod network (different CSI drivers or volume modes) or leaves a clone into the other class to the CSI driver. Leaving it empty makes the same comparison against the class CDI would pick. On a `builtin` pool the resolved class is then written onto the worker disk rather than left for the cluster to fill in at bind time, so a pool that has already cloned keeps binding on the class its disks are on even after an admin moves the default annotation; on the HTTP path an empty class is still left to the cluster. Has no effect on `substrate: proxmox`, where the worker disk is cloned from the VM template onto the template's storage or `proxmox.storage`.
|
||||
// +kubebuilder:default:="replicated"
|
||||
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="storageClass is immutable"
|
||||
@@ -125,6 +133,13 @@ type Kubelet struct {
|
||||
SystemReservedMemory string `json:"systemReservedMemory,omitempty"`
|
||||
}
|
||||
|
||||
type Network struct {
|
||||
// Name of the VirtualPrivateCloud (without the "virtualprivatecloud-" prefix) in this namespace
|
||||
// +kubebuilder:validation:MaxLength=63
|
||||
// +kubebuilder:validation:Pattern="^[a-z0-9]([-a-z0-9]*[a-z0-9])?$"
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type Proxmox struct {
|
||||
// Nameservers written into the worker machineconfig. On kubevirt the workers use the management cluster's CoreDNS, which they reach over the pod network; an off-cluster Proxmox worker cannot, so it needs reachable resolvers of its own. Required when `substrate` is `proxmox`. Keep in sync with the parent kubernetes chart's `proxmox.dnsServers`.
|
||||
// +kubebuilder:default:={}
|
||||
|
||||
@@ -53,6 +53,7 @@ func (in *Config) DeepCopyObject() runtime.Object {
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *ConfigSpec) DeepCopyInto(out *ConfigSpec) {
|
||||
*out = *in
|
||||
out.Network = in.Network
|
||||
out.DiskSize = in.DiskSize.DeepCopy()
|
||||
if in.Roles != nil {
|
||||
in, out := &in.Roles, &out.Roles
|
||||
@@ -145,6 +146,21 @@ func (in *Kubelet) DeepCopy() *Kubelet {
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Network) DeepCopyInto(out *Network) {
|
||||
*out = *in
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Network.
|
||||
func (in *Network) DeepCopy() *Network {
|
||||
if in == nil {
|
||||
return nil
|
||||
}
|
||||
out := new(Network)
|
||||
in.DeepCopyInto(out)
|
||||
return out
|
||||
}
|
||||
|
||||
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
|
||||
func (in *Proxmox) DeepCopyInto(out *Proxmox) {
|
||||
*out = *in
|
||||
|
||||
Reference in new issue
Block a user