apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: dex
  name: dex
  namespace: dex
spec:
  replicas: 3
  selector:
    matchLabels:
      app: dex
  template:
    metadata:
      labels:
        app: dex
    spec:
      serviceAccountName: dex
      initContainers:
        - name: add-ca-cert
          image: ghcr.io/dexidp/dex:v2.30.0
          command: 
            - "sh"
          args: 
            - "-c"
            - "cp -r /etc/ssl/certs/* /certs; cat /etc/ssl/certs/ca-certificates.crt /ca-certs/ca.crt > /certs/ca-certificates.crt"
          volumeMounts:
            - name: "certs"
              mountPath: "/certs"
            - name: "ca-certs"
              mountPath: "/ca-certs"
      containers:
      - image: ghcr.io/dexidp/dex:v2.30.0
        name: dex
        command: ["/usr/local/bin/dex", "serve", "/etc/dex/cfg/config.yaml"]

        ports:
        - name: https
          containerPort: 5556

        volumeMounts:
        - name: config
          mountPath: /etc/dex/cfg
          readOnly: true
        - name: tls
          mountPath: /etc/dex/tls
        - name: certs
          mountPath: /etc/ssl/certs
        env:
        - name: GITHUB_CLIENT_ID
          valueFrom:
            secretKeyRef:
              name: github-client
              key: client-id
        - name: GITHUB_CLIENT_SECRET
          valueFrom:
            secretKeyRef:
              name: github-client
              key: client-secret

        readinessProbe:
          httpGet:
            path: /healthz
            port: 5556
            scheme: HTTPS
      volumes:
      - emptyDir: {}
        name: certs
      - name: ca-certs
        secret:
          secretName: trusted-ca
          items:
            - key: tls.crt
              path: ca.crt
      - name: config
        configMap:
          name: dex
          items:
          - key: config.yaml
            path: config.yaml
      - name: tls
        secret:
          secretName: dex-tls
