kustomize configmap command: what does it do?

7/5/2019

I'm new to kubernetes and I'm following some tutorials here and there. I'm struggling to understand the different components and tools and one of these ones is kustomize. I saw different examples of kustomize usages and I don't understand one of them (even after searching it on the net). So can you explain to me the function of the following kustomize command:

kustomize edit add configmap mnist-map-training --from-literal=trainSteps=200
-- Patrick
kubernetes
kustomize

1 Answer

7/5/2019

Kubernetes is a tool basically that orchestrates docker containers. We create deployments, services, ingresses using yaml and these form the components of the cluster. However, lets say a team has come up with the kubernetes cluster configuration yaml files for development environment. For say, integration environment, the yaml files differ a little. It differs, even more for a production environment. So, the obvious and simple solution is to maintain three copies of yaml files. But it might not work out in the long run. A change applied to one environment may need to be applied in other environments. Missing the changes might cause issues.

Kustomize is a tool that address this issue. You create a base copy(as per our example, let's assume its development environment) of kubernetes yaml config files along with the kustomization file. The kustomization file in general, describes the resources(yaml files), configmaps, secrets to create. Then the diff to create the kubernetes cluster configuration in integration and production environments are created as overlays. You can use this link for complete reference, though it is not latest, it might help. In addition there is documentation in github as well.

Now regarding this command,

kustomize edit add configmap mnist-map-training --from-literal=trainSteps=200

This command edits the kustomize file in the current directory, to create a snippet like this:

configMapGenerator:
- name: mnist-map-training
  literals:
  - trainSteps=200

When the kustomize build command is run this creates a configmap yaml like this:

apiVersion: v1
kind: ConfigMap
metadata:
  name: mnist-map-training
data:
  trainSteps: "200"
-- Malathi
Source: StackOverflow