apiVersion: apps/v1
kind: Deployment
metadata:
  name: ldap
  labels:
    app: ldap
spec:
  replicas: 1
  selector:
    matchLabels:
      app: ldap
  template:
    metadata:
      labels:
        app: ldap
    spec:            
      containers:
        - name: ldap
          image: osixia/openldap:1.3.0
          volumeMounts:
            - name: ldap-certs
              mountPath: /container/service/slapd/assets/certs
            - name: ldif-config
              mountPath: >-
                /container/service/slapd/assets/config/bootstrap/ldif/custom/database.ldif
              subPath: database.ldif
          ports:
            - containerPort: 389
              name: openldap
          args:
            - '--copy-service'   
            - '--loglevel'
            - 'debug'
          env:
            - name: LDAP_LOG_LEVEL
              # value: "256"
              value: "256"
            - name: LDAP_ORGANISATION
              value: "Example Inc."
            - name: LDAP_DOMAIN
              value: "example.com"
            - name: LDAP_ADMIN_PASSWORD
              value: "admin"
            - name: LDAP_CONFIG_PASSWORD
              value: "config"
            - name: LDAP_READONLY_USER
              value: "false"
            - name: LDAP_READONLY_USER_USERNAME
              value: "readonly"
            - name: LDAP_READONLY_USER_PASSWORD
              value: "readonly"
            - name: LDAP_RFC2307BIS_SCHEMA
              value: "false"
            - name: LDAP_BACKEND
              value: "mdb"
            - name: LDAP_TLS
              value: "false"
            - name: LDAP_TLS_CRT_FILENAME
              value: "ldap.crt"
            - name: LDAP_TLS_KEY_FILENAME
              value: "ldap.key"
            - name: LDAP_TLS_DH_PARAM_FILENAME
              value: "dhparam.pem"
            - name: LDAP_TLS_CA_CRT_FILENAME
              value: "ca.crt"
            - name: LDAP_TLS_ENFORCE
              value: "false"
            - name: LDAP_TLS_CIPHER_SUITE
              value: "SECURE256:+SECURE128:-VERS-TLS-ALL:+VERS-TLS1.2:-RSA:-DHE-DSS:-CAMELLIA-128-CBC:-CAMELLIA-256-CBC"
            - name: LDAP_TLS_VERIFY_CLIENT
              value: "demand"
            - name: LDAP_REPLICATION
              value: "false"
            - name: LDAP_REPLICATION_CONFIG_SYNCPROV
              value: "binddn=\"cn=admin,cn=config\" bindmethod=simple credentials=$LDAP_CONFIG_PASSWORD searchbase=\"cn=config\" type=refreshAndPersist retry=\"60 +\" timeout=1 starttls=critical"
            - name: LDAP_REPLICATION_DB_SYNCPROV
              value: "binddn=\"cn=admin,$LDAP_BASE_DN\" bindmethod=simple credentials=$LDAP_ADMIN_PASSWORD searchbase=\"$LDAP_BASE_DN\" type=refreshAndPersist interval=00:00:00:10 retry=\"60 +\" timeout=1 starttls=critical"
            - name: LDAP_REPLICATION_HOSTS
              value: "#PYTHON2BASH:['ldap://ldap-one-service', 'ldap://ldap-two-service']"
            - name: KEEP_EXISTING_CONFIG
              value: "false"
            - name: LDAP_REMOVE_CONFIG_AFTER_SETUP
              value: "false"
            - name: LDAP_SSL_HELPER_PREFIX
              value: "ldap"
          resources:
            requests:
              memory: "64Mi"
              cpu: "150m"
            limits:
              memory: "128Mi"
              cpu: "200m"
        - name: phpldapadmin
          image: osixia/phpldapadmin:0.9.0
          resources:
            requests:
              memory: "64Mi"
              cpu: "150m"
            limits:
              memory: "128Mi"
              cpu: "200m"
          volumeMounts:
            - name: phpldapadmin-certs
              mountPath: /container/service/phpldapadmin/assets/apache2/certs
            - name: ldap-certs
              mountPath: /container/service/ldap-client/assets/certs
          ports:
            - containerPort: 443
          env:
            - name: PHPLDAPADMIN_LDAP_HOSTS
              value: "#PYTHON2BASH:[{'localhost': [{'server': [{'tls': 'false'}]}]}]"
            - name: PHPLDAPADMIN_SERVER_ADMIN
              value: "webmaster@example.org"
            - name: PHPLDAPADMIN_SERVER_PATH
              value: "/phpldapadmin"
            - name: PHPLDAPADMIN_HTTPS
              value: "true"
            - name: PHPLDAPADMIN_HTTPS_CRT_FILENAME
              value: "cert.crt"
            - name: PHPLDAPADMIN_HTTPS_KEY_FILENAME
              value: "cert.key"
            - name: PHPLDAPADMIN_HTTPS_CA_CRT_FILENAME
              value: "ca.crt"
            - name: PHPLDAPADMIN_LDAP_CLIENT_TLS
              value: "false"
            - name: PHPLDAPADMIN_LDAP_CLIENT_TLS_REQCERT
              value: "never"
            - name: PHPLDAPADMIN_LDAP_CLIENT_TLS_CRT_FILENAME
              value: "cert.crt"
            - name: PHPLDAPADMIN_LDAP_CLIENT_TLS_KEY_FILENAME
              value: "cert.key"
            - name: PHPLDAPADMIN_LDAP_CLIENT_TLS_CA_CRT_FILENAME
              value: "ca.crt"              
      volumes:
        - name: ldap-certs
          emptyDir: {}
        - name: phpldapadmin-certs
          emptyDir: {}         
        - name: ldif-config
          configMap:
            name: ldif-config                