Import data to config map from kubernetes secret

后端 未结 2 2085
半阙折子戏
半阙折子戏 2021-02-19 07:41

I\'m using a kubernetes ConfigMap that contains database configurations for an app and there is a secret that has the database password. I need to use this secret in the ConfigM

相关标签:
2条回答
  • 2021-02-19 08:18

    I would transform the whole configMap into a secret and deploy the database password directly in there. Then you can mount the secret as a file to a volume and use it like a regular config file in the container.

    0 讨论(0)
  • 2021-02-19 08:21

    Kubernetes can't make that substitution for you, you should do it with shell in the entrypoint of the container.

    This is a working example. I modify the default entrypoint to create a new variable with that substitution. After this command you should add the desired entrypoint.

    apiVersion: extensions/v1beta1
    kind: Deployment
    metadata:
      name: app
      labels:
        app: backend
    spec:
      replicas: 1
      template:
        metadata:
          labels:
            app: backend
        spec:
          containers:
          - name: app
            image: simple-app-image
            command:
              - /bin/bash
              - -c
            args:
              - "NEW_APP_CONFIG=$(echo $APP_CONFIG | envsubst) && echo $NEW_APP_CONFIG && <INSERT IMAGE ENTRYPOINT HERE>"
            ports:
              - name: "app"
                containerPort: 8080
            env:
              - name: APP_CONFIG
                valueFrom:
                  configMapKeyRef:
                    name: config
                    key: APP_CONFIG
              - name: DB_PASSWORD
                valueFrom:
                  secretKeyRef:
                    name: "mysql-secret"
                    key: "mysql-root-password"
    
    0 讨论(0)
提交回复
热议问题