Kubernetes deployment mycat1.6

  1. write mycat-configmap

kind: ConfigMap
apiVersion: v1
metadata:
  name: mycat-config
  namespace: default
data:
  rule.xml: |
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mycat:rule SYSTEM "rule.dtd">
    <mycat:rule xmlns:mycat="http://io.mycat/">
    </mycat:rule>
  schema.xml: |
    <?xml version="1.0"?>
    <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
    <mycat:schema xmlns:mycat="http://io.mycat/">
        <schema name="database" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1">
        </schema>
        <dataNode name="dn1" dataHost="host1" database="database"/>
        <dataHost name="host1" maxCon="1000" minCon="10" balance="0" dbDriver="native" dbType="mysql" slaveThreshold="100\ ">
            <heartbeat>select user()</heartbeat>
                <writeHost host="host1" url="mysql:3306" user="usermame" password="password">
                <readHost host="host1" url="mysql:3306" user="usermame" password="password" />
                </writeHost>
        </dataHost>
    </mycat:schema>
  server.xml: |
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE mycat:server SYSTEM "server.dtd">
    <mycat:server xmlns:mycat="http://io.mycat/">
            <system>
            <property name="useHandshakeV10">1</property>
        <property name="removeGraveAccent">1</property>
            <property name="useSqlStat">0</property> <!-- 1 is to enable real-time statistics, 0 is to disable -->
            <property name="useGlobleTableCheck">0</property> <!-- 1 is to enable full overtime consistency detection, 0 is to disable -->
            <property name="sqlExecuteTimeout">3000</property> <!-- SQL execution timeout unit: second -->
                    <property name="sequenceHandlerType">1</property>
            <property name="sequnceHandlerPattern">(?:(\s*next\s + value\s + for\s*MYCATSEQ_(\w + ))(,|\)|\ s)*) + </property>
            <property name="sequenceHanlderClass">io.mycat.route.sequence.handler.HttpIncrSequenceHandler</property>
                    <property name="processorBufferPoolType">0</property>
                    <property name="handleDistributedTransactions">0</property>

                    <property name="useOffHeapForMerge">0</property>

            <property name="useHandshakeV10">1</property>
        <property name="removeGraveAccent">1</property>
            <property name="useSqlStat">0</property>
            <property name="useGlobleTableCheck">0</property> <!-- 1 is to enable full overtime consistency detection, 0 is to disable -->
            <property name="sqlExecuteTimeout">3000</property> <!-- SQL execution timeout unit: second -->
                    <property name="sequenceHandlerType">1</property>
            <property name="sequnceHandlerPattern">(?:(\s*next\s + value\s + for\s*MYCATSEQ_(\w + ))(,|\)|\ s)*) + </property>
            <property name="sequenceHanlderClass">io.mycat.route.sequence.handler.HttpIncrSequenceHandler</property>
                    <property name="processorBufferPoolType">0</property>
                    <property name="handleDistributedTransactions">0</property>

                    <property name="useOffHeapForMerge">0</property>

                    <!--
                                                 The unit is m
                    -->
            <property name="memoryPageSize">64k</property>

                    <!--
                                                 The unit is k
                    -->
                    <property name="spillsFileBufferSize">1k</property>

                    <property name="useStreamOutput">0</property>

                    <!--
                                                 The unit is m
                    -->
                    <property name="systemReserveMemorySize">384m</property>



                    <property name="strictTxIsolation">true</property>
                    <property name="parallExecute">0</property>
                    <property name="serverBacklog">2048</property>
            </system>


            <user name="usrname">
                    <property name="password">password</property>
                    <property name="schemas">databases</property>
            </user>

    </mycat:server>
  wrapper.conf: |
    #************************************************** *******************
    # Wrapper Properties
    #************************************************** *******************
    # Java Application
    wrapper.java.command=java
    wrapper.working.dir=..

    # Java Main class. This class must implement the WrapperListener interface
    # or guarantee that the WrapperManager class is initialized. Helper
    # classes are provided to do this for you. See the Integration section
    # of the documentation for details.
    wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
    set.default.REPO_DIR=lib
    set.APP_BASE=.

    # Java Classpath (include wrapper.jar) Add class path elements as
    # needed starting from 1
    wrapper.java.classpath.1=lib/wrapper.jar
    wrapper.java.classpath.2=conf
    wrapper.java.classpath.3=%REPO_DIR%/*

    # Java Library Path (location of Wrapper.DLL or libwrapper.so)
    wrapper.java.library.path.1=lib

    # Java Additional Parameters
    #wrapper.java.additional.1=
    wrapper.java.additional.1=-DMYCAT_HOME=.
    wrapper.java.additional.2=-server
    wrapper.java.additional.3=-XX:MaxPermSize=1024M
    wrapper.java.additional.4=-XX: + AggressiveOpts
    wrapper.java.additional.5=-XX:MaxDirectMemorySize=8G
    wrapper.java.additional.6=-Dcom.sun.management.jmxremote
    wrapper.java.additional.7=-Dcom.sun.management.jmxremote.port=1984
    wrapper.java.additional.8=-Dcom.sun.management.jmxremote.authenticate=false
    wrapper.java.additional.9=-Dcom.sun.management.jmxremote.ssl=false
    wrapper.java.additional.10=-Xmx4G
    wrapper.java.additional.11=-Xms1G

    # Initial Java Heap Size (in MB)
    # wrapper.java.initmemory=2048

    # Maximum Java Heap Size (in MB)
    # wrapper.java.maxmemory=10240

    # Application parameters. Add parameters as needed starting from 1
    wrapper.app.parameter.1=io.mycat.MycatStartup
    wrapper.app.parameter.2=start

    #************************************************** *******************
    # Wrapper Logging Properties
    #************************************************** *******************
    # Format of output for the console. (See docs for formats)
    wrapper.console.format=PM

    # Log Level for console output. (See docs for log levels)
    wrapper.console.loglevel=INFO

    # Log file to use for wrapper output logging.
    wrapper.logfile=logs/wrapper.log

    # Format of output for the log file. (See docs for formats)
    wrapper.logfile.format=LPTM

    # Log Level for log file output. (See docs for log levels)
    wrapper.logfile.loglevel=INFO

    # Maximum size that the log file will be allowed to grow to before
    # the log is rolled. Size is specified in bytes. The default value
    # of 0, disables log rolling. May abbreviate with the 'k' (kb) or
    # 'm' (mb) suffix. For example: 10m = 10 megabytes.
    wrapper.logfile.maxsize=0

    # Maximum number of rolled log files which will be allowed before old
    # files are deleted. The default value of 0 implies no limit.
    wrapper.logfile.maxfiles=0

    # Log Level for sys/event log output. (See docs for log levels)
    wrapper.syslog.loglevel=NONE

    #************************************************** *******************
    # Wrapper Windows Properties
    #************************************************** *******************
    # Title to use when running as a console
    wrapper.console.title=Mycat-server

    #************************************************** *******************
    # Wrapper Windows NT/2000/XP Service Properties
    #************************************************** *******************
    # WARNING - Do not modify any of these properties when an application
    # using this configuration file has been installed as a service.
    # Please uninstall the service before modifying this section. The
    # service can then be reinstalled.

    # Name of the service
    wrapper.ntservice.name=mycat

    # Display name of the service
    wrapper.ntservice.displayname=Mycat-server

    # Description of the service
    wrapper.ntservice.description=The project of Mycat-server

    # Service dependencies. Add dependencies as needed starting from 1
    wrapper.ntservice.dependency.1=

    # Mode in which the service is installed. AUTO_START or DEMAND_START
    wrapper.ntservice.starttype=AUTO_START

    # Allow the service to interact with the desktop.
    wrapper.ntservice.interactive=false

    wrapper.ping.timeout=120
    wrapper.startup.timeout=300
    configuration.directory.in.classpath.first=conf
  1. Write mycat-deployer.yaml

kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: mycat
  namespace: default
spec:
  serviceName: mycat
  replicas: 1
  selector:
    matchLabels:
      app: mycat
  template:
    metadata:
      labels:
        app: mycat
    spec:
      volumes:
        - name: configmap-mycat
          configMap:
            name: mycat-config
            items:
              - key: server.xml
                path: server.xml
              - key: schema.xml
                path: schema.xml
              - key: wrapper.conf
                path: wrapper.conf
              - key: rule.xml
                path: rule.xml
      containers:
        -name: mycat
          image: manondidi/mycat:1.6.7.5
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 8066
              protocol: TCP
              name: mycat
          resources:
            limits:
              memory: 3Gi
            requests:
              memory: 1Gi
          volumeMounts:
            - name: data
              mountPath: /usr/local/mycat/logs
            - name: configmap-mycat
              mountPath: /usr/local/mycat/conf/server.xml
              subPath: server.xml
            - name: configmap-mycat
              mountPath: usr/local/mycat/conf/schema.xml
              subPath: schema.xml
            - name: configmap-mycat
              mountPath: /usr/local/mycat/conf/rule.xml
              subPath: rule.xml
            - name: configmap-mycat
              mountPath: /usr/local/mycat/conf/wrapper.conf
              subPath: wrapper.conf
  volumeClaimTemplates:
  - metadata:
      name: data
    spec:
      accessModes:
      - ReadWriteOnce
      resources:
        requests:
          storage: 5Gi
  1. write mycat.service.yaml

apiVersion: v1
kind: Service
metadata:
  labels:
    app: mycat
  name: mycat
  namespace: default
spec:
  ports:
  -name: mycat
    port: 8066
  clusterIP: None
  selector:
    app: mycat
  1. verify

 mysql -h mycat.mysql -P8066 -uroot -p -e "show databases