Skip to content

CKS: set kube-apiserver 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 three optional parameters:

Parameter Type Used for
apiserverargs map kube-apiserver flags, e.g. OIDC (oidc-issuer-url, oidc-client-id, ...)
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.extraArgs / extraVolumes plus a KubeletConfiguration document, not into shell flags.
    • The stacked case keeps the existing flag-based kubeadm init unless one of the new parameters is set.
  • Nodes added later: kubeadm uploads the kubelet config to the kubelet-config ConfigMap, 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 relies on are reserved, e.g. secure-port, etcd-servers, anonymous-auth, audit-policy-file, requestheader-*, 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.

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: 155 in the kubernetes-service module, 27 of them in KubeadmConfigBuilderTest (v1beta3/v1beta4 output, stacked and external etcd, validation and reserved names).

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

createKubernetesCluster gains three optional parameters:

| parameter | type | used for |
|---|---|---|
| apiserverargs | map | kube-apiserver flags, e.g. OIDC (oidc-issuer-url, oidc-client-id, ...) |
| 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.extraArgs and
  extraVolumes, plus a KubeletConfiguration document), not into shell flags.
- kubeadm uploads the kubelet config to the kubelet-config ConfigMap, 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, or v1beta4 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 relies
  on (secure-port, etcd-servers, anonymous-auth, audit-policy-file, cgroupDriver,
  clusterDNS, requestheader-*, ...) reserved, 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.

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

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 54.04412% with 125 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.82%. Comparing base (2737087) to head (1cb425e).

Files with missing lines Patch % Lines
...bernetes/cluster/KubernetesClusterManagerImpl.java 0.00% 38 Missing ⚠️
...kubernetes/cluster/utils/KubeadmConfigBuilder.java 83.05% 14 Missing and 16 partials ⚠️
...er/actionworkers/KubernetesClusterStartWorker.java 0.00% 29 Missing ⚠️
...kubernetes/cluster/CreateKubernetesClusterCmd.java 0.00% 19 Missing ⚠️
...dstack/api/response/KubernetesClusterResponse.java 0.00% 9 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14783      +/-   ##
============================================
+ Coverage     20.80%   20.82%   +0.01%     
- Complexity    20919    20969      +50     
============================================
  Files          6053     6054       +1     
  Lines        548451   548704     +253     
  Branches      78719    73322    -5397     
============================================
+ Hits         114128   114285     +157     
- Misses       420958   421038      +80     
- Partials      13365    13381      +16     
Flag Coverage Δ
uitests 3.86% <ø> (ø)
unittests 22.26% <54.04%> (+0.01%) ⬆️

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.

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