How to deploy a nodejs app using kubernetes and mongodb

1/28/2019

I'm trying to deploy an application built using nodejs and mongodb. I have mongodb on different VM and I have added the urls for the mongodb servers as a secret in the kubernetes cluster. I have an env variable for the mongodb secret and MONGODB_URL is the var that holds the secret and its declared as process.env.MONGODB_URL in the .js file. But when I try to deploy the app the my pod has a crashloopbackoff status and I get this error when I describe it.

starting container process caused "exec: \"--env=\\\"MONGODB_URL=–nmongodb://10.128.x.x,10.128.x.x:27017/db?replicaSet=rs0”\\n\\\"\": stat --env=\"MONGODB_URL=–nmongodb://10.128.x.x,10.128.x.x:27017/db?replicaSet=rs0”\n\": no such file or directory"

this is what my deployment yaml file looks like

kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: s-provider
spec:
  selector:
    matchLabels:
       app: s-provider
       role: provider
 replicas: 1
 template:
   metadata:
     name: s-provider
     labels:
       app: s-provider
       role: provider
       env: staging
   spec:
     containers:
     - name: s-provider
       image: gcr.io/gcr-project/sample:1.0.0
       env:
        - name: MONGODB_URL
          valueFrom:
          secretKeyRef:
            name: mongo-secret
            key: MONGODB_URL
      #- name: API_URL
       # valueFrom:
        #  secretKeyRef:
         #   name: lesvault
          #  key: api_url_staging
      - name: NODE_ENV
        value: production
    resources:
      limits:
        memory: "500Mi"
        cpu: "100m"
    imagePullPolicy: Always
    readinessProbe:
      httpGet:
        path: /
        port: 3000
    args: ['--env="MONGODB_URL=$(MONGODB_URL)"']
    ports:
    - name: s-provider
      containerPort: 3000

can anyone tell me what the error says and help me to solve it

-- ILoveCode
kubectl
kubernetes
kubernetes-health-check
mongodb
node.js

0 Answers