ComparedKlass8s, cdk8s and Pulumi

Compared

Klass8s, cdk8s and Pulumi

Three ways to write Kubernetes manifests in a programming language. What they share, where they differ, and how to choose.

cdk8s and Pulumi's Kubernetes provider share Klass8s's premise: manifests are a program, so write them in a typed language with an editor and tests. If you accept that premise, this page is about which language and which tool.

In short: typed construction of resources is common to all three. The differences are in what surrounds it (dependency injection, interception of the construction, environments, Helm) and in one structural fork: Pulumi deploys and keeps state, while cdk8s and Klass8s generate files and keep none.

What they share

  • Resource classes generated from the Kubernetes OpenAPI specification (cdk8s's imports, Pulumi's SDKs, klass8s/k8schema).
  • Structure checked by the compiler or the editor: a misspelt field is an error.
  • Reuse through the language: constructs in cdk8s, component resources in Pulumi, classes and traits in Klass8s.
  • A way down to the raw API when the abstractions end.

Where they differ

Configuration and dependency injection

A cdk8s chart gets its configuration the way any hand-written program does: properties passed down the construct tree. Pulumi adds per-stack configuration and secrets. Klass8s hands the problem to Symfony's container: manifests are services, facts arrive as bindings, shared logic as injected services, and data per manifest from configuration merged per environment.

Interception

The main structural difference. Every Klass8s manifest is wrapped in a proxy, and every method call and every generated resource is an event: "every pod runs under a ServiceAccount unless its manifest names one", "every workload restarts when its configuration changes", "every production container declares limits" are one subscriber each, which also applies to manifests written later.

In cdk8s, a rule over all resources is code that walks the construct tree; in Pulumi, transforms rewrite resources as they are registered. Both see objects that are already built. A rule of the form "supply a value only where the manifest chose none" then has to infer the choice from the built object; in Klass8s the subscriber sees what the manifest's own method returned (the example).

Environments

cdk8s and Pulumi express differences between environments in general-purpose code or per-stack configuration, and each team settles on its convention. Klass8s has one: environment methods, decorators and configuration files per environment.

Helm

cdk8s includes a chart's rendered output in a chart of its own; Pulumi deploys Helm charts and releases as resources. In Klass8s a release's values merge per environment with the rest of the configuration, and releases are ordered with your Apps.

Custom resources

cdk8s's import generates typed classes from a custom resource definition, and Pulumi can generate SDKs from CRDs. Klass8s describes instances of other operators' kinds as a class with a spec() array: the identity, the naming and the events are typed, the specification is not. Here the others are ahead.

State and deployment

Pulumi does more than render: it applies, records every resource in a state backend (Pulumi Cloud or one you host), previews changes and rolls back. If one tool should own cloud infrastructure (networks, clusters, DNS) and what runs in Kubernetes, Pulumi is the strongest offer on this page.

Klass8s, like cdk8s, declines that job: the output is inert YAML, the state lives in the cluster and in Git, a preview is kubectl diff, and deploying is whatever you already trust. Declining gives you nothing to host and no state file to lock, corrupt or leak; it costs Pulumi's preview and rollback. Which side you want is an architectural decision, not a score.

Languages

  • cdk8s: TypeScript first; Python, Java and Go through jsii.
  • Pulumi: TypeScript and JavaScript, Python, Go, C#, Java and YAML.
  • Klass8s: PHP and Phaenon, for teams whose product is written in them.

cdk8s and Pulumi have larger communities, more examples and more answers to search for. Klass8s has a codebase small enough to read and types that answer many questions in the editor.

Side by side

cdk8sPulumiKlass8s
Typed resourcesyesyesyes
Typed custom resourcesgenerated by importgenerated SDKsarrays under typed identity
Dependency injectionproperties passed by handper-stack configurationSymfony's container
Rules over every resourcewalking the construct treetransformsevents during construction
Environmentsyour conventionstacksbuilt in
Helmchart output includedcharts and releases deployedreleases with merged values, ordered with Apps
State, preview, rollbacknoyesno, by design
LanguagesTypeScript, Python, Java, GoTypeScript, Python, Go, C#, Java, YAMLPHP, Phaenon
Runs in the cluster or needs a backendnoa state backendno

Choosing

  • A TypeScript, Python or Go team that wants a generator: cdk8s. Klass8s in a team without PHP would be a mistake.
  • One tool for the cloud and the cluster, with state and previews: Pulumi, with its backend.
  • A PHP team: Klass8s, and not only for the language: dependency injection, the events, environments and the Helm bridge are what you would otherwise build on top of a generator yourself.