Managing multiple Pods with one Deploy

1/15/2019

Good afternoon, I need help defining a structure of my production cluster, i want something like.

  • 1 Deployment that controlled the pods
  • multiple PODS (one pod per-customer)
  • multiple services (one service-per pod)

but how will I do this structure if for each POD I have env vars that will connect to the customer database, like that

env:
    - name: dbuser
      value: "svc_iafox_test@***"
    - name: dbpassword
      value: "****"
    - name: dbname
      value: "ts-demo1"
    - name: dbconnectstring
      value: "jdbc:sqlserver://***-test.database.windows.net:1433;database=$(dbname);user=$(dbuser);password=$(dbpassword);encrypt=true;trustServerCertificate=true;hostNameInCertificate=*.database.windows.net;loginTimeout=30;"

so for each pod I will have to change these env vars ... anyway, what is the best way for me to do this??

-- Bruno Luis
azure
azure-aks
azure-kubernetes
kubernetes

1 Answer

1/15/2019

you could use configmap to achieve that:

apiVersion: v1
kind: Pod
metadata:
  name: dapi-test-pod
spec:
  containers:
    - name: test-container
      image: k8s.gcr.io/busybox
      command: [ "/bin/sh", "-c", "echo $(SPECIAL_LEVEL_KEY) $(SPECIAL_TYPE_KEY)" ]
      env:
        - name: SPECIAL_LEVEL_KEY
          valueFrom:
            configMapKeyRef:
              name: special-config
              key: SPECIAL_LEVEL
        - name: SPECIAL_TYPE_KEY
          valueFrom:
            configMapKeyRef:
              name: special-config
              key: SPECIAL_TYPE
  restartPolicy: Never

https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#use-configmap-defined-environment-variables-in-pod-commands

ps. I dont think 1 deployment per pod makes sense. 1 deployment per customer does. I dont think you understand exactly what a deployment does: https://kubernetes.io/docs/concepts/workloads/controllers/deployment/

-- 4c74356b41
Source: StackOverflow