I have a config yaml file for a kubernetes deployment that looks like this:
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
labels:
app: <some_app>
name: <some_app>
namespace: dataengineering
spec:
replicas: 1
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
app: <some_app>
spec:
dnsPolicy: ClusterFirst
restartPolicy: Always
terminationGracePeriodSeconds: 30
containers:
- image: 127579856528.dkr.ecr.us-west-2.amazonaws.com/dataengineering/<some_app>:latest
imagePullPolicy: Always
name: <some_app>
env:
- name: ES_HOST
value: "vpc-some-name-dev-wrfkk5v7kidaro67ozjrv4wdeq.us-west-2.es.amazonaws.com"
- name: ES_PORT
value: "443"
- name: DATALOADER_QUEUE
valueFrom:
configMapKeyRef:
name: <some_name>
key: DATALOADER_QUEUE
- name: AWS_DEFAULT_REGION
value: "us-west-2"
- name: AWS_ACCESS_KEY_ID
valueFrom:
secretKeyRef:
name: <some_name>
key: AWS_ACCESS_KEY_ID
- name: AWS_SECRET_ACCESS_KEY
valueFrom:
secretKeyRef:
name: <some_name>
key: AWS_SECRET_ACCESS_KEY
...
Currently, this file is in dev/deployment.yaml
but I also want a prod/deployment.yaml
. Instead of copying this whole file over, is there a better way to DRY up this file so it can be used for both dev and prod clusters? The parts of this file that differ are some of the environment variables (I used a different DATALOADER_QUEUE
variable for prod and dev, and the AWS keys. What can be done?
I looked into some options like a configmap. How does one do this? What's a mounted volume? I'm reading this: https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#add-configmap-data-to-a-volume
but I'm not sure what it is.... what is a volume? How do I access the data stored in this "volume"?
Can the image be switched from prod to dev? I know that seems odd...
Something like this would help with the env vars:
envFrom:
- configMapRef:
name: myapp-config
- secretRef:
name: myapp-secrets
You can then use different namespaces for dev vs. prod so the references don't have to vary. For handling labels, look at Kustomize overlays and setting labels at the overlay level.