Skip to content

CKS: deploy the Ceph CSI RBD driver when a cluster is created - #14906

Open
bhouse-nexthop wants to merge 1 commit into
apache:mainfrom
bhouse-nexthop:cks-ceph-csi
Open

bhouse-nexthop wants to merge 1 commit into
apache:mainfrom
bhouse-nexthop:cks-ceph-csi

Conversation

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator

Description

On a zone whose primary storage is Ceph RBD, a CKS cluster that should get its PersistentVolumes from Ceph needs ceph-csi installed by hand after every create: the driver's manifests and images, a ConfigMap with the monitors, a Secret with a Ceph user and key, and a StorageClass. The only storage CKS sets up is the CloudStack CSI driver (enablecsi), which attaches volumes through the hypervisor.

createKubernetesCluster takes four new parameters. When they are given, CKS deploys the ceph-csi RBD driver into the cluster with a default StorageClass ceph-rbd on the given pool.

Parameter Value
cephcsimonitors Monitor addresses, host or host:port with the v1 port (6789, the default), comma-separated
cephcsipool RBD pool for the cluster's volumes
cephcsiuser Ceph user, without client. (refused with it), e.g. one made with mon 'profile rbd' osd 'profile rbd pool=<pool>' mgr 'profile rbd pool=<pool>'
cephcsisecretkey That user's key, as printed by ceph auth get-key

All four or none; each is checked against a character set that cannot break the generated manifests.

How it works:

  • Images and manifests come from the binaries ISO. create-kubernetes-binaries-iso.sh adds the ceph-csi RBD manifests (namespace ceph-csi-rbd) and their images when CEPH_CSI_VERSION is set, e.g. CEPH_CSI_VERSION=3.18.2, so nodes pull nothing from the internet. It is opt-in because the images add about 370 MB to every node's import. The control node copies ceph-csi/ from the ISO to /opt/ceph-csi, like the CloudStack CSI manifests.
  • The cluster's settings are a template, cks/conf/ceph-csi-rbd.yml, next to the node templates, so an operator can change the StorageClass. After the cluster is up, CKS fills it in, copies it to the control node and runs kubectl apply --server-side on it and on /opt/ceph-csi/. A cluster whose ISO has no ceph-csi fails with kubectl's the path "/opt/ceph-csi/" does not exist, before anything is applied.
  • The key is never on a command line, in the node's user data or in the management server log.
    • It is stored in kubernetes_cluster_details, encrypted with the database key and not displayed, until the driver is deployed; then that detail is removed.
    • It is copied over SCP as a file only the login user can read. The file is opened as kubectl's stdin and unlinked before kubectl runs; if the apply fails, CKS removes it.
    • Server-side apply, so kubectl does not copy the Secret into a last-applied-configuration annotation.
    • The parameter name ends in secretkey, so the API access log masks it. createKubernetesCluster is now marked requestHasSensitiveInfo, so its async job parameters are stored encrypted (with database encryption on), which also covers the existing registry password.
    • As for the registry password, async-job events on the event bus carry the request parameters and mask only fields named password. Changing that is a separate change.
  • StorageClass: default (a new cluster has no other), reclaimPolicy: Delete, volume expansion on, imageFeatures: layering,exclusive-lock,object-map,fast-diff, ext4 with discard.
  • Delete: a cluster with ceph-csi runs the same PVC cleanup as one with the CloudStack CSI driver, so the provisioner deletes the RBD images of volumes with reclaim policy Delete. Two changes to that cleanup, which help both drivers:
    • It runs once, before any node is destroyed. It used to run when the loop reached a control node, and etcd nodes come first in that list, so with external etcd the API server was already gone.
    • The script waits up to 120 s for the deleted PVCs' PVs to go. Before, it returned right after deleting the PVCs, and the nodes could be destroyed before the driver deleted the backing volumes.
    • A cluster that is stopped when it is deleted can't run the cleanup, as before.
  • No schema change: the settings live in kubernetes_cluster_details.

Not included: CephFS, the snapshot controller (the provisioner's snapshotter sidecar is there, but VolumeSnapshots need the CRDs and controller), csi-addons, UI fields, and a response field. The upstream provisioner Deployment asks for 3 replicas on separate nodes, so on a cluster with fewer workers the extra replicas stay Pending until workers are added. Every Kubernetes version ISO used by such a cluster, for upgrades too, should be built with CEPH_CSI_VERSION.

Fixes: #14905

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

  • Unit tests: mvn test -pl plugins/integrations/kubernetes-service -am: 141 tests, 0 failures. The new tests cover:
    • parameter validation: none given, all given, a missing key, a monitor, pool or key that would break the manifest, an empty monitor entry, commas only, a client. prefix;
    • the template filled with the cluster's values and the decrypted key;
    • the copy as a mode 0600 file, the unlink before kubectl apply --server-side, and the key detail removed afterwards;
    • a failed apply failing the cluster, removing the file and keeping the detail.
  • ISO builder: ran the ceph-csi part with CEPH_CSI_VERSION=3.18.2 and v3.18.2. It downloads the five RBD manifests, moves every object to ceph-csi-rbd, and adds the six images (cephcsi and the five sidecars) to the image list. With the variable unset, nothing is added.
  • Not yet tested on a real cluster. I will add a test report from a KVM lab with Ceph: create a cluster with the parameters, a PVC binds, a pod writes and a second pod reads the data, the RBD image is in the pool, and deleting the PVC, then the cluster, removes the images.

How did you try to break this feature and the system with this change?

  • Values with quotes, spaces, empty monitor entries or a client. prefix are refused before anything is created.
  • Without the parameters, nothing changes: no detail is stored and nothing is applied.
  • An ISO without ceph-csi makes kubectl apply fail on the missing /opt/ceph-csi/ before it contacts the API server (checked with kubectl against an unreachable server), and the create fails with that reason.

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 60.43956% with 36 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.93%. Comparing base (58fda71) to head (508a429).

Files with missing lines Patch % Lines
...kubernetes/cluster/CreateKubernetesClusterCmd.java 0.00% 12 Missing ⚠️
...bernetes/cluster/KubernetesClusterManagerImpl.java 62.96% 9 Missing and 1 partial ⚠️
...r/actionworkers/KubernetesClusterActionWorker.java 88.37% 5 Missing ⚠️
.../actionworkers/KubernetesClusterDestroyWorker.java 0.00% 4 Missing ⚠️
...dstack/api/response/KubernetesClusterResponse.java 0.00% 3 Missing ⚠️
...er/actionworkers/KubernetesClusterStartWorker.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##              main   #14906       +/-   ##
============================================
+ Coverage     3.86%   20.93%   +17.07%     
- Complexity       0    21161    +21161     
============================================
  Files          494     6057     +5563     
  Lines        42888   549650   +506762     
  Branches      8141    73487    +65346     
============================================
+ Hits          1657   115071   +113414     
- Misses       40999   421123   +380124     
- Partials       232    13456    +13224     
Flag Coverage Δ
uitests 3.86% <ø> (-0.01%) ⬇️
unittests 22.38% <60.43%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator Author

Tested on a KVM lab running a main (24.0) build that includes this change. Primary storage is Ceph RBD. The Kubernetes 1.33.1 ISO was built with this PR's create-kubernetes-binaries-iso.sh and CEPH_CSI_VERSION=v3.18.2. The cluster has 1 control and 1 worker node, and the ceph-csi parameters point at a dedicated pool and a Ceph user with profile rbd on it.

Result: 24 of 24 checks passed.

Check Result
Create with the monitors, pool and user but no key refused
Key in the management server log, in the node user data, in kubernetes_cluster_details after deploy none of them (the detail is removed after the driver is deployed)
Copied manifest file on the control node gone
ceph-csi pods node plugin 3/3 and one provisioner 7/7 Running; the other 2 provisioner replicas Pending on a 1-worker cluster, as described
StorageClass ceph-rbd present and default
PVC without a class Bound
One pod writes, a second pod reads the data same data
RBD image in the pool listed while the PVC exists, gone after the PVC is deleted
Cluster deleted with a mounted PVC its image deleted with the cluster
Pool after the test empty

One thing to know when using it: cephcsi v3.18.2 needs an x86-64-v2 CPU in the guest. On the first run the KVM guests used the qemu64 CPU model (guest.cpu.mode not set) and the ceph-csi pods crashed with "Fatal glibc error: CPU does not support x86-64-v2". With guest.cpu.mode=host-passthrough the run above passed. It may be worth a line in the docs.

Not tested: UI (the PR has no UI fields), CephFS and snapshots (not part of this PR).

On Ceph-backed zones, a CKS cluster that needs ReadWriteOnce volumes from
Ceph gets them only after ceph-csi is installed by hand: its manifests, a
config map with the monitors, a secret with the Ceph key and a StorageClass.

createKubernetesCluster takes cephcsimonitors, cephcsipool, cephcsiuser and
cephcsisecretkey. When they are given, the cluster is created with the
ceph-csi RBD driver from the Kubernetes version ISO and a default
StorageClass ceph-rbd on that pool. The key is stored encrypted in the
cluster's details until the driver is deployed, then removed from them.
It is copied to the control node as a file only the login user can read.
The file is unlinked as soon as kubectl has it open, and it is applied
server-side, so the key is never on a command line, in the node's user
data or in a last-applied annotation. The request is marked as
sensitive so the async job stores it encrypted.

The cluster response returns cephcsipool, so the details tab shows which
pool the cluster was created with for the driver; the key is never
returned. In the create cluster form, advanced mode has a Ceph RBD
storage switch that shows the monitors, pool, user and key (a password
field that cannot be revealed).

create-kubernetes-binaries-iso.sh adds the ceph-csi manifests and images
to the ISO when CEPH_CSI_VERSION is set.

Deleting a cluster with ceph-csi first deletes its PVCs with reclaim
policy Delete, as for the CloudStack CSI driver. The cleanup now runs
once before any node is destroyed (etcd nodes used to go first) and waits
up to 120s for those PVs to go, so the driver can remove the backing
volumes while the cluster still runs.

Signed-off-by: Brad House <bhouse@nexthop.ai>
@bhouse-nexthop

bhouse-nexthop commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

I added the UI to this PR (still one commit):

  • Create cluster form, advanced mode: a "Ceph RBD storage" switch that shows the monitors, pool, user and key. The key is a password field that cannot be revealed, and the values are trimmed before they are sent.
  • The cluster response now returns cephcsipool, the pool given at create time, and the details tab shows it. The key, user and monitors are not returned.
  • Labels in en.json.

Tested in a nested KVM test environment with Ceph: with Ceph RBD storage turned on, the form created a cluster that reached Running with the driver deployed, in about 5 minutes. The request carried the four parameters, the key field had no reveal icon, the details tab and listKubernetesClusters showed the pool, and neither the response nor the management server logs contained the key.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CKS: option to deploy the Ceph CSI RBD driver when a cluster is created

1 participant