Mongo Express Error while using Basic Auth in Kubernetes

你说的曾经没有我的故事 提交于 2021-01-29 11:19:19

问题


I am deploying a mongo-express pod in my kubernetes cluster in order to have a quick view of my db data.

I can use mongo-express normally if I do not config basic auth.

However, when I add the basic auth configuration to my Deployment yaml file. It has the below error that showing on website directly.

Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds.

I am using Kubernetes cluster and I use Ingress to expose mongo-express. Therefore, I access it with this url: db.myapp.com

This is my Deployment yml:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mongo-express
  labels:
    app: mongo-express
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mongo-express
  template:
    metadata:
      labels:
        app: mongo-express
    spec:
      containers:
        - name: mongo-express
          image: mongo-express
          ports:
            - containerPort: 8081
          env:
            - name: ME_CONFIG_MONGODB_SERVER
              valueFrom:
                configMapKeyRef:
                  name: mongodb-configmap
                  key: database_url
            - name: ME_CONFIG_BASICAUTH_USERNAME
              value: admin
            - name: ME_CONFIG_BASICAUTH_PASSWORD
              value: mypassword

---
apiVersion: v1
kind: Service
metadata:
  name: mongo-express-service
  annotations:
    cloud.google.com/neg: '{"ingress": true}'
spec:
  ports:
    - port: 8081
      protocol: TCP
  selector:
    app: mongo-express
  type: NodePort

---
My ingress:
      ...
      - host: db.myapp.com
        http:
          paths:
            - backend:
                serviceName: mongo-express-service
                servicePort: 8081

If I added ME_CONFIG_BASICAUTH_USERNAME and ME_CONFIG_BASICAUTH_PASSWORD, it will become the above error.

And even if the basic auth config and error exist, I check the logs for this pod are:

Welcome to mongo-express
------------------------
Mongo Express server listening at http://0.0.0.0:8081
Server is open to allow connections from anyone (0.0.0.0)
basicAuth credentials are "admin:pass", it is recommended you change this in your config.js!
Database connected
Admin Database connected

so there is no error in the pod

来源:https://stackoverflow.com/questions/64412085/mongo-express-error-while-using-basic-auth-in-kubernetes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!