K8s Create Deployment with EnvFrom

5/21/2019

I am trying to fire up an influxdb instance on my cluster.

I am following a few different guides and am trying to get it to expose a secret as environment variables using the envFrom operator. Unfortunately I am always getting the Environment: <none> after doing my deployment. Doing an echo on the environment variables I expect yields a blank value as well.

I am running this command to deploy (the script below is in influxdb.yaml): kubectl create deployment influxdb --image=influxdb

Here is my deployment script:

 apiVersion: extensions/v1beta1
 kind: Deployment
 metadata:
   creationTimestamp: null
   generation: 1
   labels:
     app: influxdb
     project: pihole
   name: influxdb
 spec:
   progressDeadlineSeconds: 600
   replicas: 1
   revisionHistoryLimit: 10
   selector:
     matchLabels:
       app: influxdb
   strategy:
     rollingUpdate:
       maxSurge: 25%
       maxUnavailable: 25%
     type: RollingUpdate
   template:
     metadata:
       creationTimestamp: null
       labels:
         app: influxdb
     spec:
       containers:
       - name: influxdb
         envFrom:
         - secretRef:
             name: influxdb-creds
         image: docker.io/influxdb:1.7.6
         imagePullPolicy: IfNotPresent
         resources: {}
         terminationMessagePath: /dev/termination-log
         terminationMessagePolicy: File
         volumeMounts:
         - mountPath: /var/lib/influxdb
           name: var-lib-influxdb
       dnsPolicy: ClusterFirst
       restartPolicy: Always
       schedulerName: default-scheduler
       securityContext: {}
       terminationGracePeriodSeconds: 30
       volumes:
       - name: var-lib-influxdb
         persistentVolumeClaim:
           claimName: influxdb
 status: {}

The output of kubectl describe secret influxdb-creds is this:

Name:         influxdb-creds
Namespace:    default
Labels:       <none>
Annotations:  <none>

Type:  Opaque

Data
====
INFLUXDB_USERNAME:  4 bytes
INFLUXDB_DATABASE:  6 bytes
INFLUXDB_HOST:      8 bytes
INFLUXDB_PASSWORD:  11 bytes
-- Khirok
kubernetes

2 Answers

5/22/2019

The answer to this is that I was creating the deployment incorrectly. I was using the command kubectl create deployment influxdb --image=influxdb which was creating a blank deployment and instead I should have been creating it with kubectl create -f influxdb.yaml where influxdb.yaml was my file that contained the deployment definition in the original question.

I was making the false assumption that the create deployment command read the yaml file by the same name, but it does not.

-- Khirok
Source: StackOverflow

5/21/2019

to test your deployment, please first create secrets and later create deployment:

1. Secrets:
kubectl create secret generic influxdb-creds --from-literal=INFLUXDB_USERNAME='test_user' --from-literal=INFLUXDB_DATABASE='test_password'

2. Deployment:
kubectl apply -f <path_to_your_yaml_file>

In order to verify, please run

kubectl describe secret influxdb-creds

kubectl exec <your_new_deployed_pod>  -- env
kubectl describe pod <your_new_deployed_pod>

Take a look at:

Environment Variables from:
      influxdb-creds  Secret  Optional: false

Hope this help.

Please share with your findings.

-- Hanx
Source: StackOverflow