AWS’ cdk8s, a Dev-Friendly Alternative to YAML for Managing Kubernetes Clusters
Cloud giant Amazon Web Services has launched an open-source framework, cdk8s, that provides developers with a way to define and manage Kubernetes-controlled applications and resources, using familiar programming languages, rather than the current default, YAML.
AWS demonstrated the technology last week in an AWS Summit technical session, hosted by Elad Ben-Israel, AWS principal engineer for the project, and Nathan Taber, AWS senior product manager.
The Kubernetes open source container orchestrator relies on YAML configuration files to maintain the application state. A running copy of Kubernetes continuously compares the current running deployment with what’s on the YAML file and then returns the application to the state specified in its YAML file if the two are not in sync.
“We think YAML is awesome. We use YAML everywhere,” Taber said of AWS. A declarative language, YAML is easy for admins to read and to use.
“It really does a great job of being representing the desired state of a system,” he said. “I can represent the desired state of my system and then use the state machine within Kubernetes to actually help bring that system to the desired state.”
That said, YAML does have some limitations, especially for developers who may not be as familiar with YAML or declarative languages in general.
One potential challenge is that it is very static. This can be advantageous for basic setups, such as for a simple web application. As Kubernetes applications grow more robust, however, their corresponding collection of YAML files growing harder to manage. Many organizations have resorted to copying and pasting across multiple deployments — not a scalable solution, Taber said.
As Kubernetes use grows, however, and the chore of managing the apps and clusters moves from operations teams to development teams, managing the sprawl is not very intuitive. A lot of boilerplate is used, which then can lead to issues when it is not fully understood. “Once you’ve copied or forked configurations there’s not really an established model for distributing the changes made by the source to fix bugs, or do security patching or migrate applications to new versions,”
In contrast, cdk8s allows developers to capture commonly-deployed configuration settings in a code library, which can be shared with others, and provides a foundation for building best practices and even GitOps-styled programmable infrastructure operations. In a GitOps setup, for instance, both the application and the configuration can be written in the same language, with the same toolsets and CI/CD pipeline.
The project stemmed from AWS’ work in building an internal cloud resource provisioning engine, Ben-Israel said. The idea is the same, to provide a way to define infrastructure or systems through object-oriented programming, which can be a very powerful tool for modeling systems.
Accessible through a minimal command-line interface (cli), cdk8s offers all the Kubernetes objects as strongly-typed classes. The developers define the different resources, such as containers, and their properties, such as accessible ports. Custom resource definitions (CRDs), such as operators for software such as Jenkins or databases, can also be imported.
Easing the process further, the developer can use a favorite IDE, which can provide autocompletion and other helpful aids. The software then generates a YAML file from this info. These constructs, as they are called, can be shared as libraries across different developers. The multilanguage support comes from another AWS project, called jsii.
The cdk8s framework also can be built upon. For instance, cdk8s-debore is a cdk8s library to define the Kubernetes app with just a few lines of code, covering Kubernetes resources such as Deployment, Service, HorizontalPodAutoscaler, Ingress, and others.