Skip to content

Commit

Permalink
Master-slave binding via lifecycleActions field, deprecating script (…
Browse files Browse the repository at this point in the history
…but still retaining)
  • Loading branch information
XiaoLiang2333 committed Sep 19, 2024
1 parent ae3411c commit 94cd643
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 27 deletions.
21 changes: 0 additions & 21 deletions tools/kubeblocks_helm/pika-master-slave/script/admin.sh
Original file line number Diff line number Diff line change
@@ -1,21 +0,0 @@
#! /bin/bash
set -x

# 获取当前Pod的索引
INDEX=${HOSTNAME##*-}
echo "index:${INDEX}"
# PIKA配置文件路径
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-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 @@ -32,15 +32,30 @@ spec:
volumes:
- name: data
lifecycleActions:
memberJoin:
postProvision:
customHandler:
image: {{ include "redis.image" . }}
image: {{ include "redis.image" .}}
exec:
command:
- /bin/sh
- /bin/bash
- -c
- "redis-cli -h ${CURRENT_POD_IP} -p ${KB_SERVICE_PORT} slaveof $(KB_MEMBER_ADDRESSES%%,*)"
preCondition: RuntimeReady
- |
IFS=',' read -r -a pod_name_array <<< ${KB_CLUSTER_COMPONENT_POD_NAME_LIST}
IFS=',' read -r -a pod_ip_array <<< ${KB_CLUSTER_COMPONENT_POD_IP_LIST}
# Ergodic name and ip array
for i in "${!pod_name_array[@]}"; do
pod_name=${pod_name_array[${i}]}
pod_ip=${pod_ip_array[${i}]}
# Extracting the digital portion of the pod
pod_number=$(echo "${pod_name}" | grep -o '[0-9]*')
# If the pod number is greater than 0
if (( pod_number > 0 )); then
pod0_ip=${pod_ip_array[0]}
echo "exec:redis-cli -h ${pod_ip} -p 9221 slaveof ${pod0_ip}:9221"
redis-cli -h "${pod_ip}" -p 9221 slaveof "${pod0_ip}" 9221
fi
done
preCondition: ComponentReady
runtime:
initContainers:
- name: init-config
Expand Down
2 changes: 1 addition & 1 deletion tools/kubeblocks_helm/pika-master-slave/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ image:
pullPolicy: IfNotPresent
redis:
registry: docker.io
repository: redislabs/redis
repository: redis
pullPolicy: IfNotPresent
roleProbe:
pika:
Expand Down

0 comments on commit 94cd643

Please sign in to comment.