---
kind: Deployment
apiVersion: apps/v1
metadata:
  labels:
    app: ceph
    daemon: mon
  name: ceph-mon
  namespace: ceph
spec:
  replicas: 3
  selector:
    matchLabels:
      app: ceph
      daemon: mon
  template:
    metadata:
      name: ceph-mon
      namespace: ceph
      labels:
        app: ceph
        daemon: mon
    spec:
      serviceAccount: default
      tolerations:
        - key: CriticalAddonsOnly
          operator: Exists
        - key: node-role.kubernetes.io/master
          operator: Exists
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
          - labelSelector:
              matchExpressions:
              - key: app
                operator: In
                values: ["ceph"]
              - key: daemon
                operator: In
                values: ["mon"]
            topologyKey: kubernetes.io/hostname
      volumes:
        - name: ceph-conf
          secret:
            secretName: ceph-conf-combined
        - name: ceph-bootstrap-osd-keyring
          secret:
            secretName: ceph-bootstrap-osd-keyring
        - name: ceph-bootstrap-mds-keyring
          secret:
            secretName: ceph-bootstrap-mds-keyring
        - name: ceph-bootstrap-rgw-keyring
          secret:
            secretName: ceph-bootstrap-rgw-keyring
        - name: ceph-bootstrap-rbd-keyring
          secret:
            secretName: ceph-bootstrap-rbd-keyring
      containers:
        - name: ceph-mon
          #image: slpcat/ceph-daemon:mimic
          image: slpcat/ceph-daemon:v3.1.0-mimic-centos7
          #imagePullPolicy: Always
          lifecycle:
            preStop:
                exec:
                  # remove the mon on Pod stop.
                  command:
                    - "/remove-mon.sh"
            postStart:
              exec:
                command:
                  - "sh"
                  - "-c"
                  - cp /tmp/ceph/* /etc/ceph/
          ports:
            - containerPort: 6789
          env:
            - name: CEPH_DAEMON
              value: MON
            - name: KV_TYPE
              value: k8s
            #NETWORK_AUTO_DETECT can't work with calico to get CEPH_PUBLIC_NETWORK
            - name: NETWORK_AUTO_DETECT
              value: "0"
            - name: CLUSTER
              value: ceph
            - name: CEPH_PUBLIC_NETWORK
              value: 10.233.0.0/16
            - name: MON_IP
              valueFrom:
                fieldRef:
                  fieldPath: status.podIP
          volumeMounts:
            - name: ceph-conf
              mountPath: /tmp/ceph
            - name: ceph-bootstrap-osd-keyring
              mountPath: /var/lib/ceph/bootstrap-osd
            - name: ceph-bootstrap-mds-keyring
              mountPath: /var/lib/ceph/bootstrap-mds
            - name: ceph-bootstrap-rgw-keyring
              mountPath: /var/lib/ceph/bootstrap-rgw
            - name: ceph-bootstrap-rbd-keyring
              mountPath: /var/lib/ceph/bootstrap-rbd
          livenessProbe:
              tcpSocket:
                port: 6789
              initialDelaySeconds: 60
              timeoutSeconds: 5
          readinessProbe:
              tcpSocket:
                port: 6789
              timeoutSeconds: 5
          resources:
            requests:
              memory: "50Mi"
              cpu: "1000m"
            limits:
              memory: "100Mi"
              cpu: "2000m"
