Version: v26.03

Binary File Custom Configuration Guide ​

Background ​

This document describes how to use Custom Resources (CR) to dynamically configure Kubelet and Containerd components. In bc, there are references to kubelet and containerd configuration CRs. The kubelet CR is abbreviated as kct, and the containerd CR is abbreviated as cct. You can edit kct and cct to import custom kubelet and containerd configuration items.

Prerequisites ​

Use CRs to complete Kubelet and Containerd configuration during cluster creation.

Restrictions ​

None.

Guide ​

KubeletConfig CR Configuration ​

Overview ​

The KubeletConfig CR allows you to dynamically configure Kubelet's configuration file and systemd service file through Kubernetes resources, without manually editing files on nodes.

CR Structure ​

bash
apiVersion: bke.bocloud.com/v1beta1
kind: KubeletConfig
metadata:
  name: <config-name>
  namespace: <namespace>  # Default is bke-system
spec:
  kubeletConfig:
    kubelet.conf:
      raw: |
        # Kubelet configuration file YAML content
  kubeletService:
    service:
      # Kubelet systemd service configuration

spec Field Description

spec.kubeletConfig

Used to configure Kubelet's configuration file (/var/lib/kubelet/config.yaml).

ParameterTypeRequiredDescription
kubelet.confmap[string]RawExtensionYesConfiguration object containing raw field
kubelet.conf.rawstringYesComplete YAML content of Kubelet configuration file

raw Field Format:

The raw field should contain the complete Kubelet configuration file YAML content, for example:

yaml
apiVersion: kubelet.config.k8s.io/v1beta1
kind: KubeletConfiguration
cgroupDriver: systemd
clusterDNS:
  - 10.96.0.10
clusterDomain: cluster.local
...

kubelet.config implements passthrough of the filled kubelet.conf.raw, and users need to ensure that the imported configuration items are correct.

spec.kubeletService

Used to configure Kubelet's systemd service file (/etc/systemd/system/kubelet.service).

ParameterTypeRequiredDescription
serviceKubeletServiceNoKubelet systemd service configuration object

kubeletService Field Description:

ParameterTypeRequiredDescription
ExecStartstringNoService startup command
RestartstringNoRestart policy (e.g., always, on-failure)
RestartSecstringNoRestart interval (e.g., 5s, 10s)
StartLimitIntervalstringNoStart limit time window
StartLimitBurstintNoStart limit count
KillModestringNoTermination mode (e.g., control-group, process)
StandardOutputstringNoStandard output redirect (e.g., journal, null)
StandardErrorstringNoStandard error redirect
SyslogIdentifierstringNoSyslog identifier
WorkingDirectorystringNoWorking directory
UserstringNoRunning user
GroupstringNoRunning group
ExecStartPre[]stringNoCommand list to execute before startup
Environment[]stringNoEnvironment variable list (format: KEY=VALUE)
EnvironmentFile[]stringNoEnvironment variable file path list
CustomExtramap[string]stringNoCustom extra configuration items (key-value pairs)

kubelet.service supports configuration items for kubelet service startup.

kubelet Dynamic Value Passing Feature

The dynamic value passing mechanism allows the use of variables in configuration files, which are replaced with actual values during deployment. This provides great flexibility, allowing the same configuration to be applicable to different nodes and environments.

Enabling Variable Substitution

During the BKECluster deployment process, the system automatically detects KubeletConfigRef and enables variable substitution. Variable substitution takes effect in the following two places:

  1. kubelet.conf configuration
  2. kubelet.service systemd service file

Expression variable: ${EXPR|command|END}

Execute shell commands and use the output as variable values.

Syntax:

${EXPR|shell_command|END}

Example:

yaml
spec:  kubeletConfig:    
  kubelet.conf:      
    raw: |        
        apiVersion: kubelet.config.k8s.io/v1beta1
        kind: KubeletConfiguration
        # Get CPU core count
        cpuManagerPolicy: "static"
        reservedSystemCPUs: "${EXPR|nproc|END}"
        # Get memory size (MB)
        evictionHard:
          memory.available: "${EXPR|free -m | grep Mem | awk '{print $2}'|END}Mi"
        # Get hostname
        hostnameOverride: "${EXPR|hostname|END}"

Note:

  • Commands are executed on the target node
  • If command execution fails, the variable remains unchanged (not replaced)
  • Command output will have leading and trailing whitespace removed

kubelet Configuration File kct Reference

my-kubelet.yaml

yaml
apiVersion: bke.bocloud.com/v1beta1
kind: KubeletConfig
metadata:
  name: my-kubelet
  namespace: my-kubelet
  labels:
    test: "true"
    component: "kubelet"
spec:

  kubeletConfig:
    kubelet.conf:
      raw: |
        apiVersion: kubelet.config.k8s.io/v1beta1
        kind: KubeletConfiguration
        authentication:
          anonymous:
            enabled: false
          webhook:
            cacheTTL: 2m0s
            enabled: true
          x509:
            clientCAFile: /etc/kubernetes/pki/ca.crt
        authorization:
          mode: Webhook
          webhook:
            cacheAuthorizedTTL: 5m0s
            cacheUnauthorizedTTL: 30s
        address: "${EXPR|ip -4 addr show | awk '/inet / {split($2,a,"/"); print a[1]}' | grep -vE '^127\.0\.0\.1|^169\.254\.' | head -n1|END}"
        port: 10250
        readOnlyPort: 0
        cgroupDriver: systemd
        hairpinMode: promiscuous-bridge
        serializeImagePulls: false
        clusterDNS:
          - "10.96.0.10"
        clusterDomain: "cluster.local"
        healthzBindAddress: 127.0.0.1
        healthzPort: 10248
        rotateCertificates: true
        staticPodPath: /etc/kubernetes/manifests
        streamingConnectionIdleTimeout: 4h0m0s
        syncFrequency: 1m0s
        volumeStatsAggPeriod: 1m0s

  kubeletService:
    enabled: true
    serviceName: "kubelet"
    unit:
      description: "Kubernetes Kubelet (my-Test)"
      documentation: "https://kubernetes.io/docs/concepts/overview/components/#kubelet"
      after:
        - "containerd.service"
        - "network-online.target"
      wants:
        - "network-online.target"
      requires:
        - "containerd.service"
    service:
      workingDirectory: "/var/lib/kubelet"
      execStartPre:
        - "/usr/bin/mkdir -p /sys/fs/cgroup/cpuacct/system.slice/kubelet.service"
        - "/usr/bin/mkdir -p /sys/fs/cgroup/hugetlb/system.slice/kubelet.service"
      execStart: "/usr/bin/kubelet \
      --bootstrap-kubeconfig=/etc/kubernetes/bootstrap-kubelet.conf \
      --kubeconfig=/etc/kubernetes/admin.conf \
      --config=/var/lib/kubelet/config.yaml \
      --container-runtime-endpoint=unix:///run/containerd/containerd.sock \
      --pod-infra-container-image=registry.k8s.io/pause:3.9 \
      --cgroup-driver=systemd \
      --register-node=true \
      --v=2 \
      --node-ip=${EXPR|ip -4 addr show scope global | awk '/inet /{print $2}' | cut -d'/' -f1|END} \
      --hostname-override=${EXPR|hostname -i | awk '{print $1}'|END}
      "
      restart: "always"
      restartSec: 10
      startLimitInterval: 30
      startLimitBurst: 3
      killMode: "process"
      standardOutput: "syslog"
      standardError: "syslog"
      syslogIdentifier: "kubelet"
      user: "root"
      group: "root"

    install:
      wantedBy:
        - "multi-user.target"
      requiredBy: []

    variables:
      kubeletBinaryPath: "/usr/bin/kubelet"
      kubeletConfigPath: "/etc/kubernetes/kubelet.conf"
      nodeName: "test-node-01"
      nodeIP: "xx"
      containerdEndpoint: "unix:///run/containerd/containerd.sock"
      pauseImage: "registry.aliyuncs.com/google_containers/pause:3.9"

ContainerdConfig CR Configuration ​

Overview ​

The ContainerdConfig CR allows you to dynamically configure Containerd's main configuration file, service file, and image registry configuration through Kubernetes resources.

CR Structure ​

yaml
apiVersion: bke.bocloud.com/v1beta1
kind: ContainerdConfig
metadata:
  name: <config-name>
  namespace: <namespace>
spec:
  script:
    # Script configuration
  service:
    # Containerd systemd service configuration
  main:
    # Containerd main configuration file (config.toml)
  registry:
    # Image registry configuration

spec Field Description

spec.script

Used to execute custom scripts before configuring Containerd.

ParameterTypeRequiredDescription
ContentstringNoScript content (inline script)
PathstringNoScript file path (local file)
InterpreterstringNoInterpreter (e.g., /bin/bash, /bin/sh), default is /bin/bash
Args[]stringNoList of arguments passed to the script

Note:
Content and Path are mutually exclusive. If both are provided, Content takes precedence.

spec.service

Used to configure Containerd's systemd service drop-in file (/etc/systemd/system/containerd.service.d/10-override.conf).

ParameterTypeRequiredDescription
ExecStartstringNoService startup command
SlicestringNosystemd slice unit
KillModestringNoTermination mode
RestartstringNoRestart policy
RestartSecstringNoRestart interval
TimeoutStopSecstringNoStop timeout
StartLimitIntervalstringNoStart limit time window
StartLimitBurstintNoStart limit count
LoggingLoggingConfigNoLogging configuration
CustomExtramap[string]stringNoCustom extra configuration items

LoggingConfig Fields:

ParameterTypeRequiredDescription
StandardOutputstringNoStandard output redirect
StandardErrorstringNoStandard error redirect
SyslogIdentifierstringNoSyslog identifier
LogLevelMaxstringNoMaximum log level

spec.main

Used to configure Containerd's main configuration file (/etc/containerd/config.toml).

ParameterTypeRequiredDescription
SandboxImagestringNoPod sandbox image (e.g., pause image)
RootstringNoContainerd data root directory, default is /var/lib/containerd
StatestringNoContainerd state directory, default is /run/containerd
ConfigPathstringNoConfiguration file path, default is /etc/containerd/certs.d
MetricsAddressstringNoMetrics monitoring address

Note:
If the main field is specified, the system will generate the config.toml file based on the template. If not specified, the default configuration is used.

spec.registry

Used to configure the image registry's hosts.toml file.

ParameterTypeRequiredDescription
ConfigPathstringNohosts.toml configuration directory, default is /etc/containerd/certs.d
Configsmap[string]RegistryHostConfigYesRegistry configuration mapping, key is registry name

RegistryHostConfig Fields:

ParameterTypeRequiredDescription
HoststringYesRegistry host address
Capabilities[]stringNoSupported capabilities (e.g., pull, push, resolve)
SkipVerifyboolNoSkip TLS verification
PlainHTTPboolNoUse HTTP instead of HTTPS
InsecureboolNoInsecure connection
OverridePathboolNoOverride path
TLSTLSConfigNoTLS configuration
AuthRegistryAuthConfigNoAuthentication configuration
Headermap[string][]stringNoCustom HTTP headers

TLSConfig Fields:

ParameterTypeRequiredDescription
CAFilestringNoCA certificate file path
CertFilestringNoClient certificate file path
KeyFilestringNoClient private key file path
InsecureSkipVerifyboolNoSkip TLS verification

RegistryAuthConfig Fields:

ParameterTypeRequiredDescription
AuthstringNoBase64 encoded authentication string
UsernamestringNoUsername
PasswordstringNoPassword
IdentityTokenstringNoIdentity token
RegistryTokenstringNoRegistry token