When saving secret information locally in a file named .env and registering it with Kubernetes:
Execute the following script in the development environment during deployment.
# Set kubeconfig
export KUBECONFIG=${HOME}/.kube/my-kube-config
# If a secret already exists, delete it (for the next registration)
kubectl -n mynamespace delete secret myapp-env
# Register the local ../.env as a secret
kubectl -n mynamespace create secret generic myapp-env --from-env-file=../.env
When using it
apiVersion: apps/v1
kind: Deployment
metadata:
name: myapp-deployment
namespace: mynamespace
spec:
replicas: 1
selector:
matchLabels:
app: myapp
template:
metadata:
labels:
app: myapp
spec:
containers:
- name: myapp
image: my-image:latest
imagePullPolicy: Always
ports:
- containerPort: 8008
env:
- name: DJANGO_SETTINGS_MODULE
value: myapp.settings.production
envFrom:
- secretRef:
name: myapp-env
Comments