Skip to content

Commit

Permalink
feat:pika-master-slave-cluster in kb (#2903)
Browse files Browse the repository at this point in the history
* Pika-master-slave-cluster in kubeblocks 0.9;use lifecycleActions instead of script to bind master-slave relation

* Use lifecycleActions instead of script to bind master-slave relation(Warning: This feature still has bugs waiting to be fixed)

* Master-slave binding via lifecycleActions field, deprecating script (but still retaining)

* Use headless svc to replace the ip
  • Loading branch information
XiaoLiang2333 authored and brother-jin committed Dec 25, 2024
1 parent d031ba6 commit c3cd42e
Show file tree
Hide file tree
Showing 18 changed files with 1,086 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tools/kubeblocks_helm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ kubectl port-forward svc/pika-cluster-codis-proxy 19000
# start new terminal
redis-cli -p 19000 info
```
### uninstall pika cluster
```bash
helm uninstall pika-cluster
helm uninstall pika
```

## Scale pika cluster

Expand All @@ -46,3 +51,29 @@ helm upgrade pika-cluster ./pika-cluster

### Scale in
scale in is not supported now.

## Install pika Master/Slave group by kubeblocks

### Install pika CD and pika Master/Slave
First,use helm install pika-master-slave-group componentdefinition and pika-master-slave cluster
```bash
cd ./tools/kubeblocks-helm/
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 cluster
```bash
kubectl port-forward svc/pika-master-slave-cluster-pika 9221
#start new terminal
redis-cli -p 9221
```
### uninstall pika master-slave-cluster
```bash
helm uninstall pika-master-slave-cluster
helm uninstall pika-master-slave
```
23 changes: 23 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave-cluster/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
22 changes: 22 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave-cluster/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: v2
name: pika-master-slave
description: A Pika Master-Slave Group Helm chart for KubeBlocks.

type: application

version: 0.9.0

appVersion: "3.5.5"

home: https://github.com/OpenAtomFoundation/pika
keywords:
- pika
- redis
- database
- nosql
- replication
- codis

maintainers:
- name: pika
url: https://github.com/OpenAtomFoundation/pika/tools/kubeblocks_helm
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "pika-cluster.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "pika-cluster.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "pika-cluster.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "pika-cluster.labels" -}}
helm.sh/chart: {{ include "pika-cluster.chart" . }}
{{ include "pika-cluster.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "pika-cluster.selectorLabels" -}}
app.kubernetes.io/name: {{ include "pika-cluster.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{- define "clustername" -}}
{{ include "pika-cluster.fullname" .}}
{{- end}}

{{/*
Create the name of the service account to use
*/}}
{{- define "pika-cluster.serviceAccountName" -}}
{{- default (printf "kb-%s" (include "clustername" .)) .Values.serviceAccount.name }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
apiVersion: apps.kubeblocks.io/v1alpha1
kind: Cluster
metadata:
name: {{ include "clustername" . }}
namespace: {{ .Release.Namespace }}
labels: {{ include "pika-cluster.labels" . | nindent 4 }}
spec:
terminationPolicy: {{ .Values.terminationPolicy }}
affinity:
{{- with .Values.topologyKeys }}
topologyKeys: {{ . | toYaml | nindent 6 }}
{{- end }}
{{- with $.Values.tolerations }}
tolerations: {{ . | toYaml | nindent 4 }}
{{- end }}
componentSpecs:
- name: pika
componentDef: pika # Ref componentdefinition.name
enabledLogs: {{ $.Values.enabledLogs | toJson | indent 4 }}
replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }}
serviceAccountName: {{ include "pika-cluster.serviceAccountName" $ }}
{{- with $.Values.resources.pikaMS }}
resources:
limits:
cpu: {{ .limits.cpu | quote }}
memory: {{ .limits.memory | quote }}
requests:
cpu: {{ .requests.cpu | quote }}
memory: {{ .requests.memory | quote }}
{{- end }}
{{- if $.Values.persistence.enabled }}
volumeClaimTemplates:
{{- with $.Values.persistence.pikaData }}
- name: data # ref componentDefinition.containers.volumeMounts.name
spec:
storageClassName: {{ .storageClassName }}
accessModes:
- ReadWriteOnce
resources:
requests:
storage: {{ .size }}
{{- end }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: kb-{{ include "clustername" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "pika-cluster.labels" . | nindent 4 }}
rules:
- apiGroups:
- ""
resources:
- events
verbs:
- create
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: kb-{{ include "clustername" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "pika-cluster.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: kb-{{ include "clustername" . }}
subjects:
- kind: ServiceAccount
name: {{ include "pika-cluster.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "pika-cluster.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{ include "pika-cluster.labels" . | nindent 4 }}
52 changes: 52 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave-cluster/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Default values for pika.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

nameOverride: ""
fullnameOverride: ""

slaveCount: 1

terminationPolicy: Delete

clusterVersionOverride: ""

monitor:
enabled: false

switchPolicy:
type: Noop

resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
pikaMS:
limits:
cpu: 500m
memory: 3Gi
requests:
cpu: 500m
memory: 1Gi

persistence:
enabled: true
pikaData:
storageClassName:
size: 10Gi

topologyKeys:
- kubernetes.io/hostname

## @param tolerations
## ref: https://kubernetes.io/docs/concepts/configuration/taint-and-toleration/
##
tolerations: [ ]

#enabledLogs:
# - running

# The RBAC permission used by cluster component pod, now include event.create
serviceAccount:
name: ""
23 changes: 23 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
21 changes: 21 additions & 0 deletions tools/kubeblocks_helm/pika-master-slave/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: v2
name: pika
description: A Pika Master Slave Group definition Helm chart for Kubernetes

type: application

version: 0.9.0

appVersion: "3.5.5"

home: https://github.com/OpenAtomFoundation/pika
keywords:
- pika
- redis
- database
- nosql
- replication

maintainers:
- name: pika
url: https://github.com/OpenAtomFoundation/pika/tools/kubeblocks_helm
Loading

0 comments on commit c3cd42e

Please sign in to comment.