Kube / create deployment with config map

2/5/2019

I new in kube, and im trying to create deployment with configmap file. I have the following:

app-mydeploy.yaml
--------
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-mydeploy
  labels:
    app: app-mydeploy
spec:
  replicas: 3
  selector:
    matchLabels:
      app: mydeploy
  template:
    metadata:
      labels:
        app: mydeploy
    spec:
      containers:
        - name: mydeploy-1
          image: mydeploy:tag-latest
          envFrom:
          - configMapRef:
              name: map-mydeploy

map-mydeploy
-----
apiVersion: v1
kind: ConfigMap
metadata:
  name: map-mydeploy
  namespace: default
data:
  my_var: 10.240.12.1

I created the config and the deploy with the following commands:

kubectl create -f app-mydeploy.yaml

kubectl create configmap map-mydeploy --from-file=map-mydeploy

when im doing kubectl describe deployments, im getting among the rest:

Environment Variables from:
  map-mydeploy  ConfigMap  Optional: false

also kubectl describe configmaps map-mydeploy give me the right results.

the issue is that my container is CrashLoopBackOff, when I look at the logs, it says: time="2019-02-05T14:47:53Z" level=fatal msg="Required environment variable my_var is not set.

this log is from my container that says that the my_var is not defined in the env vars.

what im doing wrong?

-- MIDE11
kubernetes

1 Answer

2/5/2019

I think you are missing you key in the command

kubectl create configmap map-mydeploy --from-file=map-mydeploy

  • try to this kubectl create configmap map-mydeploy --from-file=my_var=map-mydeploy

also I highly recommend that if you are just using one value, create you configMap from literal kubectl create configmap my-config --from-literal=my_var=10.240.12.1 then related the configMap in your deployment as you are currently doing it.

-- cperez08
Source: StackOverflow