---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: apm
  namespace: edoc2
  labels:
    app: apm
    k8s-app: apm
spec:
  replicas: 1
  revisionHistoryLimit: 5
  selector:
    matchLabels:
      app: apm
  template:
    metadata:
      labels:
        app: apm
    spec:
      hostname: apm
      terminationGracePeriodSeconds: 30
      containers:
      - name: apm
        #image: 192.168.251.78/edoc2v5/apm:v6.5-20230828160958
        image: 192.168.251.78/edoc2v5/apm:v6.5-20230831140130
        imagePullPolicy: IfNotPresent
        # envFrom:
        # - configMapRef:
        #     name: envfile
        env:
        - name: ESURL
          value: "http://es:9200"
        - name: ELASTICSEARCH_HOSTS
          value: "es"
        - name: APM_ESURL
          value: "http://es:9200"
        - name: ELASTICSEARCH_PORT
          value: "9200"
        - name: ECM_ESURL
          value: "http://es:9200"
        - name: MiddlewareIsCluster
          value: "0"
        - name: SwarmOrKube
          value: "Kube"
        - name: ServerApiUrl
          value: "https://192.168.11.185:6443/api/v1"
        - name: SUBREGION
          value: "true"
        #- name: LOGGER_ISDEBUG
        #  value: "true"
        # - name: DatabaseType
        #   value: "1"
        # - name: DatabaseServerName
        #   value: "sqlserver"
        # - name: DatabaseServerPort
        #   value: "1433"
        command: [ "/bin/bash", "-ce", "/root/entrypoint.sh" ]
        volumeMounts:
        #- name: apm-kube-config
        #  mountPath: /app/.kube/config
        #  subPath: config
        - name: apm-heartbeat-cnf
          mountPath: /usr/share/heartbeat/config/heartbeat.yml
          subPath: heartbeat.yml
        - name: apm-heartbeat-fields
          mountPath: /usr/share/heartbeat/bin/fields.yml
          subPath: fields.yml
        - name: apm-entrypoint-sh
          mountPath: /root/entrypoint.sh
          subPath: entrypoint.sh
        - name: apm-metricbeat-cnf
          mountPath: /usr/share/metricbeat/config/metricbeat.yml
          subPath: metricbeat.yml
        - name: apm-metricbeat-fields
          mountPath: /usr/share/metricbeat/bin/fields.yml
          subPath: fields.yml
        resources:
          requests:
            cpu: 1000m
            memory: 1Gi
          limits:
            cpu: 2000m
            memory: 8Gi
      restartPolicy: Always
      volumes:
        - name: apm-heartbeat-cnf
          configMap:
            name: apm-heartbeat-cnf
            items:
              - key: apm-heartbeat.yml
                path: heartbeat.yml
        - name: apm-heartbeat-fields
          configMap:
            name: apm-heartbeat-fields
            items:
              - key: apm-heartbeat-fields.yml
                path: fields.yml
        - name: apm-entrypoint-sh
          configMap:
            defaultMode: 493
            name: apm-entrypoint-sh
            items:
              - key: apm-entrypoint.sh
                path: entrypoint.sh
        - name: apm-metricbeat-cnf
          configMap:
            name: apm-metricbeat-cnf
            items:
              - key: apm-metricbeat.yml
                path: metricbeat.yml
        - name: apm-metricbeat-fields
          configMap:
            name: apm-metricbeat-fields
            items:
              - key: apm-metricbeat-fields.yml
                path: fields.yml
      nodeSelector:
        node.apm.labels: apm-node01

---
apiVersion: v1
kind: Service
metadata:
  name: apm
  namespace: edoc2
  labels:
    app: apm
spec:
  ports:
  - name: apm
    port: 80
    targetPort: 80
    #nodePort: 36180
    protocol: TCP
  #- name: sqlapm
  #  port: 3306
  #  targetPort: 3306
  #  nodePort: 32116
  #  protocol: TCP
  selector:
    app: apm
  #sessionAffinity: ClientIP
  #sessionAffinityConfig:
  #  clientIP:
  #    timeoutSeconds: 5
  type: ClusterIP
  #type: NodePort
