Updated April 15, 2023
Introduction to Kubernetes Kustomize
Kubernetes kustomize is defined as it is an independent tool which can personalize the objects of Kubernetes through a kustomization file and that specifically outline to customize the raw and template free YAML files for various motive, kubectl also carry the leadership of Kubernetes objects with the help of kustomize files, and Kustomize is a configuration management solution that can support to the layering which can be used to protect the bottom set of our application and its parts by overspreading the indicative of YAML that called patches, in which it can override the default setting without usually swapping the original files.
What is Kubernetes kustomize?
The Kubernetes kustomize is a very helpful tool in the ecosystem of the Kubernetes which can be used to clarify the implementation that also allows us to generate the complete application of the Kubernetes via its individual pieces and it cannot move the configuration files of the YAML for their individual components, for example, we can merge the pieces from various sources to keep our customization or kustomization and the kustomize is used to generate the overlay for a specific situation and that also allows us to generate a file which can tie up everything together or it can use to override the individual parameters.
We can use the kustomize to clarify the command of our application configuration for various environments, before starting the working we need to generate the base directory through kustomization and that directory has the deployment and objects of YAML service.
Benefits:
- Reusability:
The kustomize can give permission to reuse or re-utilize one base file over all of our developing environment, staging environment, and production environment and then cover the individual statement for everyone in this way the kustomize is beneficial.
- Easy to debug:
In Kubernetes kustomize, if any activity goes incorrect then YAML themselves are uncomplicated to understand and debug so we can match that with the reality so that our configurations are out of the way in reinforcement or patches.
- Fast generation:
The kustomize does not have any templating language so that we can use the usual YAML to state our configurations rapidly.
Kubernetes kustomize Example
Let us see the working of kustomize by using deployment scenario which has 3 environments such as dev, staging, and production and these environments use the various types of services but in dev and staging environment it does not involve the HPA.
In the below example, we will use the service, deployment, horizontal pod autoscaler resources, the environments are as follows,
- dev: It uses ClusterIP service
- Staging: The Node Port service has been using in these environments
- Production: It uses Load Balancer
Let us see the structure of a directory,
The structure of the directory has a base and overlays in which one for staging environment and another for a production environment,
- The base folder contains configuration files such as deployment.YAML, hpa.YAML, kustomization.YAML, and service.YAML,
deployment.YAML:
apiVersion: apps/v1
kind: Developement
metadata:
name: frontend-developement
spec:
selector:
matchLabels:
app: frontend-developement
template:
metadata:
labels:
app: frontend-developement
spec:
containers:
- name: app
image: foo/bar:latest
ports:
- name: http
containerPort: 8080
protocol: TCP
- service.YAML:
apiVersion: v1
kind: Solution
metadata:
name: frontend-solution
spec:
ports:
- name: http
port: 8080
selector:
app: frontend-developement
- hpa.yaml:
apiVersion: autoscaling
kind: HorizontalPodAutoscaler
metadata:
name: frontend-developement-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Developement
name: frontend-developement
minReplicas: 2
maxReplicas: 6
metrics:
- type: Assets
resource:
name: cpu
target:
type: Implementation
averageUtilization: 60
- kustomization.YAML: This is a very important file in the base folder in which it shows the resources which we have been used,
apiVersion:kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- service.yaml
- deployment.yaml
- hpa.yaml
- Overlay files contain dev, production and staging let us see these in detail,
dev:
- hpa.YAML: it is useful to compare the resources with the base file,
apiVersion: autoscaling/v2beta2
form: HorizontalPodAutoscaler
metadata:
title: frontend-developement-hpa
spec:
minReplicas:2
maxReplicas:3
metrics:
- class:Assets
resource:
title:cpu
target:
class: Implementation
averageImplementation: 80
kustomization.YAML: this file can be used for configuration and patching purposes
apiVersion:kustomize.config.k8s.io/v1beta1
form:Kustomization
base:
reinforcementPlanUnite: hpa.YAML
- production:
hpa.YAML:
apiVersion:autoscaling
form:HorizontalPodAutoscaler
metadata:
title:frontend-developement-hPa
spec:
minReplicas:2
maxReplicas:30
metrics:
- class: Assets
resource:
title:cpu
target:
class:Implementation
averageImplementation:70
- kustomization.YAML: this can be used to describe the base file with the production environment,
apiVersion:kustomize.config.k8s.io/v1beta1
form: Kustomization
base:
reinforcementPlanUnite:
newprod-copy.YAML
hpa.YAML
service-loadbalancer.YAML
- rollout-replica.YAML: it describes the rolling plan
apiVersion: apps/v1
form: Developement
metadata:
title: frontend-developement
spec:
replicas: 30
strategy:
rollingUpdate:
maxSurge: 3
maxUnavailable: 3
class: RollingUpdate
- service-loadbalancer.YAML: this can be used to convert the service type into loadbalancer,
apiVersion: v1
form: Resource
metadata:
title:frontend-resource
spec:
class:LoadBalancer
Practices Kubernetes kustomize
- Best practices to hold supporting assets and their examples in discrete combination.
- Also try to retain the ordinary values such as namespace, common metadata in the base file.
- The assets can be sorted by their names that come under the lowercase-hypented.yaml and services may come under the service.YAML.
- We also need to understand that ‘bases/’ will be used for base files and ‘patches/’ or ‘overlays/ ‘will be used for environment-specific files.
- At the time of development, we need to make sure to format the file.
Install Kubernetes kustomize
We can install the latest version of kustomize by checking with the version in kubectl so let us discuss them,
- We have to run the following link for the setup
'curl -s "https://raw.githubusercontent.com/\
kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash'
For the macOS, the setup is easy to install
- We can obtain the system in native place by moving kustomize in our path by using the below link,
"sudo mv kustomize /user/local/bin"
- Then new terminal will open and we have to run kustomize -h for verification,
kustomize -h
Conclusion
In this article, we conclude that by using kustomize we can control the configurations of the Kubernetes through the Kubernetes files in which it has patches to use plain YAML for customization and validation purpose, hence go through this article it will definitely help to understand the concept of Kubernetes kustomize.
Recommended Articles
We hope that this EDUCBA information on “Kubernetes Kustomize” was beneficial to you. You can view EDUCBA’s recommended articles for more information.