OpenKruise Documentation

repository·master·Indexed 26 days ago

https://github.com/openkruise/kruise

A CNCF incubating project providing Kubernetes controllers for advanced workload management, sidecar lifecycle control, and multi-domain application management. Key features include CloneSet, Advanced StatefulSet, Advanced DaemonSet, SidecarSet, and UnitedDeployment, as well as a high-performance resource calculator for Kubernetes CPU and memory expressions.

Tokens
43.7K
Snippets
96
Records
219
Agent score
89%

What's inside OpenKruise

  1. Overview of OpenKruise features

    master

    OpenKruise is a CNCF incubating project that extends Kubernetes core controllers for advanced workload and application management. Its key feature sets include:

    • Advanced Workloads: Enhanced management for stateless, stateful, daemon, and job workloads, supporting in-place updates, configurable scale/upgrade strategies, and parallel operations. Key resources include CloneSet, Advanced StatefulSet, Advanced DaemonSet, BroadcastJob, and AdvancedCronJob.
    • Sidecar Container Management: Simplifies sidecar injection, in-place updates, and startup/termination control via SidecarSet, Container Launch Priority, and Sidecar Job Terminator.
    • Multi-domain Management: Manages applications across different node pools, zones, architectures (x86/arm), or node types using WorkloadSpread and UnitedDeployment.
    • Enhanced Operations: Tools for container recreation (ContainerRecreateRequest), image pre-downloading (ImagePullJob), resource distribution (ResourceDistribution), persistent pod states (PersistentPodState), and custom probes (PodProbeMarker).
    • Application Protection: Protects resources from cascading deletion and manages application availability via PodUnavailableBudget.
  2. Overview of Kruise Workload Management

    master
    Kruise is a set of Kubernetes controllers designed to supplement default workload controllers (like StatefulSet, Deployment, and DaemonSet). It addresses diverse requirements for workload upgrades and deployments that standard Kubernetes controllers cannot satisfy. Kruise provides controllers for representative cloud-native applications while maintaining full Kubernetes API compatibility.
  3. Overview of OpenKruise capabilities

    master

    OpenKruise is a CNCF incubating project that provides extended workload and application management capabilities beyond the standard Kubernetes core controllers. Its core features include:

    • Advanced Workloads: Manages stateless, stateful, daemon, and job-type applications with features like in-place upgrades, configurable scaling/release strategies, and concurrency control. Key types include CloneSet, Advanced StatefulSet, Advanced DaemonSet, BroadcastJob, and AdvancedCronJob.
    • Sidecar Container Management: Simplifies sidecar injection and in-place upgrades via SidecarSet. It also provides Container Launch Priority for startup order control and Sidecar Job Terminator for managing sidecar lifecycles in Jobs.
    • Multi-zone Management: Facilitates deployment across different node resource pools, availability zones, or architectures (x86/arm) using WorkloadSpread or UnitedDeployment.
    • Enhanced Operations: Includes in-place container restarts, image pulling on specific nodes, cross-namespace resource distribution (ResourceDistribution), persistent pod states (PersistentPodState), and custom probe capabilities (PodProbeMarker).
    • Application Security: Provides deletion protection for Kubernetes resources/pods and PodUnavailableBudget for enhanced disruption protection.
  4. Overview of Enhanced LivenessProbe in OpenKruise

    master
    OpenKruise provides an enhanced livenessProbe solution designed to address the limitations of the standard Kubernetes liveness probe. While the standard Kubernetes liveness probe triggers immediate container restarts upon failure—which can lead to service outages or cascading failures (avalanche effect) if probe configurations are incorrect—the OpenKruise enhanced solution focuses on service availability and resilience protection. It aims to provide application-level global high availability and prevent catastrophic service outages caused by aggressive restart policies.
  5. Understand the Enhanced LivenessProbe architecture

    master

    The Enhanced LivenessProbe solution replaces the native kubelet probe logic with a distributed system to provide better application protection and scalability:

    1. EnhancedLivenessProbeWebhook (Kruise-manager): Converts native livenessProbe configs into a JSON string stored in the apps.kruise.io/container-probe-context pod annotation.
    2. LivenessNodeProbeController (Kruise-manager): Converts the annotation data into a NodePodProbe Custom Resource (CR).
    3. LivenessProbeDetector (Kruise-daemon): A component in the Kruise-daemon that executes the actual probes (TCP, HTTP, EXEC, or RPC) based on the NodePodProbe resource and reports results back to the Pod annotations.
    4. EnhancedLivenessProbeController (Kruise-manager): Analyzes probe failures and decides whether to restart containers. It uses a ContainerRecreateRequest (CRR) to trigger restarts, ensuring high availability by respecting PodUnavailableBudget (maxUnavailable protection) and applying resilience algorithms (token bucket, blacklists, etc.).
  6. Use ConfigMapSet for decoupled configuration and image updates

    master

    The ConfigMapSet resource allows you to manage multiple versions of configuration files (Env/files) alongside workloads like CloneSet. This enables decoupling image releases from configuration releases, which is useful for large-scale data/model loading scenarios where you want to preserve validation progress or serve different data versions without changing the application image.

    Key capabilities include:

    • Version management via a RevisionManager ConfigMap (RMC).
    • Container selection (static or dynamic).
    • Reload sidecar container injection.
    • Flexible update strategies (ReStart, PostHook, or HotUpdate).
    • Rollback support.
    apiVersion: apps.kruise.io/v1alpha1
    kind: ConfigMapSet
    metadata:
      name: deploy-cms
      namespace: my-namespace
    spec:
      selector:
        matchLabels:
          app: sample
      data: 
        application.yaml: |
          server:
            port: 6666
      containers:
      - name: main
        mountPath: /data/conf1
      reloadSidecarConfig:
        type: k8s
        config:
          name: reload-sidecar
          image: openkruise/reload-sidecar:v1.0.0
          restartPolicy: Always
      effectPolicy:
        type: HotUpdate
  7. Understand CloneSet scale-down topology spread behavior

    master

    CloneSet scale-down logic includes rankers to ensure pods are deleted in a way that respects topology constraints and minimizes node stacking.

    When scaling down, the controller uses two primary ranking mechanisms:

    1. SameNodeRanker: Prioritizes deleting pods that are stacked on the same node. Pods that are the sole occupant of a node are assigned a rank of 0 and are preserved longer. For nodes with multiple pods, pods are ranked based on their index after sorting.
    2. SpreadConstraintsRanker: Uses Pod Topology Spread Constraints defined in the CloneSet template to distribute pod deletion across different topology domains (e.g., zones or regions).

    If topologySpreadConstraints are defined in the cloneset.spec.template.spec, the controller uses SpreadConstraintsRanker to rank pods across topology values, but still applies SameNodeRanker to sort pods within the same node/topology to ensure efficient node evacuation.

  8. Use the Kruise Resource Calculator for mathematical expressions

    master
    The Kruise Resource Calculator is a high-performance, thread-safe evaluator for mathematical expressions, specifically designed for Kubernetes resource calculations (like CPU and memory) in SidecarSet scenarios. It supports basic arithmetic, parentheses, max() and min() functions, percentages (e.g., 50%), and Kubernetes quantities (e.g., 40m, 100Mi).
  9. Understand ConfigMapSet Cold Start Behavior

    master

    ConfigMapSet implements a 'Cold Start' mechanism to prevent unnecessary Pod churn when configuration changes occur.

    Behavior

    When spec.containers is modified, the controller does not automatically trigger a Pod rebuild. Instead, the new configuration is applied only when a new Pod is created.

    Logic

    To avoid affecting existing Pods that cannot dynamically reload mounted volumes, the controller checks the Pod's creation time against status.lastContainersTimestamp. If a Pod was created before status.lastContainersTimestamp, it is treated as a 'legacy' Pod and will not undergo ConfigMapSet version changes until it is naturally replaced or recreated.

  10. Manage ConfigMapSet versions using a RevisionManager ConfigMap

    master

    To persist multiple versions of ConfigMapSet data, create an associated ConfigMap (the RevisionManager ConfigMap or RMC).

    • Naming: It is recommended to name revisions by hash. If the hash is identical to an existing version, no new revision is generated.
    • Pod Annotation: The ConfigMapSet controller injects the annotation configMapSet/<RMC_NAME>/Revision into Pods to indicate their current configuration version.
    • Retention: Use revisionHistoryLimit in the ConfigMapSet spec to define the maximum number of versions to retain in the RMC.

    RMC Format Example:

    apiVersion: v1
    kind: ConfigMap
    metadata:
      name: deploy-cms1-hub
      namespace: infra-demo-uat
    data: 
      revisions: |
        en3kp9:
          settings.yaml: |
            value: aaa
        fes34f:
          settings.yaml: |
            value: bbb
  11. Enable Cascading Deletion Protection

    master

    Kruise provides a safety policy to protect Kubernetes resources from accidental deletion via the cascading deletion mechanism. To use this feature, you must enable the ResourcesDeletionProtection feature-gate during installation or upgrade.

    Once enabled, Kruise uses a validation webhook to intercept deletion operations for specific resource types that carry the policy.kruise.io/delete-protection label.