rekustomize
lets you generate
kustomize
manifests. With
rekustomize
you can:
- Export resource manifests from live cluster using supported formats:
- Filter exported resources or attributes based on customizable rules (example)
- Deduplicate manifests to ensure DRY principle
- Re-format existing manifests to follow customizable styles and to optimize duplicated manifests
- Convert existing manifests between formats, e.g. from helm chart to kustomize components
rekustomize
truly shines when it's used to generate manifests for multiple
clusters at once. It will group correlad resources together and will also
efficiently handle multiple versions of the same resource.
This template
shows how rekustomize
can handle multiple versions of the same resource:
spec:
{{- if index .Values.global "simple-app/Deployment/simple-app.spec.replicas" }}
replicas: {{ index .Values.global "simple-app/Deployment/simple-app.spec.replicas" }}
{{- end }} # simple-app/Deployment/simple-app.spec.replicas
template:
spec:
containers:
- image: {{ index .Values.global "simple-app/Deployment/simple-app.spec.template.spec.containers.[name=simple-app].image" }}
name: simple-app
values.yaml defines presets to group values from different resources:
preset_values:
prod:
simple-app/ConfigMap/simple-app-env.data.ENV_VAR2: prod-value
simple-app/Deployment/simple-app.spec.replicas: 5
prod_test:
simple-app/Deployment/simple-app.spec.template.spec.containers.[name=simple-app].image: example.com/simple-app:v1.2.345
test:
simple-app/ConfigMap/simple-app-env.data.ENV_VAR2: test-value
simple-app/Deployment/simple-app.spec.replicas: 3
The generated presets are then assigned to each corresponding cluster:
valuesInline:
presets:
- prod_test
- test
valuesInline:
presets:
- prod
- prod_test
Values, that are unique to a cluster are also supported:
valuesInline:
global:
simple-app/ConfigMap/simple-app-env.data.ENV_VAR3: prod-cluster-a-value
If you use kustomize components format, similar overrides will be generated as strategic-merge patches:
apiVersion: apps/v1
kind: Deployment
metadata:
name: simple-app
namespace: simple-app
spec:
replicas: 5
apiVersion: apps/v1
kind: Deployment
metadata:
name: simple-app
namespace: simple-app
spec:
replicas: 3
apiVersion: apps/v1
kind: Deployment
metadata:
name: simple-app
namespace: simple-app
spec:
template:
spec:
containers:
- name: simple-app
image: example.com/simple-app:v1.2.345
To start using rekustomize
, create a new folder with a rekustomization.yaml
file where you can configure rekustomize
behavior. Here's a breakdown of the
helm chart example:
By default rekustomize
will use clusters defined in your KUBECONFIG
file.
You can select clusters using shell-like patterns:
clusters:
- names: dev-* # shell-like pattern
tags: dev
- names: test-cluster-a,test-cluster-* # comma-separated list
tags: test
- names: # yaml list
- prod-cluster-a
- prod-cluster-*
tags: prod
In the future versions rekustomize
will be able to use cluster metadata/labels
from external sources, such as ClusterAPI, k0rdent, ArgoCD or
Flux.
By default, rekustomize
will generate manifests for all resources from all
namespaces, excluding a pre-defined list of dynamic
resources, like pods
or events
. You can customize that behavior in the
export
section:
export:
- namespaces: simple-app
labelSelectors: ['!generated-by']
apiResources:
exclude: jobs.batch
- apiResources: namespaces
names: simple-app
If your live cluster resources contain attributes that you don't want to be
included in the generated manifests, you can use SkipFilter
to remove such
unwanted attributes or values. The following example will remove any
'example.com/generated'
annotations and 'dev.example.com/info'
annotations
with the value of 'flaky-tests'
:
filters:
- kind: SkipFilter
fields:
- metadata.annotations.example\.com/generated
- metadata.annotations.dev\.example\.com/info[=flaky-tests]
You can also use SkipFilter
to exclude entire resources from the generated
manifests - to further refine resource selection:
filters:
- kind: SkipFilter
resources:
- kind: CronJob
name: infra-canary
This section defines metadata for the generated chart:
helmChart:
name: simple-app
version: v1.0
If no helmChart
is specified, rekustomize
will generate manifests in kustomize components format