---
apiVersion: v1
kind: Service
metadata:
  name: mysql
  namespace: edoc2
  labels:
    app: mysql
spec:
  ports:
  - name: mysql
    port: 3306
    targetPort: 3306
    nodePort: 33306
    protocol: TCP
  selector:
    app: mysql
  #type: ClusterIP
  type: NodePort
---
apiVersion: v1
kind: Service
metadata:
  name: middle-proxy
  namespace: edoc2
  labels:
    app: mysql
spec:
  ports:
  - name: middle-proxy
    port: 3306
    targetPort: 3306
    protocol: TCP
  selector:
    app: mysql
  type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment 
#kind: StatefulSet
metadata:
  labels:
    app: mysql
    k8s-app: mysql
  name: mysql
  namespace: edoc2
spec:
  replicas: 3
  revisionHistoryLimit: 5
  #serviceName: middleware-proxy
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      hostname: mysql
      terminationGracePeriodSeconds: 5
      initContainers:
      - name: increase-vm-max-map
        image: registry.edoc2.com:5000/library/busybox:1.28
        command: ["sysctl", "-w", "vm.max_map_count=655360"]
        securityContext:
          privileged: true
      - name: increase-file-max-map
        image: registry.edoc2.com:5000/library/busybox:1.28
        command: ["sysctl", "-w", "fs.file-max=655360"]
        securityContext:
          privileged: true
      - name: increase-somaxconn-map
        image: registry.edoc2.com:5000/library/busybox:1.28
        command: ["sysctl", "-w", "net.core.somaxconn=28096"]
        securityContext:
          privileged: true
      - name: increase-fd-ulimit
        image: registry.edoc2.com:5000/library/busybox:1.28
        command: ["sh", "-c", "ulimit -n 655360"]
        securityContext:
          privileged: true
      containers:
      - name: proxy-container
        image: registry.edoc2.com:5000/edoc2v5/haproxy:pod6600-v2.7.10.61
        imagePullPolicy: IfNotPresent
        env:
        - name: MYSQL_REPL_USER
          valueFrom:
            secretKeyRef:
              name: haproxy-secret
              key: MYSQL_REPL_USER
        - name: MYSQL_REPL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: haproxy-secret
              key: MYSQL_REPL_PASSWORD
        - name: CONTAINER_PLATFORM
          value: "kubernetes"
        - name: NAMESPACE
          valueFrom:
            fieldRef:
              fieldPath: metadata.namespace
        livenessProbe:
          exec:
            command: ["bash","/opt/check.sh"]
          periodSeconds: 20
          timeoutSeconds: 30         # 检测时间间隔
          failureThreshold: 5
          successThreshold: 1
        #- name: HAPROXY_ROOT_PASSWORD
        #  value: "1qaz2WSX"
        #- name: HAPROXY_REPL_USER
        #  value: "repl"
        #- name: HAPROXY_REPL_PASSWORD
        #  value: "Xjb0^DDy"
      #volumes:
      #- name: config-map
      #    configMap:
      #      name: middle-haproxy-cnf
      restartPolicy: Always
      nodeSelector:
        "node.labels.nodelabels": Middleware
        #"node.drive.nodelabels":InDrive
