Skip to content

CKS: set control plane, etcd and kubelet options at create time - #14783

Open
bhouse-nexthop wants to merge 1 commit into
apache:mainfrom
bhouse-nexthop:cks-kubelet-apiserver-settings
Open

bhouse-nexthop wants to merge 1 commit into
apache:mainfrom
bhouse-nexthop:cks-kubelet-apiserver-settings

Conversation

@bhouse-nexthop

@bhouse-nexthop bhouse-nexthop commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Description

createKubernetesCluster gains six optional parameters:

Parameter Type Used for
apiserverargs map kube-apiserver flags, e.g. OIDC (oidc-issuer-url, oidc-client-id, ...)
etcdargs map etcd flags, e.g. heartbeat-interval, election-timeout
controllermanagerargs map kube-controller-manager flags, e.g. leader-elect-lease-duration, leader-elect-renew-deadline, leader-elect-retry-period
schedulerargs map kube-scheduler flags, e.g. the same leader election timings
kubeletconfig JSON object KubeletConfiguration fields, e.g. systemReserved, kubeReserved, evictionHard
auditpolicy string audit Policy document; turns on audit logging
  • Storage: kept in kubernetes_cluster_details and returned in the cluster response. No schema change.
  • kubeadm config:
    • Built in Java for both the external etcd and the stacked case: kubeadm.k8s.io/v1beta3, or v1beta4 for Kubernetes 1.31+.
    • The settings go into ClusterConfiguration apiServer, controllerManager, scheduler and etcd.local extraArgs (a map in v1beta3, a name/value list in v1beta4), apiServer.extraVolumes, plus a KubeletConfiguration document, not into shell flags.
    • With external etcd nodes, etcdargs are added to the etcd service on those nodes instead.
    • The stacked case keeps the existing flag-based kubeadm init unless one of the new parameters is set.
  • Nodes added later: kubeadm uploads the ClusterConfiguration and the kubelet config to the cluster, so nodes that join later (scale, extra control nodes) get the same settings. The audit policy file is also written on the extra control nodes.
  • Audit logs: written to /var/log/kubernetes/audit with rotation defaults (maxage 30, maxbackup 3, maxsize 100 MB) that apiserverargs can override.
  • Validation:
    • Flag names must be [a-z0-9-]. Values and kubelet strings are limited to a plain character set (no spaces, quotes or braces).
    • Duplicate flags are rejected, and JSON nulls are rejected.
    • Flags and kubelet fields CloudStack or kubeadm rely on are reserved per component, e.g. kube-apiserver secure-port, etcd-servers, anonymous-auth, audit-policy-file, proxy-client-*, requestheader-*; etcd name, data-dir, wal-dir, initial-cluster* and the URL and TLS flags; controller-manager and scheduler kubeconfig, bind-address, secure-port, leader-elect, master, controllers, config; kubelet cgroupDriver, clusterDNS, staticPodURL.
    • NodeRestriction stays in enable-admission-plugins.
    • Requires Kubernetes 1.22+, and is rejected for ExternalManaged clusters.
  • kubeadm-config.yaml is now 0600, since it holds the bootstrap token and certificate key.
  • API server certificate: certSANs (and --apiserver-cert-extra-sans in the flag path) list the control node's own IP next to the public IP. With external etcd, advertiseAddress is the control node's own IP, as kubeadm already picks for stacked etcd. The public IP stays the controlPlaneEndpoint, so kubeconfig is unchanged.
  • UI: in advanced mode the create cluster form has kube-apiserver, etcd, kube-controller-manager and kube-scheduler arguments (one name=value per line; leading dashes are stripped), kubelet configuration (JSON) and audit policy fields. The cluster details tab shows the six values.

A use for the new ones: a cluster on network storage can ride out a short storage stall (e.g. a disk failing in the storage cluster) with longer etcd and leader election timeouts, instead of failing over etcd leaders and restarting controllers.

Fixes #14782

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)

How Has This Been Tested?

Unit tests: 173 in the kubernetes-service module, 42 of them in KubeadmConfigBuilderTest (v1beta3/v1beta4 output, stacked and external etcd, the etcd service flags, validation and reserved names per component) and 3 in CreateKubernetesClusterCmdTest.

First version (apiserverargs, kubeletconfig, auditpolicy), KVM lab (build that also carried other pending CKS changes), Kubernetes v1.33.13, HA cluster (2 control + 1 worker) created with OIDC apiserverargs, a kubeletconfig with systemReserved and evictionHard, and a Metadata-level auditpolicy:

Check Result
Cluster create Running, all nodes Ready, 19 pods Running
kube-apiserver flags on both control nodes --oidc-issuer-url, --oidc-client-id, --audit-policy-file, --audit-log-* defaults, --enable-admission-plugins=NodeRestriction
Audit log on both control nodes /var/log/kubernetes/audit/audit.log written, Metadata-level events
Worker /var/lib/kubelet/config.yaml systemReserved and evictionHard as given
Scale to 2 workers new worker gets the same kubelet settings and goes Ready
kubeadm-config.yaml mode 0600

UI: npm run lint clean; tests/unit/components/view and tests/unit/views/compute unit tests pass.

@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.24855% with 141 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.95%. Comparing base (2737087) to head (9914316).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
...bernetes/cluster/KubernetesClusterManagerImpl.java 2.32% 42 Missing ⚠️
...er/actionworkers/KubernetesClusterStartWorker.java 0.00% 42 Missing ⚠️
...kubernetes/cluster/utils/KubeadmConfigBuilder.java 84.72% 17 Missing and 16 partials ⚠️
...dstack/api/response/KubernetesClusterResponse.java 0.00% 18 Missing ⚠️
...kubernetes/cluster/CreateKubernetesClusterCmd.java 77.77% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14783      +/-   ##
============================================
+ Coverage     20.80%   20.95%   +0.14%     
- Complexity    20919    21205     +286     
============================================
  Files          6053     6058       +5     
  Lines        548451   549902    +1451     
  Branches      78719    73532    -5187     
============================================
+ Hits         114128   115216    +1088     
- Misses       420958   421221     +263     
- Partials      13365    13465     +100     
Flag Coverage Δ
uitests 3.86% <ø> (-0.01%) ⬇️
unittests 22.39% <59.24%> (+0.15%) ⬆️

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.

createKubernetesCluster gains six optional parameters:

| parameter | type | used for |
|---|---|---|
| apiserverargs | map | kube-apiserver flags, e.g. OIDC (oidc-issuer-url, oidc-client-id, ...) |
| etcdargs | map | etcd flags, e.g. heartbeat-interval, election-timeout |
| controllermanagerargs | map | kube-controller-manager flags, e.g. leader-elect-lease-duration |
| schedulerargs | map | kube-scheduler flags, e.g. leader-elect-lease-duration |
| kubeletconfig | JSON object | KubeletConfiguration fields, e.g. systemReserved, kubeReserved, evictionHard |
| auditpolicy | string | audit Policy document; turns on audit logging |

- Stored in kubernetes_cluster_details and returned in the cluster response. No schema change.
- Rendered into the kubeadm init config (ClusterConfiguration apiServer, controllerManager,
  scheduler and etcd.local extraArgs, apiServer extraVolumes, plus a KubeletConfiguration
  document), not into shell flags.
- With external etcd nodes, etcdargs are added to the etcd service on those nodes instead.
- kubeadm uploads the ClusterConfiguration and the kubelet config to the cluster, so nodes
  that join later (scale, HA control nodes) get the same settings. The audit policy file is
  also written on the extra control nodes.
- Audit logs go to /var/log/kubernetes/audit with rotation defaults (maxage 30,
  maxbackup 3, maxsize 100 MB) that apiserverargs can override. The policy is written
  gzip+base64 encoded.
- kubeadm config is now built in Java for both the external etcd and the stacked case,
  as kubeadm.k8s.io/v1beta3 (extraArgs as a map), or v1beta4 (extraArgs as a name/value
  list) for Kubernetes 1.31+. The stacked case keeps the old flag based kubeadm init
  unless one of the new parameters is set.
- Validation: flag names [a-z0-9-], values and kubelet strings limited to a plain
  character set (no spaces, quotes, braces), flags and kubelet fields CloudStack or
  kubeadm rely on reserved per component (kube-apiserver secure-port, etcd-servers,
  anonymous-auth, audit-policy-file, proxy-client-*, requestheader-*; etcd name,
  initial-cluster, data-dir, wal-dir, the URL and TLS flags; controller-manager and
  scheduler kubeconfig, bind-address, secure-port, leader-elect, controllers, config;
  kubelet cgroupDriver, clusterDNS, ...),
  NodeRestriction kept in enable-admission-plugins, Kubernetes 1.22+, rejected for
  ExternalManaged clusters, duplicate flags rejected.
- kubeadm-config.yaml is now 0600: it holds the bootstrap token and certificate key.
- The API server certificate lists the control node's own IP as well as the public IP,
  and with external etcd the control node advertises its own IP (as kubeadm does for
  stacked etcd). The public IP stays the controlPlaneEndpoint.
- UI: in advanced mode the create cluster form has kube-apiserver, etcd,
  kube-controller-manager and kube-scheduler arguments (one name=value per line),
  kubelet configuration and audit policy fields; the cluster details tab shows them.

Signed-off-by: Brad House <bhouse@nexthop.ai>
@bhouse-nexthop
bhouse-nexthop force-pushed the cks-kubelet-apiserver-settings branch from 43d5967 to 9914316 Compare November 30, 2026 01:46
@bhouse-nexthop bhouse-nexthop changed the title CKS: set kube-apiserver and kubelet options at create time CKS: set control plane, etcd and kubelet options at create time Nov 30, 2026
@bhouse-nexthop

Copy link
Copy Markdown
Collaborator Author

Extended this PR: createKubernetesCluster now also takes etcdargs, controllermanagerargs and schedulerargs, alongside apiserverargs, kubeletconfig and auditpolicy. They go into the kubeadm ClusterConfiguration (etcd.local, controllerManager and scheduler extraArgs). With external etcd nodes, the etcd flags go on the etcd service instead. The create form and the details tab show them.

Test report: a management server built from main plus this change, KVM, advanced zone, Ceph RBD primary storage, Kubernetes 1.33.1 (kubeadm v1beta4). Both clusters were created through the UI form, with etcd heartbeat-interval=500 / election-timeout=5000, controller-manager and scheduler leader-elect-lease-duration=60s / leader-elect-renew-deadline=40s / leader-elect-retry-period=5s, plus kube-apiserver args, a kubelet config and an audit policy.

  • 2 control nodes, stacked etcd: the form sent all six parameters, the cluster reached Running, and the API and details tab returned all of them. On both control nodes, including the joined one, the kube-controller-manager, kube-scheduler and etcd static pod manifests carry the flags. 42 checks passed (of 42).
  • 1 control node + 1 external etcd node: Running. The etcd process on the etcd node runs with --election-timeout=5000 --heartbeat-interval=500, the control node has no etcd static pod, and its controller-manager and scheduler manifests carry the lease flags. 41 checks passed (of 41).

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: allow setting kube-apiserver arguments, kubelet configuration and an audit policy at create time

1 participant