Skip to content

Welcome!

Infrastructure as Code (IaC) is a well established paradigm and refers to the standard practice of treating infrastructure (network, disk, storage, databases, message queues etc.) in the same way as application code and applying general software engineering practices including source control versioning, testing and more. For example, Terraform and AWS CloudFormation are widely-adopted technologies that use configuration files/templates to represent the infrastructure components.

What does it mean in the context of Kubernetes?

Over the course of next few (relatively short!) chapters, I will cover how Go developers can use the cdk8s (Cloud Development Kit for Kubernetes) project for defining Kubernetes resources. It's an open-source framework (also part of CNCF) that provides high-level abstractions which can be composed into larger Kubernetes applications. Instead of adopting YAML or other configuration/template driven approach, cdk8s supports multiple programming languages, which means you can work with Kubernetes resources using familiar concepts such as classes, methods, etc. Ultimately, cdk8s generates Kubernetes manifests which you can apply using kubectl - business as usual!

At the time of writing, cdk8s supports Go, Typescript, Python and Java

Infrastructure IS Code

Imagine you have an application that comprises of a Serverless function fronted by an API Gateway along with a NoSQL database as the backend. Instead of defining it in a static way (using JSON, YAML etc.), one can represent these components using standard programming language constructs such as classes, methods, etc. Here is pseudo-code example:

DBTable table = new DBTable("demo-table");
table.addPrimaryKey("email", Type.String);

Function function = new Function("demo-func");
function.addEnvVars("TABLE_NAME", table.Name());

APIGateway apigw = new APIGateway();
apigw.addFunctionIntegration(function);

Notice the (hypothetical) classes DBTable, Function and APIGateway and the way they are used. For e.g. a function can reference the table object and get it's name - all this comes to life during the program runtime and taken care of by the implementation details of the underlying framework/platform.

But, you don't have to write pseudo-code for your production infrastructure

... thanks to existing solutions such as cdk8s, AWS CDK, Pulumi, CDK for Terraform (cdktf) etc. Almost all these solutions follow a similar approach - write code to define infrastructure, then convert that into configuration, for e.g. Kubernetes manifest (YAML), AWS CloudFormation template, HCL config etc., which can then be applied using standard tooling.

While we are on this topic, its hard not to mention the Go programming language and its ubiquitous presence in the cloud services and infrastructure domain. It combines the safety of a compiled language with the speed a interpreted language (like Python), has a robust standard library and compiles to a single binary. These and many more qualities have led to lots of cloud-native software (IaC, monitoring, observability etc.) written in Go, such as Prometheus, Terraform, Grafana, Jaeger etc.

"In fact, over 75 percent of projects in the Cloud Native Computing Foundation are written in Go."

Let's get started!!!!