I am trying to deploy my image to Azure Kubernetes Service. I use command:
kubectl apply -f mydeployment.ymlAnd here is my deployment file:
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-api
spec:
replicas: 1
selector:
matchLabels:
app: my-api
template:
metadata:
labels:
app: my-api
spec:
containers:
- name: my-api
image: mycr.azurecr.io/my-api
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 250m
memory: 256Mi
ports:
- containerPort: 80
envFrom:
- configMapRef:
name: my-existing-config-mapI have configmap my-existing-config-map created with a bunch of values in it but the deployment doesn't add these values as environment variables.
Config map was created from ".env" file this way:
kubectl create configmap my-existing-config-map --from-file=.envWhat am I missing here?
If your .env file in this format
a=b
c=dyou need to use --from-env-file=.env instead.
To be more explanatory, using --from-file=aa.xx creates configmap looks like this
aa.xx: |
file content here....
....
....When the config map used with envFrom.configmapref, it just creates on env variable "aa.xx" with the content. In the case, that filename starts with '.' like .env , the env variable is not even created because the name violates UNIX env variable name rules.
As you are using the .env file the format of the file is important 1. Create config.env file in the following format which can include comments
<!-- begin snippet: js hide: false console: true babel: false --><!-- language: lang-js --> echo -e "var1=val1\n# this is a comment\n\nvar2=val2\n#anothercomment" > config.env<!-- end snippet -->Create Config Map
kubectl create cm config --from-env-file=config.env <!-- end snippet -->apiVersion: v1
kind: Pod
metadata:
labels:
run: nginx
name: nginx
spec:
containers:
- image: nginx
name: nginx
resources: {}
envFrom:
- configMapRef:
name: config<!-- end snippet -->