Skip to content

Illustrate how to work with Kustomize overlays and components

Notifications You must be signed in to change notification settings

mbigras/kustomize-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kustomize-demo

Illustrate how to work with Kustomize overlays and components.

Summary

You can inherit Kubernetes settings with Kustomize bases and overlays. But! You can also compose Kubernetes settings with Kustomize components.

Getting started

The following procedure describes how to deployment app app to a hypothetical env1 environment on Docker Desktop on your laptop.

  1. Create your Kubernetes cluster on Docker Desktop on your laptop—see mbigras/hello-kubernetes repo.

  2. Get the code.

    git clone [email protected]:mbigras/kustomize-demo.git
    cd kustomize-demo
    
  3. Run example.sh script.

    ./example.sh
    

    Your output should look like the following:

    $ ./example.sh
    # ...
    deployment.apps/app created
    # ...
    {
      "app": "app",
      "env": "env1",
      "color": "cheapblue",
      "password": "s3cr3t",
      "features": [
        "feature1",
        "feature2"
      ]
    }
    deployment.apps "app" deleted
    

    Observation: Notice that you created your app—that is, a app Kubernetes Deployment—, send a test request, and deleted your app!

Study Kustomize code

The following procedure describes how to create an app Kubernetes Deployment with Kustomize overlays and components.

  1. Build your app Kubernetes settings for env1 environment.

    kustomize build [email protected]:mbigras/kustomize-demo.git//overlays/env1?ref=35b728e6ba9ad874fa6f49985aa5081508fcc52d
    

    Your output should look like the following:

    $ kustomize build [email protected]:mbigras/kustomize-demo.git//overlays/env1?ref=35b728e6ba9ad874fa6f49985aa5081508fcc52d
    apiVersion: apps/v1
    kind: Deployment
    metadata:
      labels:
        app: app
      name: app
    spec:
      selector:
        matchLabels:
          app: app
      template:
        metadata:
          labels:
            app: app
        spec:
          containers:
          - env:
            - name: ENV
              value: env1
            - name: COLOR
              value: cheapblue
            - name: PASSWORD
              value: s3cr3t
            - name: FEATURE2
              value: "on"
            - name: FEATURE1
              value: "on"
            image: mbigras/app:2023-07-15
            name: app
    

    Consider the following details:

    1. Observation: Notice that the app Deployment contains an app Container that is configured to run in env1 environment.
    2. Note: You inject settings as environment variables—follows excellent twelve-factor methodology—see https://12factor.net/config page.
  2. To understand how the ENV, COLOR, and PASSWORD settings reach app running in env1 environment, consider the overlays/env1/kustomization.yaml#L3-L6 code.

    kind: Kustomization
    apiVersion: kustomize.config.k8s.io/v1beta1
    resources:
      - ../../base
    patches:
      - path: deployment.yaml
    # ...

    Observation: Notice how your overlay inherits your base, then patches—inheritance.

  3. To understand how the FEATURE1 and FEATURE2 settings reach app running in env1 environment, consider the overlays/env1/kustomization.yaml#L7-L9 code.

    kind: Kustomization
    apiVersion: kustomize.config.k8s.io/v1beta1
    # ...
    components:
      - ../../components/feature1
      - ../../components/feature2

    Observation: Notice how your overlay reaches your components like plug and play composition—excellent!

Conclusion

You can freely compose Kubernetes YAML objects with Kustomize bases, overlays, and components. Kustomize bases and overlays compose like inheritance. Kustomize components compose like plug and play.

About

Illustrate how to work with Kustomize overlays and components

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published