Azure
Service Operator and Kubernetes Kustomization
Introduction: In the previous article, we discussed Kubernetes Open Service Broker API. We followed it up on
the discussion with an introduction to Azure OSBA which is also complying with the open standard and introduces
Azure resources to Kubernetes control plane. Then we discussed the Azure
Service Operator that provisions those resources via the Kubernetes control
plane. Finally, we discuss Kustomization.
Description: Kustomize is a standalone tool for the Kubernetes
platform that supports the management of objects using a kustomization file.
“kubectl kustomize
<kustomization_directory>” command allows us to view the resources that
can be kustomized. The apply verb instead of the kustomize verb can be used to
apply it again.
It can help with generating
resources, setting cross-cutting fields such as labels and annotations or
metadata and composing or customizing groups of resources.
The resources can be
generated and infused with specific configuration and secret using a configMap
generator and a secret generator respectively. For example, it can take an existing
application.properties file and generated a configMap that can be applied to
new resources.
Kustomization allows us to
override the registry for all images used in the containers for an application.
There are two advantages to
using it. First, it allows us to configure the individual components of the
application without requiring changes in them. Second, it allows us to combine
components from different sources and overlay them or even override certain
configurations. The kustomize tool provides this feature. Kustomize can add
configmaps and secrets to the deployments using their specific generators
respectively.
Kustomize
is static declaration. We can add labels across components. We can choose the
groups of Kubernetes resources dynamically using selectors but they have to be
declared as yaml. This kustomization yaml is usually stored as manifests and
applied on existing components so they refer to other yamls. The manifests is a
way of specifying the location of the kustomization files and passing it as a
commandline parameter to kubectl commands with -k option
For
example, we can say:
commonLabels:
app: potpourri-app
resources:
-
deployment.yaml
-
service.yaml
We can
even add new resources such as K8s secret
This
comes useful to inject username passwords for say a database application at the
time of install and uninstall with the help of a resource called secret.yaml.
It just won't detect a virus to force an uninstall of the product. Those
actions remain with the user.
Kustomize
also helps us to do overlays and overrides. Overlay means we change parameters
for one or more existing components. Override means we take an existing yaml
and change portions of it such as changing the service to be of type
LoadBalancer instead of NodePort or vice versa for developer builds. In this
case, we provide just enough information to lookup the declaration we want to
modify and specify the modification. For example:
apiVersion:v1
kind:Service
metadata:
name: myservice
spec:
type: NodePort
If the
above service type modification were persisted side by side as prod and dev
environment, it would be called an overlay.
Finally
the persistence of kustomization files is not strictly required and we can run:
kustomize
build manifests_folder | kubectl apply -f
or
kubectl
apply -k
One of
the interesting applications of Kustomization is the use of internal docker
registries.
we use
the secretGenerator to create the secret for the registry which typically has
the
docker-server,
docker-username, docker-password and docker-email and the secret type to be
type: docker-registry
This
secret can take environment variables and the kustomization file can even be
stored in source control.
Azure has native Kustomization
for its manifest using the parameters, variables, and builtin functions.These
vary from the kubernetes side but by exposing Azure resources to the Kubernetes
control plane, we can leverage all the
functionality native to Kubernetes.
No comments:
Post a Comment