---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: netbox
spec:
  replicas: 1
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
  selector:
    matchLabels:
      component: netbox
  template:
    metadata:
      labels:
        component: netbox
    spec:
      containers:
        - name: netbox
          image: netbox
          readinessProbe:
            httpGet:
              path: /
              port: http
            initialDelaySeconds: 5
            periodSeconds: 5
          ports:
            - name: http
              containerPort: 80
          envFrom:
            - configMapRef:
                name: netbox-config
          env:
            - name: DB_USER
              valueFrom:
                secretKeyRef:
                  name: netbox.acid-main-cluster.credentials
                  key: username

          volumeMounts:
            - name: postgres-auth
              mountPath: /run/secrets/db_password
              subPath: password

            - name: django-secrets
              mountPath: /run/secrets/secret_key
              subPath: DJANGO_SECRET_KEY

            - name: datadir
              mountPath: /etc/netbox/media
              subPath: media
            - name: datadir
              mountPath: /etc/netbox/scripts
              subPath: scripts
            - name: datadir
              mountPath: /etc/netbox/reports
              subPath: reports
            - name: static-files
              mountPath: /opt/netbox/netbox/static

        # nginx sidecar container used to serve static files
        - name: nginx
          image: nginx:1.21.3-alpine
          volumeMounts:
            - name: static-files
              mountPath: /opt/netbox/netbox/static
            - name: nginx-config
              subPath: nginx.conf
              mountPath: /etc/nginx/nginx.conf

      volumes:
        - name: datadir
          persistentVolumeClaim:
            claimName: netbox-datadir
        - name: static-files
          emptyDir: {}

        - name: postgres-auth
          secret:
            secretName: netbox.acid-main-cluster.credentials
        - name: django-secrets
          secret:
            secretName: netbox-django-secrets

        - name: nginx-config
          configMap:
            name: nginx-config

