Kubernetes Kustomize Tutorial
Kubernetes Kustomize Tutorial
Kustomize, just like the name implies, is used for customizing Kubernetes deployments to help
developers manage Kubernetes application configurations. With Kustomize, it is easy to define a
base set of Kubernetes resources and create overlays on top of it in separate directories to modify
or extend the base configuration. It allows you to have a single source of truth for all your
Kubernetes application configuration while still being able to customize it for different
environments or use cases. Kustomize is especially helpful while managing large or complex
Kubernetes deployments, where maintaining separate YAML files for each environment or use
case can be tricky and error-prone.
Using a rolling update strategy, this Kustomize tutorial will deploy multiple variants of a simple
public Hello World server. So let's begin the show!!!
Prerequisites:
Free Harness account with free builds
Minikube to have a single node cluster access
A repo containing the kustomization yaml file. We'll use a publicly available hellword
kustomization cloned from Kustomize.
Tutorial
In our example repo, you can see
the configMap.yaml, deployment.yaml, service.yaml and kustomization.yaml.
For any Kubernetes application deployment, we need deployment and service manifest files. In
this tutorial, we are more interested in the kustomization manifest file. Why?
Let's take a use case where kustomization comes in handy for developers and DevOps
professionals.
Suppose you're using a deployment package from a specific vendor that is almost suitable for
your use case, but not entirely. Consequently, you create a fork of the deployment package, make
necessary configuration changes, and apply it to your Kubernetes cluster. After a few months,
the vendor releases a new version of the package that incorporates critical features that you
require. To utilize those new features, you have to fork the updated package and reapply your
configuration changes.
As your deployment scales, this repetitive process of reforking and customizing the deployment
package can become a tedious task and lead to an increased likelihood of misconfigurations,
which could compromise the stability of your product and services. This can be easily avoided
by making use of kustomize.
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
# metadata:
# name: arbitrary
resources:
- deployment.yaml
- service.yaml
- configMap.yaml
By default, Kustomize concatenates all the resources listed in the resources section in the order
they appear and applies any overlays if they are specified.
This is just a basic example of a kustomization.yaml file. You can add many more options and
customizations to manage more complex deployments with multiple environments and
configurations using Kustomize.
Login to your Harness CD module and start your free plan where you get free builds.
You need to have a Delegate up and running to deploy with Harness. Let's add Delegate.
Now, you need to install this Harness Delegate on your Kubernetes cluster.
Make sure you have a cluster access from any cloud provider.
Nothing to worry about if you don't have access to any cluster access. We will make use of
Minikube.
Once the installation is complete, start the Minikube cluster with the following command.
minikube start
As guided there, download the harness delegate yml file and run the below command from the
folder where your yaml file is downloaded.
Apply changes, save and run the pipeline. You should see a successful execution of the pipeline.
You can see the console view also.
This is how you can deploy multiple variants of a simple public Hello World server using a
rolling update strategy using Harness.
For more help, refer to the following Harness developer hub link.
Also, if you like to learn more about CI/CD and practical examples, follow my tutorial where I
shared a complete CI/CD setup from scratch.