1

My original YAML

base/deployment.yaml

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
        - image: nginx
          name: nginx
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: database-configmap
data:
  config: |
    dbport=1234
    dcname=sfsdf
    dbssl=false
    locktime=300
    domainuser=

base/Kustomization.yaml

resources:
  - deployment.yaml

commonLabels:
  owner: sara

From the parent folder of base:

kustomize build base

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
    owner: sara
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
      owner: sara
  template:
    metadata:
      labels:
        app: nginx
        owner: sara
    spec:
      containers:
      - image: nginx
        name: nginx

If you observe above, the ConfigMap is being discarded, please suggest how to fix that.

Sara June
  • 389
  • 4
  • 15
  • I just tried and it's working fine on kustomize `v4.4.0`, which version are you using (`kustomize version` command)? – Mikolaj S. Oct 07 '21 at 12:09
  • kustomize version {Version:kustomize/v4.1.3 GitCommit:0f614e92f72f1b938a9171b964d90b197ca8fb68 BuildDate:2021-05-20T20:52:40Z GoOs:windows GoArch:amd64} – Sara June Oct 07 '21 at 12:26
  • Just tried with `v4.1.3` and it's fine too....but two things to notice: on the output I have ConfigMap at the top, above the Deployoment. Maybe you missed it? The second one, I tried to use `Kustomization.yaml` name of file, but I got error `Error: unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory`. Please double check if you have a proper file name. – Mikolaj S. Oct 07 '21 at 12:36
  • Don't know how, after restart of the machine, it is working. Can you please check this question also https://serverfault.com/questions/1079866/how-to-load-configmap-from-a-properties-file-using-kustomize – Sara June Oct 07 '21 at 12:49

1 Answers1

0

In both versions of the Kustomize - the current newest (v.4.4.0) and v4.1.3 used in the question it is working correctly. The author notice that the restart can help:

after restart of the machine, it is working.

Keep in mind about two things:

  • base/Kustomization.yaml name can't be used; you will get an error Error: unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization' in directory. There is a need to use proper name.
  • After running command: kustomize build base the ConfigMap will be generated at the top of the output, even if it is defined at the bottom in the resource file. Check below.

Output of the kustomize build base command:

apiVersion: v1
data:
  config: |
    dbport=1234
    dcname=sfsdf
    dbssl=false
    locktime=300
    domainuser=
kind: ConfigMap
metadata:
  labels:
    owner: sara
  name: database-configmap
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: nginx
    owner: sara
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      app: nginx
      owner: sara
  template:
    metadata:
      labels:
        app: nginx
        owner: sara
    spec:
      containers:
      - image: nginx
        name: nginx
Mikolaj S.
  • 208
  • 1
  • 7
  • can you check this also https://serverfault.com/questions/1079866/how-to-load-configmap-from-a-properties-file-using-kustomize – Sara June Oct 07 '21 at 13:26