diff --git a/tools/kubeblocks_helm/README.md b/tools/kubeblocks_helm/README.md index f80a19fb5..04ec8c5bc 100644 --- a/tools/kubeblocks_helm/README.md +++ b/tools/kubeblocks_helm/README.md @@ -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 ``` diff --git a/tools/kubeblocks_helm/pika-master-slave/script/admin.sh b/tools/kubeblocks_helm/pika-master-slave/script/admin.sh index 3b4c0864d..dc50fa674 100644 --- a/tools/kubeblocks_helm/pika-master-slave/script/admin.sh +++ b/tools/kubeblocks_helm/pika-master-slave/script/admin.sh @@ -8,6 +8,7 @@ echo "index:${INDEX}" PIKA_CONF="../data/pika.conf" # 确保配置文件存在 + touch $PIKA_CONF echo $? if [ "$INDEX" = "0" ]; then @@ -15,6 +16,6 @@ if [ "$INDEX" = "0" ]; then ../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 diff --git a/tools/kubeblocks_helm/pika-master-slave/templates/_helpers.tpl b/tools/kubeblocks_helm/pika-master-slave/templates/_helpers.tpl index 5c5c04f6e..ac8d1009c 100644 --- a/tools/kubeblocks_helm/pika-master-slave/templates/_helpers.tpl +++ b/tools/kubeblocks_helm/pika-master-slave/templates/_helpers.tpl @@ -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 }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave/templates/clusterdefinition.yaml b/tools/kubeblocks_helm/pika-master-slave/templates/clusterdefinition.yaml index 486d97035..994ed325d 100644 --- a/tools/kubeblocks_helm/pika-master-slave/templates/clusterdefinition.yaml +++ b/tools/kubeblocks_helm/pika-master-slave/templates/clusterdefinition.yaml @@ -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 \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave/templates/componentdefinition-pika.yaml b/tools/kubeblocks_helm/pika-master-slave/templates/componentdefinition-pika.yaml index 8bdd2f69f..ca6dff3a6 100644 --- a/tools/kubeblocks_helm/pika-master-slave/templates/componentdefinition-pika.yaml +++ b/tools/kubeblocks_helm/pika-master-slave/templates/componentdefinition-pika.yaml @@ -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 @@ -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" \ No newline at end of file + - "/etc/pika/pika.conf" \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave/values.yaml b/tools/kubeblocks_helm/pika-master-slave/values.yaml index d900fbb05..4e3bd3544 100644 --- a/tools/kubeblocks_helm/pika-master-slave/values.yaml +++ b/tools/kubeblocks_helm/pika-master-slave/values.yaml @@ -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