yolen
11/04/2018, 1:31 PMall: onlaw_configmap database prisma
onlaw_secrets:
kubectl create secret generic onlaw --from-env-file=../.env
onlaw_configmap:
kubectl delete configmap onlaw --ignore-not-found
kubectl create configmap onlaw --from-env-file ../.env
onlaw_db:
kubectl apply -f database/pvc.yml
kubectl apply -f database/deployment.yml
kubectl apply -f database/service.yml
onlaw_prisma: onlaw_configmap
kubectl apply -f prisma/configmap.yml
kubectl apply -f prisma/deployment.yml
kubectl apply -f prisma/service.yml
kubectl get pods deployment.yml apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: prisma
labels:
stage: production
name: prisma
app: prisma
spec:
replicas: 1
strategy:
type: Recreate
template:
metadata:
labels:
stage: production
name: prisma
app: prisma
spec:
containers:
- name: prisma
image: 'prismagraphql/prisma:1.19'
ports:
- name: prisma-4466
containerPort: 4466
# command: [ "sh", "-c"]
# args:
# - while true; do
# echo -en '\n';
# printenv DB_USER
# printenv PRISMA_CONFIG;
# sleep 10;
# done;
env:
- name: DB_USER
valueFrom:
configMapKeyRef:
name: onlaw
key: DB_USER
- name: DB_PASSWORD
valueFrom:
configMapKeyRef:
name: onlaw
key: DB_PASSWORD
- name: DB_HOST
valueFrom:
configMapKeyRef:
name: onlaw
key: DB_HOST
- name: PRISMA_MANAGEMENT_API_SECRET
valueFrom:
configMapKeyRef:
name: onlaw
key: PRISMA_MANAGEMENT_API_SECRET
- name: PRISMA_HOST_PORT
valueFrom:
configMapKeyRef:
name: onlaw
key: PRISMA_HOST_PORT
- name: PRISMA_CONFIG
valueFrom:
configMapKeyRef:
name: prisma-configmap
key: PRISMA_CONFIG configmap.yml apiVersion: v1
kind: ConfigMap
metadata:
name: prisma-configmap
labels:
stage: production
name: prisma
app: prisma
data:
PRISMA_CONFIG: |
port: penis
managementApiSecret: ${PRISMA_MANAGEMENT_API_SECRET}horse
databases:
default:
connector: mysql
#host: ${DB_HOST}
host: database
port: 3306
#user: ${DB_USER}
user: root
#password: ${DB_PASSWORD}
password: prisma
migrations: true So what troubles me is that it does not matter what the port and or the manament_api_secret is set to in PRISMA_CONFIG. Here it is of course wrong (includes the word "penis") but it works anyway. My guess is that prisma either 1) does string replacement whenever ${} is encountered or that the environment variables set in the pods in deployment.yml equals other environment var that prisma look for besides PRISMA_CONFIG ? What I would like to do is to inject environment variables into the PRISMA_CONFIG yaml scalar block but I cannot figure out how (unless I write a script generating my config files; not a good approach if i later want to store e.g. password in k8s secrets ).Sach97
11/05/2018, 7:56 AMyolen
11/05/2018, 8:00 AMexport $(cat ../.env | xargs)
perl -p -e 's/\$\{([^}]+)\}/defined $ENV{$1} ? $ENV{$1} : $&/eg; s/\$\{([^}]+)\}//eg' prisma/configmap.template.yml > prisma/configmap.yml so configmap containing PRISMA_CONFIG is build from a template