Skip to content

Commit

Permalink
Use lifecycleActions instead of script to bind master-slave relation(…
Browse files Browse the repository at this point in the history
…Warning: This feature still has bugs waiting to be fixed)
  • Loading branch information
XiaoLiang2333 committed Sep 17, 2024
1 parent b5ddc4a commit ae3411c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 11 deletions.
8 changes: 4 additions & 4 deletions tools/kubeblocks_helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,16 @@ scale in is not supported now.
First,use helm install pika-master-slave-group componentdefinition and pika-master-slave cluster
```bash
cd ./tools/kubeblocks-helm/
helm install pika-master-slave-group ./pika-master-slave-group
helm install pika-master-slave ./pika-master-slave-group
helm install pika-master-slave ./pika-master-slave
helm install pika-master-slave-cluster ./pika-master-slave-cluster
```
Wait for pika-master-slave-pika-{index} pods until the status all to be `Running`.
```bash
kubectl get pods --watch
````
### connect to pika master-slave group
### connect to pika master-slave cluster
```bash
kubectl port-forward svc/pika-master-slave-pika 9221
kubectl port-forward svc/pika-master-slave-cluster-pika 9221
#start new terminal
redis-cli -p 9221
```
Expand Down
3 changes: 2 additions & 1 deletion tools/kubeblocks_helm/pika-master-slave/script/admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ echo "index:${INDEX}"
PIKA_CONF="../data/pika.conf"

# 确保配置文件存在

touch $PIKA_CONF
echo $?
if [ "$INDEX" = "0" ]; then
# 如果是pika-0,配置为主节点
../pika/bin/pika -c ../data/pika.conf
else
# 如果不是pika-0,配置为从节点
sed -i "s/#slaveof : master-ip:master-port/slaveof : pika-master-slave-pika-0.pika-master-slave-pika-headless.default.svc.cluster.local:9221/" $PIKA_CONF
sed -i "s/#slaveof : master-ip:master-port/slaveof : pika-master-slave-cluster-pika:9221/" $PIKA_CONF
../pika/bin/pika -c ../data/pika.conf
fi
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,12 @@ Define image

{{- define "pika.imagePullPolicy" -}}
{{ .Values.image.pika.pullPolicy | default "IfNotPresent" }}
{{- end }}

{{- define "redis.image" -}}
{{ .Values.image.pika.registry | default "docker.io" }}/{{ .Values.image.redis.repository }}
{{- end }}

{{- define "redis.imagePullPolicy" -}}
{{ .Values.image.pika.pullPolicy | default "IfNotPresent" }}
{{- end }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@ metadata:
name: pika
labels:
{{- include "pika.labels" . | nindent 4 }}
spec:
topologies:
- name: master-slave-cluster
components:
- name: master-slave
compDef: pika
default: true
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,28 @@ spec:
targetPort: pika
updateStrategy: Serial
configs:
- name: pika-config
- name: config
templateRef: pika-master-slave-conf-template
namespace: {{ .Release.Namespace }}
volumeName: config
scripts:
- name: pika-script
- name: script
templateRef: pika-master-slave-script-template
namespace: {{ .Release.Namespace }}
volumeName: script
defaultMode: 0555
volumes:
- name: data
lifecycleActions:
memberJoin:
customHandler:
image: {{ include "redis.image" . }}
exec:
command:
- /bin/sh
- -c
- "redis-cli -h ${CURRENT_POD_IP} -p ${KB_SERVICE_PORT} slaveof $(KB_MEMBER_ADDRESSES%%,*)"
preCondition: RuntimeReady
runtime:
initContainers:
- name: init-config
Expand Down Expand Up @@ -60,8 +70,14 @@ spec:
mountPath: /data
- name: script
mountPath: /script
command:
- "/bin/bash"
args:
env:
- name: CURRENT_POD_HOST_IP
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: status.hostIP
command:
- "/pika/bin/pika"
args:
- "-c"
- "sh /script/admin.sh"
- "/etc/pika/pika.conf"
4 changes: 4 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ image:
repository: pikadb/pika
tag: 3.5.3
pullPolicy: IfNotPresent
redis:
registry: docker.io
repository: redislabs/redis
pullPolicy: IfNotPresent
roleProbe:
pika:
failureThreshold: 2
Expand Down

0 comments on commit ae3411c

Please sign in to comment.