|
| 1 | +# Redis Connect for MSSQL in K8s |
| 2 | + |
| 3 | +This repository describes the steps involved to deploy Redis Connect for MSSQL in K8s. |
| 4 | + |
| 5 | +Overall flow: |
| 6 | +1. Clone the Redis Connect for MSSQL repository. |
| 7 | +2. Configure Redis Connect as in <a href="../demo/config/samples/sqlserver" target="_blank">this set of docs</a>. |
| 8 | +3. Deploy the Redis Connect configuration to Kubernetes. |
| 9 | +4. Configure the Redis Connect deployment manifests. |
| 10 | +5. Stage the Redis Connect job. |
| 11 | +6. Start the Redis Connect job. |
| 12 | + |
| 13 | +**Note:** This doc uses `kubectl` and `oc` interchangeably. |
| 14 | + |
| 15 | +## 1. Clone the Redis Connect for MSSQL Repository |
| 16 | + |
| 17 | +Follow the [demo](../demo) steps then goto k8s-docs directory |
| 18 | +``` |
| 19 | +redis-connect-sqlserver$ cd k8s-docs |
| 20 | +``` |
| 21 | + |
| 22 | +## 2. Configure Redis Connect |
| 23 | + |
| 24 | +Configure the files to describe your Redis Connect Job. One sample configuration is <a href="../demo/config/samples/sqlserver" target="_blank">here</a>. |
| 25 | + |
| 26 | +Redis Connect is a Java application which is a client of both the source RDBMS and the target Redis. As such, you will need: |
| 27 | +* Source database details (endpoint, port, credentials) |
| 28 | + * <a href="../" target="_blank">CDC and replication configuration</a> completed on the source database system |
| 29 | +* Source schema details |
| 30 | +* Target Redis details and instances (one for the data, one for the Job configuration) |
| 31 | + |
| 32 | +Details for configuring Redis Connect for MSSQL are <a href="../demo/" target="_blank">here</a>. |
| 33 | + |
| 34 | +## 3. Deploy the Redis Connect Configuration to Kubernetes |
| 35 | + |
| 36 | +This deployment requires the use of K8s ConfigMaps. The necessary config maps will be uploaded from your local directories using the commands below. |
| 37 | + |
| 38 | +``` |
| 39 | +$ cd ../demo/config/samples/sqlserver |
| 40 | +demo/config/samples/sqlserver$ ls |
| 41 | +FormatterConfig.yml JobManager.yml env.yml templates/ |
| 42 | +JobConfig.yml Setup.yml mappers/ |
| 43 | +``` |
| 44 | + |
| 45 | +Here is an example of creating the ConfigMap. This command should be *run from the directory containing your config files*. |
| 46 | +``` |
| 47 | +kubectl create configmap redis-connect-sqlserver-config \ |
| 48 | + --from-file=JobConfig.yml=JobConfig.yml \ |
| 49 | + --from-file=JobManager.yml=JobManager.yml \ |
| 50 | + --from-file=env.yml=env.yml \ |
| 51 | + --from-file=Setup.yml=Setup.yml \ |
| 52 | + --from-file=mapper1.yml=mappers/mapper1.yml |
| 53 | +``` |
| 54 | +The outcome is: |
| 55 | +``` |
| 56 | +$ oc get configmap/redis-connect-sqlserver-config |
| 57 | +NAME DATA AGE |
| 58 | +redis-connect-sqlserver-config 5 5s |
| 59 | +``` |
| 60 | + |
| 61 | +If you need to add a custom stage jar file then you can append that to the ConfigMap creation as follows: |
| 62 | +``` |
| 63 | +kubectl create configmap redis-connect-sqlserver-config \ |
| 64 | + --from-file=JobConfig.yml=JobConfig.yml \ |
| 65 | + --from-file=JobManager.yml=JobManager.yml \ |
| 66 | + --from-file=env.yml=env.yml \ |
| 67 | + --from-file=Setup.yml=Setup.yml \ |
| 68 | + --from-file=mapper1.yml=mappers/mapper1.yml \ |
| 69 | + --from-file=redis-connect-custom-stage-demo-1.0-SNAPSHOT.jar=redis-connect-custom-stage-demo-1.0-SNAPSHOT.jar |
| 70 | +``` |
| 71 | +The outcome is: |
| 72 | +``` |
| 73 | +$ oc get configmap/redis-connect-sqlserver-config |
| 74 | +NAME DATA AGE |
| 75 | +redis-connect-sqlserver-config 6 12s |
| 76 | +``` |
| 77 | + |
| 78 | +If the ConfigMap did not get created, it's likely that one of more of the source configuration files was not found (eg. JobConfig.yml) so please verify the path to your files. |
| 79 | + |
| 80 | +The details of the the command above are: |
| 81 | +`kubectl create configmap <configmap_name> --from-file=<key_name>=<path-to/file_name>` |
| 82 | + |
| 83 | +**Note:** ConfigMaps are immutable so if you are making changes to an existing configuration, you need to delete the existing configuration first. |
| 84 | + |
| 85 | +### How Does the ConfigMap get used? |
| 86 | + |
| 87 | +The values of keys in the ConfigMap will be mounted directly to the pod's filesystem. |
| 88 | + |
| 89 | +The following volume mount is defined in the manifests. The a will mount the resource `config-volume` to that `mountPath`. |
| 90 | +``` |
| 91 | + volumeMounts: |
| 92 | + - name: config-volume |
| 93 | + mountPath: /opt/redislabs/redis-connect-sqlserver/config/fromconfigmap |
| 94 | +``` |
| 95 | +The volume is defined through the following `volume` directive. It will mount the file/pth `JobConfig.yml` using the contents of the key named `JobConfig.yml` from the ConfigMap `redis-connect-sqlserver-config` in the `mountPath` define above. |
| 96 | +``` |
| 97 | + volumes: |
| 98 | + - name: config-volume |
| 99 | + configMap: |
| 100 | + name: redis-connect-sqlserver-config |
| 101 | + items: |
| 102 | + - key: JobConfig.yml |
| 103 | + path: JobConfig.yml |
| 104 | +``` |
| 105 | +The effect of this mapping in the pod's filesystem is the following: |
| 106 | +``` |
| 107 | +root@redis-connect-sqlserver-7b7ccf87b9-sqshl> pwd |
| 108 | +/opt/redislabs/redis-connect-sqlserver/config/fromconfigmap |
| 109 | +root@redis-connect-sqlserver-7b7ccf87b9-sqshl> ls -al |
| 110 | +total 0 |
| 111 | +drwxrwxrwx 3 root root 149 Aug 12 15:52 . |
| 112 | +drwxr-xr-x 1 root root 27 Aug 12 15:52 .. |
| 113 | +drwxr-xr-x 3 root root 96 Aug 12 15:52 ..2021_08_12_15_52_06.258096011 |
| 114 | +lrwxrwxrwx 1 root root 31 Aug 12 15:52 ..data -> ..2021_08_12_15_52_06.258096011 |
| 115 | +lrwxrwxrwx 1 root root 20 Aug 12 15:52 JobConfig.yml -> ..data/JobConfig.yml |
| 116 | +lrwxrwxrwx 1 root root 21 Aug 12 15:52 JobManager.yml -> ..data/JobManager.yml |
| 117 | +lrwxrwxrwx 1 root root 16 Aug 12 15:52 Setup.yml -> ..data/Setup.yml |
| 118 | +lrwxrwxrwx 1 root root 14 Aug 12 15:52 env.yml -> ..data/env.yml |
| 119 | +lrwxrwxrwx 1 root root 14 Aug 12 15:52 mappers -> ..data/mappers |
| 120 | +``` |
| 121 | +The final link is the environment variable that instructs Redis Connect to use these mapped files: |
| 122 | +``` |
| 123 | + env: |
| 124 | + - name: REDISCONNECT_CONFIG |
| 125 | + value: "/opt/redislabs/redis-connect-sqlserver/config/fromconfigmap" |
| 126 | +``` |
| 127 | + |
| 128 | +## 4. Configure the Redis Connect Deployment Manifests |
| 129 | + |
| 130 | +Update both the `redis-connect-sqlserver-stage.yaml` and `redis-connect-sqlserver-start.yaml` to map the appropriate environment variables in the `env:` section. Notable, the `REDISCONNECT_SOURCE_USERNAME`, `REDISCONNECT_SOURCE_PASSWORD`, `REDISCONNECT_TARGET_USERNAME` and `REDISCONNECT_TARGET_PASSWORD`. |
| 131 | + |
| 132 | +Examples are provided to populate environment variables from the manifest/yaml, from configmap, and from k8s secrets for sensitive info such as credentials: |
| 133 | + |
| 134 | +``` |
| 135 | + - name: REDISCONNECT_SOURCE_PASSWORD |
| 136 | + value: admin123 |
| 137 | + # valueFrom: |
| 138 | + # configMapKeyRef: |
| 139 | + # key: REDISCONNECT_SOURCE_PASSWORD |
| 140 | + # name: redis-connect-sqlserver-config |
| 141 | + # valueFrom: |
| 142 | + # secretKeyRef: |
| 143 | + # key: password |
| 144 | + # name: redis-connect-secret |
| 145 | +``` |
| 146 | + |
| 147 | +## 5. Stage the Redis Connect Job |
| 148 | + |
| 149 | +Apply the stage manifest as follows: `oc apply -f redis-connect-sqlserver-stage.yaml`. The outcome will be a k8s batch/Job which will run once and exit. |
| 150 | +``` |
| 151 | +$ oc get po -w |
| 152 | +NAME READY STATUS RESTARTS AGE |
| 153 | +redis-connect-sqlserver-stage-lkvp2 0/1 Completed 0 44s |
| 154 | +``` |
| 155 | + |
| 156 | +The effect of this stage operation is the configuration keys are loaded in to the target Redis instance defined in `env.yml`:`jobConfigConnection`. The Job should have an `UNASSIGNED` owner. |
| 157 | + |
| 158 | +## 6. Start the Redis Connect Job |
| 159 | + |
| 160 | +Apply the stage manifest as follows: `oc apply -f redis-connect-sqlserver-start.yaml`. The outcome will be a k8s apps/Deployment which will run continually. |
| 161 | +``` |
| 162 | +$ oc get po -w |
| 163 | +NAME READY STATUS RESTARTS AGE |
| 164 | +redis-connect-sqlserver-cbc7dcd9d-k9mxj 1/1 Running 0 4s |
| 165 | +redis-connect-sqlserver-stage-lkvp2 0/1 Completed 0 3m10s |
| 166 | +``` |
| 167 | + |
| 168 | +The effect of the above is that the Redis Connect job has started. The Job Owner should be specified in the in `env.yml`:`jobConfigConnection` Redis DB as `JC-xx@redis-connect-sqlserver-cbc7dcd9d-k9mxj` indicating that the pod created is the Redis Connect job owner. You should see your changes propagate to the `targetConnection` Redis database as defined in `env.yml`. |
| 169 | + |
| 170 | +--- |
| 171 | +### Troubleshooting Options |
| 172 | + |
| 173 | +1. Tail the pod logs. `oc logs -f pod/redis-connect-sqlserver-cbc7dcd9d-k9mxj` |
| 174 | +2. Start the pods in interactive mode. |
| 175 | + * Launch the pods in a do/while loop instead of the redisconnect.sh start command: |
| 176 | + ``` |
| 177 | + #### uncomment the following two lines while you are setting up your |
| 178 | + command: [ "/bin/bash", "-c", "--" ] |
| 179 | + args: [ "while true; do sleep 30; done;" ] |
| 180 | + #### |
| 181 | + # comment out the default starting point |
| 182 | + # command: ["/opt/redislabs/redis-connect-sqlserver/bin/redisconnect.sh", "start"] |
| 183 | + ``` |
| 184 | + * Now you can leverage the `bin/redisconnect.sh` enterpoint interactively to: |
| 185 | + * Test source and target connections |
| 186 | + * Run Redis Connect interactively to test a configuration |
| 187 | +3. Enable more verbose logging. |
| 188 | + * Adjust and add `logback.xml` to your ConfigMap |
| 189 | + * Add to the `volumeMounts` and `volumes` to leverage the map the `logback.xml` file. |
| 190 | + * Point to the file in the `REDISCONNECT_LOGBACK_CONFIG` environment variable. |
| 191 | +
|
0 commit comments