Overview of cdk8s+
mastercdk8s, providing hand-crafted constructs for each native Kubernetes object to offer richer APIs with reduced complexity.repository·master·Indexed 26 days ago
https://github.com/cdk8s-team/cdk8sAn open-source software development framework for defining Kubernetes applications and reusable abstractions using familiar programming languages and rich object-oriented APIs. cdk8s synthesizes code into standard Kubernetes manifests through a construct tree consisting of App, Chart, and Resources. The ecosystem includes the core library, cdk8s-cli, and cdk8s-plus for high-level L2 constructs.
cdk8s, providing hand-crafted constructs for each native Kubernetes object to offer richer APIs with reduced complexity.When validation fails during cdk8s synth, the CLI uses annotations added to the generated manifests to provide a traceback to the original source code. This helps developers locate exactly which construct caused the violation. The following annotations are used:
cdk8s.io/construct.path: The path to the construct (e.g., Chart/Deployment).cdk8s.io/construct.traceback: A list of file names and line numbers representing the code path to the construct.The cdk8s command-line interface is a utility shipped with the cdk8s toolchain to help work with cdk8s apps. While not strictly required to use the library, it provides useful utilities for managing your projects.
Note: This documentation refers to version 2.x of the cdk8s toolchain. If you are using version 1.x, you should consult the Migrating from 1.x Guide.
cdk8s facilitates a "left-shift" approach to Kubernetes manifest validation. Instead of relying solely on a deployment-time gate (like an Admission Controller), cdk8s allows organizations to integrate validation directly into the developer's local workflow (authoring time) and the CI/CD pipeline (build time).
By coupling manifest authoring with validation, cdk8s helps ensure that every manifest generated via cdk8s synth is checked against:
To benefit from this, ensure that cdk8s synth is a standard part of your local development and build processes.
cdk8s is a framework for defining Kubernetes applications using object-oriented APIs. Applications are structured as a tree of constructs:
Chart class. Each chart synthesizes into a separate Kubernetes manifest file.Pod, Service, Deployment, or ReplicaSet.Synthesis Workflow:
dist directory.kubectl apply -f dist/chart.k8s.yaml or a GitOps tool like Flux.An ApiObject is the base class representing a Kubernetes manifest entry (level 0). While you rarely use ApiObject directly, most Kubernetes resources imported via cdk8s import extend this class.
When importing API objects, cdk8s automatically prefixes class names with Kube to distinguish them from high-level cdk8s+ APIs. You can modify this behavior using the CLI:
--class-prefix <string> to set a custom prefix.--no-class-prefix to remove the prefix entirely (use caution to avoid naming conflicts).cdk8s is a framework for defining Kubernetes applications using object-oriented programming. The workflow follows these steps:
App.Chart classes (which extend the Chart class) to group resources like Pod, Service, or Deployment.dist directory.kubectl apply -f dist/chart.k8s.yaml or GitOps tools like Flux.Note: cdk8s only defines and synthesizes manifests; it does not interact with the Kubernetes cluster directly.
StatefulSet class implements IScalable and is used to manage stateful applications. Unlike a Deployment, a StatefulSet maintains a sticky identity for each Pod, providing guarantees about ordering and uniqueness. This is useful when using storage volumes to provide persistence, as the persistent Pod identifiers make it easier to match existing volumes to replacement Pods.In cdk8s, high-level abstractions are referred to as L2 (Layer 2) constructs. These are designed to sit on top of basic Kubernetes building blocks to simplify resource interaction and better represent a developer's mental model.
Key capabilities of L2 constructs include:
Constructs are the fundamental building blocks of cdk8s. They allow you to create higher-level abstractions for Kubernetes resources using standard object-oriented programming.
Think of constructs as programmatically defined Helm Charts that leverage the full power of your programming language. By using constructs, you can: