<p>I am trying to deploy a rest api application in kubernetes with helm. Some of the configuration files have credentials in them and I would like to replace the variables inside the helm templates during the deployment with Kubernetes secrets.</p>
<p>Does anyone have a pointer to a documentation where I can explore this please ?</p>

S1c0r4x
<p>If you are looking forward to directly deploy the <code>ENV</code> to the deployment file you can also do it if you can few environment variables however best practices to create the <strong>secret</strong> and inject them all into the <strong>deployment</strong>.</p>
<p>here sharing the direct example to inject the secret into the deployment</p>
<p><strong>deployment.yaml</strong></p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: &quot;{{  .Chart.Name }}-deployment&quot;
  labels:
    chart: '{{ .Chart.Name }}-{{ .Chart.Version | replace &quot;+&quot; &quot;_&quot; }}'
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxUnavailable: 0
      maxSurge: 1
  selector:
    matchLabels:
      app: &quot;{{  .Chart.Name }}-selector&quot;
      version: &quot;current&quot;
  revisionHistoryLimit: {{ .Values.revisionHistoryLimit }}
  template:
    metadata:
      labels:
        app: &quot;{{  .Chart.Name }}-selector&quot;
        version: &quot;current&quot;
    spec:
      containers:
      - name: &quot;{{  .Chart.Name  }}&quot;
        image: &quot;{{ .Values.image.repository }}:{{ .Values.image.tag }}&quot;
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        ports:
        - containerPort: {{ .Values.service.servicePort}}
        resources:
          requests:
            cpu: &quot;{{ .Values.image.resources.requests.cpu }}&quot;
            memory: &quot;{{ .Values.image.resources.requests.memory }}&quot;
        env:
          - name: PORT
            value : &quot;{{ .Values.service.servicePort }}&quot;
        {{- if .Values.image.livenessProbe }}
        livenessProbe:
{{ toYaml .Values.image.livenessProbe | indent 10 }}
        {{- end }}
        {{- if .Values.image.readinessProbe }}
        readinessProbe:
{{ toYaml .Values.image.readinessProbe | indent 10 }}
        {{- end }}
</code></pre>
<p><strong>values.yaml</strong></p>
<pre><code>image:
  repository: nodeserver
  tag: 1.0.0
  pullPolicy: IfNotPresent 
  resources:
    requests:
      cpu: 200m
      memory: 300Mi
  readinessProbe: {}
  # Example (replace readinessProbe: {} with the following):
  # readinessProbe:
  #   httpGet:
  #     path: /ready
  #     port: 3000
  #   initialDelaySeconds: 3
  #   periodSeconds: 5
  livenessProbe: {}
  # Example (replace livenessProbe: {} with the following)::
  # livenessProbe:
  #   httpGet:
  #     path: /live
  #     port: 3000
  #   initialDelaySeconds: 40
  #   periodSeconds: 10  
service:
  name: Node
  type: NodePort
  servicePort: 3000
</code></pre>
<p>you can see inside the deployment.yaml code block</p>
<pre><code>env:
          - name: PORT
            value : &quot;{{ .Values.service.servicePort }}&quot;
</code></pre>
<p>it's fetching the values from <code>values.yaml</code> file</p>
<pre><code>service:
  name: Node
  type: NodePort
  servicePort: 3000
</code></pre>
<p>if you don't want to update the <code>values.yaml</code> file you can rewrite the value using the command also</p>
<pre><code>helm install chart my-chart -n namespace-name --set service.servicePort=5000 
</code></pre>
