Kustomize – Templating in Kubernetes

📰 Hacker News · davinkevin

Learn Kustomize for templating in Kubernetes and improve your deployment workflow with a declarative approach

intermediate Published 20 Apr 2019
Action Steps
  1. Install Kustomize using brew or by downloading the binary from the release page
  2. Create a base directory for your original YAML files describing resources to deploy
  3. Apply customization layers on top of the base using Kustomize
  4. Use the kubectl apply command with the -f flag to apply the customized resources to your cluster
  5. Explore the declarative philosophy of Kustomize and its similarities to Git, Docker, and Kubernetes
Who Needs to Know This

DevOps teams and Kubernetes administrators can benefit from using Kustomize to manage and customize their deployments efficiently

Key Insight

💡 Kustomize provides a declarative approach to templating in Kubernetes, allowing for efficient management and customization of deployments

Share This
🚀 Simplify your Kubernetes deployments with Kustomize! 💡

Full Article

Title: Kustomize - The right way to do templating in Kubernetes

URL Source: https://blog.stack-labs.com/code/kustomize-101/

Markdown Content:
En poursuivant votre navigation sur ce site, vous acceptez l’utilisation des cookies ayant pour but de réaliser des statistiques de visites [En savoir plus](https://support.google.com/accounts/answer/61416)

[Je suis d'accord](https://blog.stack-labs.com/code/kustomize-101/)

* [About Stack Labs](https://stack-labs.com/)

[![Image 1](https://blog.stack-labs.com/logo_small.png)](https://blog.stack-labs.com/)

[![Image 2](https://blog.stack-labs.com/logo_text.svg) The new generation tech company](https://blog.stack-labs.com/)

![Image 3](https://blog.stack-labs.com/blog_icon.svg)

[Tu veux rejoindre la team ?](https://taleez.com/apply/2ube4u3#/apply)

[Découvrir STACK LABS](https://stack-labs.com/)

Stack Labs Blog moves to [Dev.to](https://dev.to/stack-labs) |Le Blog Stack Labs déménage sur [Dev.to](https://dev.to/stack-labs) 🚀

[](https://blog.stack-labs.com/code/kustomize-101/)

18 avril 2019|[Cloud](https://blog.stack-labs.com/tags/cloud)|[Kevin Davin](https://blog.stack-labs.com/author/kevin-davin)

### [Kustomize - The right way to do templating in Kubernetes](https://blog.stack-labs.com/code/kustomize-101/)

![Image 4](https://blog.stack-labs.com/images/articles/kustomize-101/Kustomize-cover.png)
Estimated read time: 11 minutes

🇬🇧 Article in English

We always need to customize our deployment with Kubernetes and, I don’t know why but the main tool around for now is HELM which throws away all the logic we learn on docker and Kubernetes. Here I will introduce to you an alternative called **Kustomize** ❤️

[Kustomize](https://github.com/kubernetes-sigs/kustomize) isn’t a new tool, it is under construction since 2017 and has been introduced as a native `kubectl` sub-command in the version `1.14`. Yeah, you’ve heard correctly, this is now embedded directly inside the tool you use everyday… so you will be able to throw that `helm` command away 😉.

## Philosophy

Kustomize tries to follow the philosophy you are using in your everyday job when using Git as VCS, creating Docker images or declaring your resources inside Kubernetes.

So, first of all, Kustomize is like Kubernetes, it is totally **declarative** ! You say what you want and the system provides it to you. You don’t have to follow the **imperative** way and describe how you want it to build the thing.

Secondly, it works like Docker. You have many layers and each of those is modifying the previous ones. Thanks to that, you can constantly write things above others without adding complexity inside your configuration. The result of the build will be the addition of the base and the different layers you applied over it.

Lastly, like Git, you can use a remote base as the start of your work and add some customization on it.

## Installation

Of course, for 🍎 Mac users, you can use `brew` to install it :

```sh
Cliquer pour copier$ brew install kustomize
```

If you are on another operating system, you can directly download the binary from the [release page](https://github.com/Kubernetes-sigs/kustomize/blob/master/docs/INSTALL.md) and add it to your path.

For the others, you also can build it from source, why not 😅.

## Your base

To start with Kustomize, you need to have your original yaml files describing any resources you want to deploy into your cluster. Those files will be stored for this example in the folder `./k8s/base/`.

Those files will NEVER (EVER) be touched, we will just apply customization above them to create new resources definitions

> **Note**: You can build base templates (e.g. for dev environment) at any point in time using the command kubectl apply -f ./k8s/base/.

In this example, we will work with a `service` and a `deployment` resources:

```yaml
Cliquer pour copierapiVersion: v1
kind: Service
metadata:
name: sl-demo-app
spec:
ports:
- name: http
port: 8080
selector:
app: sl-demo-a
Read full article → ← Back to Reads