apiVersion: apps/v1
kind: Deployment
metadata:
  name: smg
  namespace: smg
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: smg
  template:
    metadata:
      labels:
        app: smg
    spec:
      containers:
        # The SMG container
        - name: smg
          image: "gcr.io/asen-smg/smulegrapher:latest"
          ports:
            - containerPort: 9000
            - containerPort: 9001
          volumeMounts:
            - name: smg-config-volume
              mountPath: /etc/smg/conf.d
            - name: smg-kube-config-volume
              mountPath: /etc/smg/kube-clusters.d
            - name: smg-data-volume
              mountPath: /opt/smg/data
            - name: rrdcached-sock-volume
              mountPath: /var/rrdtool/rrdcached
            - name: smg-sa-token-volume
              mountPath: /etc/smg/kube-token
            - name: smg-images-volume
              mountPath: /opt/smg/inst/smg/public/smg
        # a rrdcached container (same image but runs rrdcached)
        - name: rrdcached
          image: "gcr.io/asen-smg/smulegrapher:latest"
          command: [ "/run-rrdcached.sh" ]
          volumeMounts:
            - name: smg-data-volume
              mountPath: /opt/smg/data
            - name: rrdcached-sock-volume
              mountPath: /var/rrdtool/rrdcached
        # an nginx container to relieve SMG from serving images
        - name: nginx
          image: "gcr.io/asen-smg/smulegrapher:latest"
          command: [ "/run-nginx.sh" ]
          ports:
            - containerPort: 9080
              name: nginx
          volumeMounts:
            - name: smg-images-volume
              mountPath: /usr/share/nginx/html/smgimages
        # one more container to watch for changes in conf.d and kube-clusters.d and reload config
        - name: watch
          image: "gcr.io/asen-smg/smulegrapher:latest"
          command: [ "/run-inotify-reload.sh" ]
          env:
            - name: SMG_DIRS_TO_WATCH
              value: "/etc/smg/conf.d /etc/smg/kube-clusters.d"
          volumeMounts:
            - name: smg-config-volume
              mountPath: /etc/smg/conf.d
            - name: smg-kube-config-volume
              mountPath: /etc/smg/kube-clusters.d
      volumes:
        - name: smg-config-volume
          configMap:
            name: smg-configmap
        - name: smg-kube-config-volume
          configMap:
            name: smg-kube-configmap
        - name: smg-data-volume
          persistentVolumeClaim:
            claimName: smg-data-vol1-claim
        - name: rrdcached-sock-volume
          emptyDir: {}
        - name: smg-sa-token-volume
          secret:
            secretName: smg-sa-token
        # a shared between nginx and SMG dir, so that nginx can serve images
        - name: smg-images-volume
          emptyDir: {}
      # nodeSelector:
      #   useLabelToPintToNode: havingTheVolumes
