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
  • 551

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