<p>I'm trying to create my first Helm release on an AKS cluster using a GitLab pipeline,
but when I run the following command</p>
<pre><code>- helm upgrade server ./aks/server
      --install
      --namespace demo
      --kubeconfig ${CI_PROJECT_DIR}/.kube/config
      --set image.name=${CI_PROJECT_NAME}/${CI_PROJECT_NAME}-server
      --set image.tag=${CI_COMMIT_SHA}
      --set database.user=${POSTGRES_USER}
      --set database.password=${POSTGRES_PASSWORD}
</code></pre>
<p>I receive the following error:</p>
<pre><code>&quot;Error: Secret in version &quot;v1&quot; cannot be handled as a Secret: v1.Secret.Data: 
decode base64: illegal base64 data at input byte 8, error found in #10 byte of ...&quot;
</code></pre>
<p>It looks like something is not working with the secrets file, but I don't understand what.</p>
<p>The <code>secret.yaml</code> template file is defined as follows:</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: server-secret
  namespace: demo
type: Opaque
data:
  User: {{ .Values.database.user }}
  Host: {{ .Values.database.host }}
  Database: {{ .Values.database.name }}
  Password: {{ .Values.database.password }}
  Port: {{ .Values.database.port }}
</code></pre>
<p>I will also add the deployment and the service <code>.yaml</code> files.</p>
<p><code>deployment.yaml</code></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .Values.app.name }}
  labels:
    app: {{ .Values.app.name }}
spec:
  replicas: {{ .Values.replicaCount }}
  selector:
    matchLabels:
      tier: backend
      stack: node
      app: {{ .Values.app.name }}
  template:
    metadata:
      labels:
        tier: backend
        stack: node
        app: {{ .Values.app.name }}
    spec:
      containers:
        - name: {{ .Values.app.name }}
          image: &quot;{{ .Values.image.name }}:{{ .Values.image.tag }}&quot;
          imagePullPolicy: IfNotPresent
          env:
          - name: User
            valueFrom:
              secretKeyRef:
                name: server-secret
                key: User
                optional: false
          - name: Host
            valueFrom:
              secretKeyRef:
                name: server-secret
                key: Host
                optional: false
          - name: Database
            valueFrom:
              secretKeyRef:
                name: server-secret
                key: Database
                optional: false
          - name: Password
            valueFrom:
              secretKeyRef:
                name: server-secret
                key: Password
                optional: false
          - name: Ports
            valueFrom:
              secretKeyRef:
                name: server-secret
                key: Ports
                optional: false
          resources:
            limits:
              cpu: &quot;1&quot;
              memory: &quot;128M&quot;
          ports:
            - containerPort: 3000
</code></pre>
<p><code>service.yaml</code></p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: server-service
spec:
  type: ClusterIP
  selector:
    tier: backend
    stack: node
    app: {{ .Values.app.name }}
  ports:
    - protocol: TCP
      port: 3000
      targetPort: 3000
</code></pre>
<p>Any hint?</p>

Salvatore Calla'
<p>You have to encode secret values to base64</p>
<p>Check the doc <a href="https://helm.sh/docs/chart_template_guide/function_list/#encoding-functions" rel="nofollow noreferrer">encoding-functions</a></p>
<p>Try below code</p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: server-secret
  namespace: demo
type: Opaque
data:
  User: {{ .Values.database.user | b64enc }}
  Host: {{ .Values.database.host | b64enc }}
  Database: {{ .Values.database.name | b64enc }}
  Password: {{ .Values.database.password | b64enc }}
  Port: {{ .Values.database.port | b64enc }}
</code></pre>
<p>Else use <code>stringData</code> instead of <code>data</code></p>
<p>stringData will allow you to create the secrets without encode to base64</p>
<p>Check the example in the <a href="https://kubernetes.io/docs/concepts/configuration/secret/#bootstrap-token-secrets" rel="nofollow noreferrer">link</a></p>
<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: server-secret
  namespace: demo
type: Opaque
stringData:
  User: {{ .Values.database.user | b64enc }}
  Host: {{ .Values.database.host | b64enc }}
  Database: {{ .Values.database.name | b64enc }}
  Password: {{ .Values.database.password | b64enc }}
  Port: {{ .Values.database.port | b64enc }}
</code></pre>
