Skip Main Navigation

Kustomize & Crossplane: maximizing the utility of Kubernetes

As we build increasingly complex applications, leveraging the right orchestration tools will optimize the way your team manages and deploys resources to different parts of your codebase, saving your business time and development resources. Let’s talk about why Kubernetes is relevant today, and how we use it in conjunction with Kustomize and Crossplane.

What is Kubernetes?

Kubernetes (or K8s), is an open-source tool developed by Google that can orchestrate containerized apps and workloads. Kubernetes has become increasingly relevant as companies shift from writing monolithic applications (everything written in a single codespace) to splitting the code into more manageable microservices that can be deployed individually. 

 

Kubernetes offers us the ability to manage these microservices, and operates on these fundamental principles: 

  1. Declarative: Kubernetes allows us to declare the desired state of the cluster. 
  2. Distributed: Kubernetes is made to be run over a set of several machines. 
  3. Decoupled: Kubernetes can easily scale containers with multiple instances (so each container should only have a single concern). 
  4. Immutable: If the instance isn’t able to execute, Kubernetes can create a new instance for your microservice since containers are designed to be ephemeral. 

 

These are some of the basic objects that Kubernetes operates with:

  • Pod: the smallest unit of computing; usually composed of a container 
  • Deployment: defines the deployment of a given pod (i.e. replicas, how to scale it) 
  • Namespace: groups resources in the cluster 

 

Kubernetes takes care of networking, security, and management of these microservices – but even then, it can be complicated to use. For example, developers need to make sure they use namespaces and definitions properly to avoid disrupting other environments that may have highly similar or identical objects. This is where add-ons come in.

Managing Kubernetes Objects with Kustomize

Kustomize is a tool that helps us customize Kubernetes configurations. Using plain, easy-to-read YAML files, Kustomize allows us to deploy Kubernetes objects as a series of layers or patches, and manage customized Kubernetes configurations with ease. For example, we can use overlays on a deployment to change things like the number of replicas, or to use a specific image. The naming feature also lets us assign all objects to the same namespace without touching the other files. Plugins offer even more freedom to alter specific instances, such as adding tags to images.

Streamline your resources with Crossplane

Crossplane is an open-source add-on for Kubernetes that transforms it into a consistent interface that can manage cloud-based services like databases and other cloud resources. Crossplane is useful in keeping resources near where they are being used. It handles cloud resources as Kubernetes resources, for example; you could deploy an AWS database as a Kubernetes resource so that everything stays in Kubernetes. By using Kubernetes’ native structure to reconcile the desired state, we don’t need to create a state file. Crossplane will also manually revert actions performed to reach the deployed state. For example, if a database gets deleted, Crossplane will automatically recreate it.

Things to consider

So, what’s the catch? Here were a few things we noticed while using Kustomize and Crossplane that are worth noting when a team is looking to integrate them into their stack: 

  • When using Kustomize, minor version differences can result in unexpected exceptions.
  • Kustomize’s namePrefix feature changes all names, including roles created by Crossplane. 
  • Crossplane is not as robust nor well documented as Terraform (i.e. several resources, like OpenSearch, are not available on Crossplane and need to be created with Terraform). Furthermore, mixing Crossplane and Terraform can cause confusion. 
  • If some objects aren’t ready to be deployed on PROD, and Kustomize needs to know which objects to ignore, it can make your customization structure a bit complex. 

 

All in all, our experience in leveraging this set of tools has vastly improved the way we build and manage applications. Kubernetes is a powerful orchestration tool, and leveraging Kustomize and Crossplane help us maximize its utility. Kustomize helps us avoid duplications in deployment, easily create new namespaces to test new features in a cloud environment, and maintain a standard environment. Meanwhile, Crossplane helps streamline the process by keeping resources near where they’re used in the cloud. 


Tomás Dias Almeida

Back-end Software Engineer

More Developer Circle

  • Agile in practice: embracing autonomy and experimentation

    Stefan Franck

    Senior Director

    One Netcentric’s co-founders, Stefan is an expert in shaping solutions for clients - from requirements analysis to project specification and more. Stefan sees himself as the link between business and technology and, for over ten years now, he has filled various roles as architect, project lead and lead consultant. Stefan's focus is on the Adobe Marketing Cloud and AEM, to which he is strongly connected from his days at Day Software and Adobe. He says that co-founding Netcentric was one of the best choices in his professional life. Never before been able to work with so many brilliant people.