-1

To define clients in secret to store client name and password, how to define a client array in env and secret to store these data?

It should be like this in application.yml:

app:
  clients:
    client1: password1
    client2: password2
      ......

I tried to define this in app-deployment.yml, but it didn't seem to be allowed

env:
  - name: APPLICATION_CLIENTS
    value:
      - name: client1
        valueFrom:
          secretKeyRef:
            name: clients
            key: client1-password
      - name: client2
        valueFrom:
          secretKeyRef:
            name: clients
            key: client2-password

Error:

invalid type for io.k8s.api.core.v1.EnvVar.value: got "array" expected "string"
zm999999
  • 23
  • 1
  • 3

2 Answers2

1

Create a secret and mount that in pod as env and then in code read that env var to get the password value And approach for user name but instead of creating config map or secret directly define it as env var in pod

  • I mean, I want to define a list structure attribute in secret, which should be the case in application.yml: app: clients: - name: client1 secret: password1 - name: client2 secret: password2 ...... Do you have any ideas? – zm999999 May 07 '20 at 13:40
  • Ok in this case i think what you can do is define that env var in a file and create configmap using --from-file tag and that will available as a file in pod at the mounted path from there u have read that file ! – Mandeep Singh May 08 '20 at 15:52
0
Create a config map and mount that in dev as env and then in deployment.yaml format gives it is as reference :

config map creation with overriding application.yml/application.properties format as both strings or array or lists :

values.yaml :

------------------------------

 spring:
   profiles: default

 server:
   port: 8085
 management:
  endpoints:
    loggers:
      enabled: true
    web:
      exposure:
        include: loggers, health, prometheus
 sites:
      - publications: test1
      - publications: test2

config.yaml :

-------------------------

apiVersion: v1
kind: ConfigMap
metadata:
  name: {{ include "project.fullname" . }}
  labels:
    app.kubernetes.io/name: {{ include "project.fullname" . }}
    helm.sh/chart: {{ include "project.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
data:
  application.yml: |-
    spring:
      profiles: {{ .Values.spring.profiles }}
    server:
      port: {{ .Values.server.port }}
    management:
      endpoints:
        loggers:
          enabled: {{ .Values.management.endpoints.loggers.enabled }}
        web:
          exposure:
            include: {{ .Values.management.endpoints.web.exposure.include }}
        sites:
{{ toYaml .Values.sites | indent 10 }} #list of items in values.yaml

deployment.yaml

-----------------------

apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.name }}
  namespace: {{ .Values.namespace }}
  labels:
    app: {{ .Values.name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      app: {{ .Values.name }}
  template:
    metadata:
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/path: "/actuator/prometheus"
        prometheus.io/port: {{ .Values.server.port | quote }}
        sidecar.istio.io/inject: "false"
      labels:
        app: {{ .Values.name }}
    spec:
      volumes:
        - name: config
          configMap:
            name: {{ include "project.fullname" . }}
      containers:
        - name: {{ .Chart.Name }}
          volumeMounts:
            - name: config
              mountPath: "/app/config"
          image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          resources:
            requests:
              memory: {{ .Values.image.resources.requests.memory }}
              cpu: {{ .Values.image.resources.requests.cpu }}
            limits:
              memory: {{ .Values.image.resources.limits.memory }}
              cpu: {{ .Values.image.resources.limits.cpu }}
      imagePullSecrets:
        - name: "{{ .Values.image.imagePullSecrets }}"
    

now while running application from docker command or pom, change the path from where the application is picking config file while running. 


Example in pom : 

       <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>

                    <to>
                        <image><image-url></image>
                    </to>
                    <container>
                        <creationTime>${maven.build.timestamp}</creationTime>
                        <mainClass>mypackage.MainApplication</mainClass>
                        <args>
                            <arg>--spring.config.location=/app/config/application.yml</arg>
                        </args>
                    </container>

                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
Sandeep Jain
  • 1,019
  • 9
  • 13