Slide 1

Slide 1 text

Templating and Rendering Using Kustomization and Kpt Irvi Aini @irvifa

Slide 2

Slide 2 text

Agenda ● Introduction ● Kustomize ● Kpt ● Skaffold ● Demo ● Q&A

Slide 3

Slide 3 text

Kustomize https://kubectl.docs.kubernetes.io/references/kustomize

Slide 4

Slide 4 text

“kustomize lets you customize raw, template-free YAML files for multiple purposes, leaving the original YAML untouched and usable as is.” This tools is originally sponsored by sig-cli as mentioned in the KEP. TL;DR ● Helps customizing config files in a template free way. ● Provides a number of handy methods like generators to make customization easier, e.g ConfigMap and Secret ● Provides patches to introduce environment specific changes on an already existing standard config file without disturbing the original files Kustomize

Slide 5

Slide 5 text

● Create a Kustomization file, this configuration should declare all of the resources that you’d like to apply the configuration over them ● Create variants using overlays, generally speaking an overlay is just another Kustomization file which will be referring to base configuration and additional patches that you’d like to apply for each of the environments Kustomize Usage

Slide 6

Slide 6 text

resources - what existing resources are to be customized. Example fields: resources, crds. meta - fields which may influence all or some of the above. Example fields: vars, namespace, apiVersion, kind, etc generators - what new resources should be created. Example fields: configMapGenerator (legacy), secretGenerator (legacy), generators (v2.1). transformers: alter specific bits of your resource definitions. e.g. labels, annotations

Slide 7

Slide 7 text

Overlays Base configuration

Slide 8

Slide 8 text

Kpt https://goo.gle/kpt

Slide 9

Slide 9 text

Original tweet

Slide 10

Slide 10 text

For further discussion we will use kpt v1. In general, the 2 fundamentals concept in kpt are: ● Packages. A package is a bundle of configuration data, which is explicitly declare inside of Kptfile. Note that a package can be a part of another package, called as a subpackage. ● Functions. A containerized program that can perform CRUD operations on Kubernetes Resource Model (KRM) resources stored on your local, it also act as a mechanism to automate mutation and validation of KRM resources. Kpt Concepts

Slide 11

Slide 11 text

Contains the user-specified Git reference to the upstream package Records the upstream Git reference (exact Git SHA) that was fetched by kpt. This section is managed and should not be changed manually. Modified from: Getting a Package

Slide 12

Slide 12 text

Kpt Workflow Create Edit Render Update Initialize Preview Apply Observe Get Modified from Kpt workflow

Slide 13

Slide 13 text

Skaffold https://skaffold.dev/

Slide 14

Slide 14 text

Skaffold’s Architecture Skaffold handles the workflow for building, pushing, and deploying your application, and provides building blocks for creating CI/CD pipelines.

Slide 15

Slide 15 text

Version of the configuration Project’s identifier Determines how images are tagged. Images that needs to be build, in this case the image is build using jib. Describes how the images are deployed Override for multiple environments. More references can be seen in this page.

Slide 16

Slide 16 text

Demo

Slide 17

Slide 17 text

jib configuration to build the container kustomize overlays Kptfile Skaffold Sample code is available on irvifa/skaffold-kpt-example

Slide 18

Slide 18 text

jib configuration to build the container kustomize overlays Kptfile Skaffold Sample code is available on irvifa/skaffold-kpt-example Where is the Dockerfile??

Slide 19

Slide 19 text

Sample code is available on irvifa/skaffold-kpt-example jib configuration to build the container kustomize overlays Kptfile Skaffold Where is the Dockerfile?? Skaffold ♡ Jib

Slide 20

Slide 20 text

Builder: Jib is a set of plugins used or building optimized OCI-compliant container images for Java applications without a Docker daemon. Tagger: inputDigest: if there’s no changes inside the source files then the tag won’t be changed.

Slide 21

Slide 21 text

With Jib With Docker Why Jib? 🤔 Jib is already an official builder for Skaffold I’m using Java and since Jib is available I don’t want to care about my Dockerfiles

Slide 22

Slide 22 text

Base image Application main class will act as entry point. Ports where the server will be served.

Slide 23

Slide 23 text

Resource path for default deployer Default k8s context

Slide 24

Slide 24 text

Enable port forwarding so we can call the API from our local

Slide 25

Slide 25 text

Port Forwarding Built-in support for forwarding ports from exposed Kubernetes resources to your local machine when running in dev, debug, deploy, or run modes.

Slide 26

Slide 26 text

Skaffold dev loop File sync Build Test Deploy If there’s changes on your source code then it will be deployed

Slide 27

Slide 27 text

Platinum sponsors: Gold sponsors:

Slide 28

Slide 28 text

Organized by: Community partners:

Slide 29

Slide 29 text

Thanks! ฅ(^・ω・^ฅ) Do you have any questions?