Skip to content

Commit 2db50e5

Browse files
committed
Updated mysql with k8's artifacts
1 parent f78387e commit 2db50e5

14 files changed

+534
-10
lines changed

connectors/db2/k8s-docs/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Redis Connect is a Java application which is a client of both the source RDBMS a
2929
* Source schema details
3030
* Target Redis details and instances (one for the data, one for the Job configuration)
3131

32-
Details for configurating Redis Connect for db2 are <a href="../demo/" target="_blank">here</a>.
32+
Details for configuring Redis Connect for db2 are <a href="../demo/" target="_blank">here</a>.
3333

3434
## 3. Deploy the Redis Connect Configuration to Kubernetes
3535

connectors/db2/k8s-docs/redis-connect-db2-stage.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ spec:
124124
# configMap:
125125
# name: redis-connect-db2-config
126126
# items: # define as many custom stages as you have here
127-
# - key: redis-connect-custom-stage-demo-1.0-SNAPSHOT.0.jar
128-
# path: redis-connect-custom-stage-demo-1.0-SNAPSHOT.0.jar
127+
# - key: redis-connect-custom-stage-demo-1.0-SNAPSHOT.jar
128+
# path: redis-connect-custom-stage-demo-1.0-SNAPSHOT.jar
129129
- name: tmpfsdir
130130
emptyDir: # node-ephemeral volume
131131
medium: Memory

connectors/db2/k8s-docs/redis-connect-db2-start.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ spec:
136136
# configMap:
137137
# name: redis-connect-db2-config
138138
# items: # define as many custom stages as you have here
139-
# - key: redis-connect-custom-stage-demo-1.0-SNAPSHOT.0.jar
140-
# path: redis-connect-custom-stage-demo-1.0-SNAPSHOT.0.jar
139+
# - key: redis-connect-custom-stage-demo-1.0-SNAPSHOT.jar
140+
# path: redis-connect-custom-stage-demo-1.0-SNAPSHOT.jar
141141
- name: tmpfsdir
142142
emptyDir: # node-ephemeral volume
143143
medium: Memory
Binary file not shown.
Binary file not shown.

connectors/mysql/demo/update_mysql.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
sudo docker cp update.sql mysql-5.7.33-$(hostname):update.sql
4+
sudo docker exec -it mysql-5.7.33-$(hostname) bash -c 'mysql -h"localhost" -P3306 -uroot -pRedis@123 < update.sql'
5+
echo ""

connectors/mysql/k8s-docs/README.md

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Redis Connect for MySQL in K8s
2+
3+
This repository describes the steps involved to deploy Redis Connect for MySQL in K8s.
4+
5+
Overall flow:
6+
1. Clone the Redis Connect for MySQL repository.
7+
2. Configure Redis Connect as in <a href="../demo/config/samples/mysql" 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` interchangably.
14+
15+
## 1. Clone the Redis Connect for MySQL Repository
16+
```
17+
$ git clone https://github.com/redis-field-engineering/redis-connect-dist.git
18+
...
19+
$ cd redis-connect-dist/connectors/mysql/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/mysql" 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">WAL 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 MySQL 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/mysql
40+
demo/config/samples/mysql$ 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-mysql-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-mysql-config
57+
NAME DATA AGE
58+
redis-connect-mysql-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-mysql-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.0.jar=redis-connect-custom-stage-demo-1.0-SNAPSHOT.0.jar
70+
```
71+
The outcome is:
72+
```
73+
$ oc get configmap/redis-connect-mysql-config
74+
NAME DATA AGE
75+
redis-connect-mysql-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-mysql/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-mysql-config` in the `mountPath` define above.
96+
```
97+
volumes:
98+
- name: config-volume
99+
configMap:
100+
name: redis-connect-mysql-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-mysql-7b7ccf87b9-sqshl> pwd
108+
/opt/redislabs/redis-connect-mysql/config/fromconfigmap
109+
root@redis-connect-mysql-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-mysql/config/fromconfigmap"
126+
```
127+
128+
## 4. Configure the Redis Connect Deployment Manifests
129+
130+
Update both the `redis-connect-mysql-stage.yaml` and `redis-connect-mysql-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-mysql-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-mysql-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-mysql-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-mysql-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-mysql-cbc7dcd9d-k9mxj 1/1 Running 0 4s
165+
redis-connect-mysql-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-mysql-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-mysql-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-mysql/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+
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
apiVersion: batch/v1
2+
kind: Job
3+
metadata:
4+
name: redis-connect-mysql-stage # deployment name
5+
labels:
6+
app: redis-connect-mysql-stage # deployment label
7+
spec:
8+
backOffLimit: 3 # try this many times before declaring failure
9+
template: # pod template
10+
metadata:
11+
labels:
12+
app: redis-connect-mysql-stage
13+
spec:
14+
restartPolicy: OnFailure
15+
containers:
16+
- name: redis-connect-mysql # Container name
17+
image: redislabs/redis-connect-mysql:pre-release-alpine #repo/image:tag
18+
# #### uncomment the following two lines for troubleshooting
19+
# command: [ "/bin/bash", "-c", "--" ]
20+
# args: [ "while true; do sleep 30; done;" ]
21+
# ####
22+
command: [ "/opt/redislabs/redis-connect-mysql/bin/redisconnect.sh", "stage"]
23+
imagePullPolicy: Always # IfNotPresent # Always pull image
24+
resources:
25+
limits:
26+
cpu: "500m"
27+
memory: "256Mi"
28+
requests:
29+
cpu: "250m"
30+
memory: "256Mi"
31+
ports:
32+
- containerPort: 8282 # exposed container port to the REST API
33+
protocol: TCP
34+
env:
35+
- name: REDISCONNECT_LOGBACK_CONFIG
36+
value: "/opt/redislabs/redis-connect-mysql/config/logs/logback.xml"
37+
# valueFrom:
38+
# configMapKeyRef:
39+
# key: REDISCONNECT_LOGBACK_CONFIG
40+
# name: redis-connect-mysql-config
41+
- name: REDISCONNECT_CONFIG
42+
value: "/opt/redislabs/redis-connect-mysql/config/fromconfigmap"
43+
# valueFrom:
44+
# configMapKeyRef:
45+
# key: REDISCONNECT_CONFIG
46+
# name: redis-connect-mysql-config
47+
- name: REDISCONNECT_REST_API_ENABLED
48+
value: "false"
49+
# valueFrom:
50+
# configMapKeyRef:
51+
# key: REDISCONNECT_REST_API_ENABLED
52+
# name: redis-connect-mysql-config
53+
- name: REDISCONNECT_REST_API_PORT
54+
value: "8282"
55+
# valueFrom:
56+
# configMapKeyRef:
57+
# key: REDISCONNECT_REST_API_PORT
58+
# name: redis-connect-mysql-config
59+
- name: REDISCONNECT_SOURCE_USERNAME
60+
value: redisconnectuser
61+
# valueFrom:
62+
# configMapKeyRef:
63+
# key: REDISCONNECT_SOURCE_USERNAME
64+
# name: redis-connect-mysql-config
65+
# valueFrom:
66+
# secretKeyRef:
67+
# key: username
68+
# name: redis-connect-secret
69+
- name: REDISCONNECT_SOURCE_PASSWORD
70+
value: redisconnectpassword
71+
# valueFrom:
72+
# configMapKeyRef:
73+
# key: REDISCONNECT_SOURCE_PASSWORD
74+
# name: redis-connect-mysql-config
75+
# valueFrom:
76+
# secretKeyRef:
77+
# key: password
78+
# name: redis-connect-secret
79+
- name: REDISCONNECT_JAVA_OPTIONS
80+
value: "-XX:+HeapDumpOnOutOfMemoryError -Xms256m -Xmx1g"
81+
# valueFrom:
82+
# configMapKeyRef:
83+
# key: REDISCONNECT_JAVA_OPTIONS
84+
# name: redis-connect-mysql-config
85+
- name: REDISCONNECT_TARGET_PASSWORD
86+
value: test
87+
# valueFrom:
88+
# configMapKeyRef:
89+
# key: REDISCONNECT_TARGET_PASSWORD
90+
# name: redis-connect-mysql-config
91+
- name: REDISCONNECT_TARGET_USERNAME
92+
value: test
93+
# valueFrom:
94+
# configMapKeyRef:
95+
# key: REDISCONNECT_TARGET_USERNAME
96+
# name: redis-connect-mysql-config
97+
volumeMounts:
98+
# - name: redis-connect-mysql-pv
99+
# mountPath: "/opt/redislabs/redis-connect-mysql"
100+
- name: tmpfsdir # Pod volumes to mount into the container's filesystem. Cannot be updated.
101+
mountPath: /tmpfs
102+
- name: config-volume
103+
mountPath: /opt/redislabs/redis-connect-mysql/config/fromconfigmap # must match env:REDISCONNECT_CONFIG
104+
- name: custom-stage-volume
105+
mountPath: /opt/redislabs/redis-connect-mysql/extlib # Redis Connect expects the custom stage jars here
106+
volumes:
107+
- name: config-volume
108+
configMap:
109+
name: redis-connect-mysql-config
110+
items:
111+
- key: JobConfig.yml
112+
path: JobConfig.yml
113+
- key: JobManager.yml
114+
path: JobManager.yml
115+
- key: Setup.yml
116+
path: Setup.yml
117+
- key: env.yml
118+
path: env.yml
119+
- key: mapper1.yml
120+
path: mappers/mapper1.yml
121+
- name: custom-stage-volume
122+
configMap:
123+
name: redis-connect-mysql-config
124+
items: # define as many custom stages as you have here
125+
- key: redis-connect-custom-stage-demo-1.0-SNAPSHOT.jar
126+
path: redis-connect-custom-stage-demo-1.0-SNAPSHOT.jar
127+
- name: tmpfsdir
128+
emptyDir: # node-ephemeral volume
129+
medium: Memory
130+
# - name: redis-connect-mysql-pv
131+
# persistentVolumeClaim:
132+
# claimName: redis-connect-mysql-pvc
133+
---
134+
# RedisConnect service with name 'redis-connect-service'
135+
# apiVersion: v1
136+
# kind: Service
137+
# metadata:
138+
# name: redis-connect-service # name should not be 'redis-connect'
139+
# spec:
140+
# type: ClusterIP
141+
# ports:
142+
# - port: 80
143+
# targetPort: 8282
144+
# selector:
145+
# app: redis-connect
146+
# ---
147+
# apiVersion: v1
148+
# kind: PersistentVolumeClaim
149+
# metadata:
150+
# name: redis-connect-mysql-pvc
151+
# spec:
152+
# storageClassName: gp2
153+
# accessModes:
154+
# - ReadWriteOnce
155+
# resources:
156+
# requests:
157+
# storage: 20Gi
158+
# ---

0 commit comments

Comments
 (0)