From bbcd1dc46fd187b34b1f5589e537ef7a708aca35 Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Mon, 22 Jul 2024 11:07:30 +0800 Subject: [PATCH 01/10] kb0.9 --- .../pika/templates/componentversion.yaml | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tools/kubeblocks_helm/pika/templates/componentversion.yaml diff --git a/tools/kubeblocks_helm/pika/templates/componentversion.yaml b/tools/kubeblocks_helm/pika/templates/componentversion.yaml new file mode 100644 index 0000000000..d5e472987f --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentversion.yaml @@ -0,0 +1,48 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentVersion +metadata: + name: pika-{{ default .Chart.AppVersion .Values.clusterVersionOverride }} + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + releases: + - name: pika-group + serviceVersion: 3.5.3 + images: + pika: {{ include "pika.image" . }} + codis-admin: {{ include "codis.image" . }} + - name: etcd + serviceVersion: 3.5.9 + images: + etcd: {{ include "etcd.image" . }} + - name: pika-exporter + serviceVersion: 3.5.3 + images: + pika-exporter: {{ include "pikaExporter.image" . }} + - name: codis-proxy + serviceVersion: 3.5.3 + images: + codis-proxy: {{ include "codis.image" . }} + - name: codis-fe + serviceVersion: 3.5.3 + images: + codis-fe: {{ include "codis.image" . }} + - name: codis-dashboard + serviceVersion: 3.5.3 + images: + codis-dashboard: {{ include "codis.image" . }} + compatibilityRules: + - compDefs: + - pika-group + - etcd + - pika-exporter + - codis-proxy + - codis-fe + - codis-dashboard + releases: + - 3.5.3 + - 3.5.9 + - 3.5.3 + - 3.5.3 + - 3.5.3 + - 3.5.3 \ No newline at end of file From aacb36792325da0933ad7dd0eb2143eced8e1359 Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Mon, 22 Jul 2024 11:09:52 +0800 Subject: [PATCH 02/10] kube0.9 --- .../pika-cluster/templates/cluster.yaml | 35 +- tools/kubeblocks_helm/pika/.helmignore | 2 +- .../pika/templates/clusterdefinition.yaml | 438 +----------------- .../pika/templates/clusterversion.yaml | 48 -- tools/kubeblocks_helm/pika/values.yaml | 3 +- 5 files changed, 20 insertions(+), 506 deletions(-) delete mode 100644 tools/kubeblocks_helm/pika/templates/clusterversion.yaml diff --git a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml index 7a7a5b6a0d..cfa385339f 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml +++ b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml @@ -6,7 +6,8 @@ metadata: labels: {{ include "pika-cluster.labels" . | nindent 4 }} spec: clusterDefinitionRef: pika # ref clusterDefinition.name - clusterVersionRef: pika-{{ default .Chart.AppVersion .Values.clusterVersionOverride }} # ref clusterVersion.name + #clusterVersionRef: pika-{{ default .Chart.AppVersion .Values.clusterVersionOverride }} # ref clusterVersion.name 已弃用 + topology: replication-codis terminationPolicy: {{ .Values.terminationPolicy }} affinity: {{- with .Values.topologyKeys }} @@ -51,13 +52,13 @@ spec: {{- if .Values.useLegacyCompDef }} {{- range $i := until (int .Values.groupCount) }} - name: pika-group-{{ add ($i) 1 }} # user-defined - componentDefRef: pika-group # ref clusterDefinition.componentDefs[x].name - monitor: {{ $.Values.monitor.enabled | default false }} + componentDef: pika-group # ref clusterDefinition.componentDefs[x].name + # monitor: {{ $.Values.monitor.enabled | default false }} 已被弃用 enabledLogs: {{ $.Values.enabledLogs | toJson | indent 4 }} replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }} serviceAccountName: {{ include "pika-cluster.serviceAccountName" $ }} - switchPolicy: - type: {{ $.Values.switchPolicy.type}} + #switchPolicy: 已被弃用 + # type: {{ $.Values.switchPolicy.type}} {{- with $.Values.resources.pikaGroup }} resources: limits: @@ -83,12 +84,8 @@ spec: {{- end }} {{- end }} - name: etcd # user-defined - {{- if .Values.useLegacyCompDef }} - componentDefRef: etcd # ref clusterDefinition.componentDefs[x].name - {{- else }} componentDef: pika-etcd # ref componentDefinition name - {{- end }} - monitor: {{ .Values.monitor.enabled | default false }} + #monitor: {{ .Values.monitor.enabled | default false }} replicas: {{ .Values.etcdReplicaCount| default 3 }} {{- with .Values.resources.etcd }} resources: @@ -117,12 +114,8 @@ spec: {{- end }} {{- end }} - name: pika-exporter - {{- if .Values.useLegacyCompDef }} - componentDefRef: pika-exporter # ref clusterDefinition.componentDefs[x].name - {{- else }} componentDef: pika-exporter # ref componentDefinition name - {{- end }} - monitor: {{ .Values.monitor.enabled | default false }} + #monitor: {{ .Values.monitor.enabled | default false }} replicas: 1 {{- with .Values.resources.pikaExporter }} resources: @@ -134,11 +127,7 @@ spec: memory: {{ .requests.memory | quote }} {{- end }} - name: codis-proxy - {{- if .Values.useLegacyCompDef }} - componentDefRef: codis-proxy # ref clusterDefinition.componentDefs[x].name - {{- else }} componentDef: pika-codis-proxy # ref componentDefinition name - {{- end }} replicas: {{ .Values.codisProxyReplicaCount | default 2 }} {{- with .Values.resources.codisProxy }} resources: @@ -150,11 +139,7 @@ spec: memory: {{ .requests.memory | quote }} {{- end }} - name: codis-fe - {{- if .Values.useLegacyCompDef }} - componentDefRef: codis-fe # ref clusterDefinition.componentDefs[x].name - {{- else }} componentDef: pika-codis-fe # ref componentDefinition name - {{- end }} replicas: {{ .Values.codisFeReplicaCount | default 1 }} {{- with .Values.resources.codisFe }} resources: @@ -166,11 +151,7 @@ spec: memory: {{ .requests.memory | quote }} {{- end }} - name: codis-dashboard - {{- if .Values.useLegacyCompDef }} - componentDefRef: codis-dashboard # ref clusterDefinition.componentDefs[x].name - {{- else }} componentDef: pika-codis-dashboard # ref componentDefinition name - {{- end }} replicas: 1 {{- with .Values.resources.codisFe }} resources: diff --git a/tools/kubeblocks_helm/pika/.helmignore b/tools/kubeblocks_helm/pika/.helmignore index 0e8a0eb36f..368cb0dd5e 100644 --- a/tools/kubeblocks_helm/pika/.helmignore +++ b/tools/kubeblocks_helm/pika/.helmignore @@ -10,7 +10,7 @@ .hg/ .hgignore .svn/ -# Common backup files +# Common files *.swp *.bak *.tmp diff --git a/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml b/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml index 2e910e63ab..634f03def2 100644 --- a/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml +++ b/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml @@ -5,437 +5,19 @@ metadata: labels: {{- include "pika.labels" . | nindent 4 }} spec: - type: pika - connectionCredential: - username: default - password: "$(RANDOM_PASSWD)" - endpoint: "$(SVC_FQDN):$(SVC_PORT_pika)" - host: "$(SVC_FQDN)" - port: "$(SVC_PORT_pika)" - componentDefs: + topologies: + - name: replication-codis + components: - name: pika-group - workloadType: Stateful - characterType: pika - service: - ports: - - name: pika - port: 9221 - targetPort: pika - configSpecs: - - name: pika-config - templateRef: pika-conf-template - namespace: {{ .Release.Namespace }} - volumeName: config - scriptSpecs: - - name: pika-script - templateRef: pika-script-template - namespace: {{ .Release.Namespace }} - volumeName: script - defaultMode: 0555 - volumeTypes: - - name: data - type: data - postStartSpec: - cmdExecutorConfig: - image: {{ include "codis.image" . }} - command: - - "/bin/bash" - args: - - "-c" - - "/script/admin.sh --rebalance" - scriptSpecSelectors: - - name: pika-script - podSpec: - initContainers: - - name: init-config - image: busybox:1.28 - imagePullPolicy: IfNotPresent - command: - - /bin/sh - - -ec - - | - if [ ! -f "/data/pika.conf" ];then cp /etc/pika/pika.conf /data/pika.conf; fi - volumeMounts: - - name: config - mountPath: /etc/pika - - name: data - mountPath: /data - containers: - - name: pika - ports: - - name: pika - containerPort: 9221 - volumeMounts: - - name: config - mountPath: /etc/pika - - name: data - mountPath: /data - command: - - "/pika/bin/pika" - args: - - "-c" - - "/data/pika.conf" - - name: codis-admin - volumeMounts: - - name: script - mountPath: /script - command: - - "/bin/bash" - args: - - "-c" - - "/script/admin.sh --register-server;tail -f /dev/null" - lifecycle: - preStop: - exec: - command: - - "/bin/bash" - - "-c" - - "/script/admin.sh --remove-server" + compDef: componentdefinition-pika-group - name: etcd - workloadType: Stateful - characterType: etcd - service: - ports: - - name: client - port: 2379 - targetPort: client - - name: peer - port: 2380 - targetPort: peer - volumeTypes: - - name: data - type: data - configSpecs: - podSpec: - initContainers: - - name: volume-permissions - image: busybox:1.28 - imagePullPolicy: IfNotPresent - command: - - /bin/sh - - -ec - - | - chown -R 1001:1001 /bitnami/etcd - securityContext: - runAsUser: 0 - volumeMounts: - - name: data - mountPath: /bitnami/etcd - containers: - - name: etcd - imagePullPolicy: "IfNotPresent" - securityContext: - runAsNonRoot: false - runAsUser: 1001 - allowPrivilegeEscalation: false - terminationMessagePath: /dev/termination-log - terminationMessagePolicy: File - volumeMounts: - - mountPath: /bitnami/etcd - name: data - ports: - - name: client - containerPort: 2379 - - name: peer - containerPort: 2380 - env: - - name: BITNAMI_DEBUG - value: "true" - - name: MY_POD_IP - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: status.podIP - - name: MY_POD_NAME - valueFrom: - fieldRef: - apiVersion: v1 - fieldPath: metadata.name - - name: MY_STS_NAME - value: $(KB_CLUSTER_COMP_NAME) - - name: ETCDCTL_API - value: "3" - - name: ETCD_ON_K8S - value: "yes" - - name: ETCD_START_FROM_SNAPSHOT - value: "no" - - name: ETCD_DISASTER_RECOVERY - value: "no" - - name: ETCD_NAME - value: $(MY_POD_NAME) - - name: ETCD_DATA_DIR - value: /bitnami/etcd/data - - name: ETCD_LOG_LEVEL - value: info - - name: ALLOW_NONE_AUTHENTICATION - value: "yes" - - name: ETCD_INITIAL_CLUSTER_TOKEN - value: "$(KB_CLUSTER_NAME)" - - name: ETCD_INITIAL_CLUSTER_STATE - value: "new" - - name: ETCD_INITIAL_CLUSTER - value: "{{ include "etcd.initialCluster" .}}" - - name: ETCD_CLUSTER_DOMAIN - value: "{{ include "etcd.clusterDomain" .}}" - - name: ETCD_AUTO_COMPACTION_MODE - value: "periodic" - - name: ETCD_AUTO_COMPACTION_RETENTION - value: "1h" - - name: ETCD_ADVERTISE_CLIENT_URLS - value: "{{ include "etcd.advertiseClientURLs" .}}" - - name: ETCD_LISTEN_CLIENT_URLS - value: http://0.0.0.0:2379 - - name: ETCD_INITIAL_ADVERTISE_PEER_URLS - value: http://$(KB_POD_FQDN){{ .Values.clusterDomain }}:2380 - - name: ETCD_LISTEN_PEER_URLS - value: http://0.0.0.0:2380 - - name: ETCD_QUOTA_BACKEND_BYTES - value: "4294967296" - - name: ETCD_HEARTBEAT_INTERVAL - value: "500" - - name: ETCD_ELECTION_TIMEOUT - value: "2500" - - name: ETCD_ENABLE_V2 - value: "true" + compDef: componentdefinition-etcd - name: pika-exporter - workloadType: Stateless - characterType: pika - monitor: - builtIn: false - exporterConfig: - scrapePath: /metrics - scrapePort: 9121 - service: - ports: - - name: exporter - targetPort: exporter - port: 9121 - configSpecs: - - name: pika-config - templateRef: pika-conf-template - namespace: {{ .Release.Namespace }} - volumeName: config - podSpec: - initContainers: - - name: wait-codis-dashboard - env: - - name: DASHBOARD_ADDR - value: "$(KB_CLUSTER_NAME)-codis-dashboard" - image: busybox:1.28 - command: - - 'sh' - - '-c' - - "until nc -z ${DASHBOARD_ADDR} 18080; do echo waiting for codis dashboard; sleep 2; done;" - containers: - - name: pika-exporter - imagePullPolicy: IfNotPresent - ports: - - containerPort: 9121 - name: exporter - volumeMounts: - - name: config - mountPath: /etc/pika - env: - - name: DASHBOARD_ADDR - value: "$(KB_CLUSTER_NAME)-codis-dashboard" - command: - - "/pika/bin/pika_exporter" - args: - - "-config" - - "/etc/pika/info.toml" - - "-codis.addr" - - "http://$(DASHBOARD_ADDR):18080/topom" + compDef: componentdefinition-pika-exporter - name: codis-proxy - workloadType: Stateful - characterType: pika - service: - ports: - - name: proxy - targetPort: proxy - port: 11080 - - name: admin - targetPort: admin - port: 19000 - configSpecs: - - name: codis-proxy-config - templateRef: pika-conf-template - namespace: {{ .Release.Namespace }} - volumeName: config - podSpec: - initContainers: - - name: wait-etcd - env: - - name: ETCD_ADDR - value: "{{ include "etcd.clusterDomain" .}}" - - name: DASHBOARD_ADDR - value: "$(KB_CLUSTER_NAME)-codis-dashboard" - image: busybox:1.28 - command: - - 'sh' - - '-c' - - "until nc -z ${ETCD_ADDR} 2379; do echo waiting for etcd; sleep 2; done;" - - "until nc -z ${DASHBOARD_ADDR} 18080; do echo waiting for etcd; sleep 2; done;" - containers: - - name: codis-proxy - imagePullPolicy: IfNotPresent - ports: - - containerPort: 11080 - name: proxy - - containerPort: 19000 - name: admin - volumeMounts: - - name: config - mountPath: /etc/codis - env: - - name: POD_IP - valueFrom: - fieldRef: - fieldPath: status.podIP - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: ETCD_ADDR - value: "{{ include "etcd.clusterDomain" .}}:2379" - - name: DASHBOARD_ADDR - value: "$(KB_CLUSTER_NAME)-codis-dashboard:18080" - - name: PRODUCT_NAME - value: "$(KB_CLUSTER_NAME)" - command: - - "/codis/bin/codis-proxy" - args: - - "-c" - - "/etc/codis/proxy.toml" - - "--host-admin" - - "$(POD_IP):11080" - - "--host-proxy" - - "$(POD_IP):19000" - - "--etcd" - - "$(ETCD_ADDR)" - - "--product_name" - - "$(PRODUCT_NAME)" - - "--pidfile" - - "log/proxy.pid" - - "--log-level=DEBUG" - lifecycle: - preStop: - exec: - command: - - "/bin/sh" - - "-c" - - "/codis/bin/codis-admin --dashboard=${DASHBOARD_ADDR} --remove-proxy --addr=${POD_IP}:11080 1>/dev/null 2>&1" + compDef: componentdefinition-codis-proxy - name: codis-fe - workloadType: Stateless - characterType: pika - service: - ports: - - name: fe - targetPort: fe - port: 8080 - podSpec: - initContainers: - - name: wait-etcd - env: - - name: ETCD_ADDR - value: "{{ include "etcd.clusterDomain" .}}" - - name: DASHBOARD_ADDR - value: "$(KB_CLUSTER_NAME)-codis-dashboard" - image: busybox:1.28 - command: - - 'sh' - - '-c' - - "until nc -z ${ETCD_ADDR} 2379; do echo waiting for etcd; sleep 2; done;" - - "until nc -z ${DASHBOARD_ADDR} 18080; do echo waiting for etcd; sleep 2; done;" - containers: - - name: codis-fe - imagePullPolicy: IfNotPresent - ports: - - containerPort: 8080 - name: fe - env: - - name: POD_IP - valueFrom: - fieldRef: - fieldPath: status.podIP - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: ETCD_ADDR - value: "{{ include "etcd.clusterDomain" .}}:2379" - command: - - "/codis/bin/codis-fe" - args: - - "--etcd" - - "$(ETCD_ADDR)" - - "--listen=0.0.0.0:8080" - - "--assets=/codis/bin/assets" - - "--log-level=DEBUG" + compDef: componentdefinition-codis-fe - name: codis-dashboard - workloadType: Stateful - characterType: pika - service: - ports: - - name: dashboard - targetPort: dashboard - port: 18080 - configSpecs: - - name: codis-dashboard-config - templateRef: pika-conf-template - namespace: {{ .Release.Namespace }} - volumeName: config - podSpec: - initContainers: - - name: wait-etcd - env: - - name: ETCD_ADDR - value: "{{ include "etcd.clusterDomain" .}}" - image: busybox:1.28 - command: - - 'sh' - - '-c' - - "until nc -z ${ETCD_ADDR} 2379; do echo waiting for etcd; sleep 2; done;" - containers: - - name: codis-dashboard - imagePullPolicy: IfNotPresent - ports: - - containerPort: 18080 - name: dashboard - volumeMounts: - - name: config - mountPath: /etc/codis - env: - - name: POD_IP - valueFrom: - fieldRef: - fieldPath: status.podIP - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: ETCD_ADDR - value: "{{ include "etcd.clusterDomain" .}}:2379" - - name: PRODUCT_NAME - value: "$(KB_CLUSTER_NAME)" - command: - - "/codis/bin/codis-dashboard" - args: - - "-c" - - "/etc/codis/dashboard.toml" - - "--host-admin" - - "$(POD_IP):18080" - - "--etcd" - - "$(ETCD_ADDR)" - - "--product_name" - - "$(PRODUCT_NAME)" - - "--pidfile" - - "log/dashboard.pid" - - "--remove-lock" - - "--log-level=DEBUG" - lifecycle: - postStart: - exec: - command: [ "/bin/bash", "-c", "/codis/bin/codis-admin --dashboard-list --etcd=${ETCD_ADDR}" ] - preStop: - exec: - command: [ "/bin/sh", "-c", "PID=$(cat log/dashboard.pid) && kill $PID && while ps -p 1 > /dev/null; do sleep 1; done" ] + compDef: componentdefinition-codis-dashboard + default: true diff --git a/tools/kubeblocks_helm/pika/templates/clusterversion.yaml b/tools/kubeblocks_helm/pika/templates/clusterversion.yaml deleted file mode 100644 index b698449d83..0000000000 --- a/tools/kubeblocks_helm/pika/templates/clusterversion.yaml +++ /dev/null @@ -1,48 +0,0 @@ -apiVersion: apps.kubeblocks.io/v1alpha1 -kind: ClusterVersion -metadata: - name: pika-{{ default .Chart.AppVersion .Values.clusterVersionOverride }} - labels: - {{- include "pika.labels" . | nindent 4 }} -spec: - clusterDefinitionRef: pika - componentVersions: - - componentDefRef: pika-group - versionsContext: - containers: - - name: pika - image: {{ include "pika.image" . }} - imagePullPolicy: {{ include "pika.imagePullPolicy" . }} - - name: codis-admin - image: {{ include "codis.image" . }} - imagePullPolicy: {{ include "codis.imagePullPolicy" . }} - - componentDefRef: etcd - versionsContext: - containers: - - name: etcd - image: {{ include "etcd.image" . }} - imagePullPolicy: {{ include "etcd.imagePullPolicy" . }} - - componentDefRef: pika-exporter - versionsContext: - containers: - - name: pika-exporter - image: {{ include "pikaExporter.image" . }} - imagePullPolicy: {{ include "pikaExporter.imagePullPolicy" . }} - - componentDefRef: codis-proxy - versionsContext: - containers: - - name: codis-proxy - image: {{ include "codis.image" . }} - imagePullPolicy: {{ include "codis.imagePullPolicy" . }} - - componentDefRef: codis-fe - versionsContext: - containers: - - name: codis-fe - image: {{ include "codis.image" . }} - imagePullPolicy: {{ include "codis.imagePullPolicy" . }} - - componentDefRef: codis-dashboard - versionsContext: - containers: - - name: codis-dashboard - image: {{ include "codis.image" . }} - imagePullPolicy: {{ include "codis.imagePullPolicy" . }} diff --git a/tools/kubeblocks_helm/pika/values.yaml b/tools/kubeblocks_helm/pika/values.yaml index 48dea8ad58..333f902479 100644 --- a/tools/kubeblocks_helm/pika/values.yaml +++ b/tools/kubeblocks_helm/pika/values.yaml @@ -21,7 +21,6 @@ image: repository: bitnami/etcd tag: 3.5.9 pullPolicy: IfNotPresent - roleProbe: pika: failureThreshold: 2 @@ -44,7 +43,7 @@ roleProbe: periodSeconds: 1 timeoutSeconds: 1 -clusterVersionOverride: 3.5.3 +componentVersionOverride: 3.5.3 nameOverride: "" fullnameOverride: "" From a29f819e5d425685abea37f6c5df92efe3a3980a Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Tue, 23 Jul 2024 21:54:55 +0800 Subject: [PATCH 03/10] use sharding --- .../pika-cluster/templates/cluster.yaml | 30 +++--------- tools/kubeblocks_helm/pika/script/admin.sh | 2 +- .../pika/templates/clusterdefinition.yaml | 12 ++--- .../pika/templates/component-pika-group.yaml | 18 +++++++ .../componentversion-codis-dashboard.yaml | 18 +++++++ .../templates/componentversion-codis-fe.yaml | 18 +++++++ .../componentversion-codis-proxy.yaml | 18 +++++++ .../templates/componentversion-pika-etcd.yaml | 18 +++++++ .../componentversion-pika-exporter.yaml | 18 +++++++ .../pika/templates/componentversion.yaml | 48 ------------------- tools/kubeblocks_helm/pika/values.yaml | 3 -- 11 files changed, 120 insertions(+), 83 deletions(-) create mode 100644 tools/kubeblocks_helm/pika/templates/component-pika-group.yaml create mode 100644 tools/kubeblocks_helm/pika/templates/componentversion-codis-dashboard.yaml create mode 100644 tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml create mode 100644 tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml create mode 100644 tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml create mode 100644 tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml delete mode 100644 tools/kubeblocks_helm/pika/templates/componentversion.yaml diff --git a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml index cfa385339f..138f0badd8 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml +++ b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml @@ -6,7 +6,6 @@ metadata: labels: {{ include "pika-cluster.labels" . | nindent 4 }} spec: clusterDefinitionRef: pika # ref clusterDefinition.name - #clusterVersionRef: pika-{{ default .Chart.AppVersion .Values.clusterVersionOverride }} # ref clusterVersion.name 已弃用 topology: replication-codis terminationPolicy: {{ .Values.terminationPolicy }} affinity: @@ -17,13 +16,14 @@ spec: tolerations: {{ . | toYaml | nindent 4 }} {{- end }} ## define pika group with shardingSpecs API which is supported in KubeBlocks v0.8.2 - {{- if not .Values.useLegacyCompDef }} shardingSpecs: - name: group shards: {{ .Values.groupCount }} template: name: pika componentDef: pika-group + enabledLogs: {{ $.Values.enabledLogs | toJson | indent 4 }} + serviceAccountName: {{ include "pika-cluster.serviceAccountName" $ }} replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }} {{- with $.Values.resources.pikaGroup }} resources: @@ -47,18 +47,15 @@ spec: storage: {{ .size }} {{- end }} {{- end }} - {{- end }} componentSpecs: - {{- if .Values.useLegacyCompDef }} - {{- range $i := until (int .Values.groupCount) }} - - name: pika-group-{{ add ($i) 1 }} # user-defined + - name: pika-group # user-defined componentDef: pika-group # ref clusterDefinition.componentDefs[x].name - # monitor: {{ $.Values.monitor.enabled | default false }} 已被弃用 + monitor: {{ $.Values.monitor.enabled | default false }} enabledLogs: {{ $.Values.enabledLogs | toJson | indent 4 }} replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }} serviceAccountName: {{ include "pika-cluster.serviceAccountName" $ }} - #switchPolicy: 已被弃用 - # type: {{ $.Values.switchPolicy.type}} + switchPolicy: + type: {{ $.Values.switchPolicy.type}} {{- with $.Values.resources.pikaGroup }} resources: limits: @@ -81,8 +78,6 @@ spec: storage: {{ .size }} {{- end }} {{- end }} - {{- end }} - {{- end }} - name: etcd # user-defined componentDef: pika-etcd # ref componentDefinition name #monitor: {{ .Values.monitor.enabled | default false }} @@ -113,19 +108,6 @@ spec: storage: {{ .size }} {{- end }} {{- end }} - - name: pika-exporter - componentDef: pika-exporter # ref componentDefinition name - #monitor: {{ .Values.monitor.enabled | default false }} - replicas: 1 - {{- with .Values.resources.pikaExporter }} - resources: - limits: - cpu: {{ .limits.cpu | quote }} - memory: {{ .limits.memory | quote }} - requests: - cpu: {{ .requests.cpu | quote }} - memory: {{ .requests.memory | quote }} - {{- end }} - name: codis-proxy componentDef: pika-codis-proxy # ref componentDefinition name replicas: {{ .Values.codisProxyReplicaCount | default 2 }} diff --git a/tools/kubeblocks_helm/pika/script/admin.sh b/tools/kubeblocks_helm/pika/script/admin.sh index b51af92f38..b6f614f84b 100755 --- a/tools/kubeblocks_helm/pika/script/admin.sh +++ b/tools/kubeblocks_helm/pika/script/admin.sh @@ -9,7 +9,7 @@ set_instance_role() { # set group id set_group_id() { - GROUP_ID=${KB_CLUSTER_COMP_NAME##*-} + GROUP_ID=${KB_POD_NAME##*-} echo "GROUP_ID: "${GROUP_ID} } diff --git a/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml b/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml index 634f03def2..9595da8ecb 100644 --- a/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml +++ b/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml @@ -9,15 +9,13 @@ spec: - name: replication-codis components: - name: pika-group - compDef: componentdefinition-pika-group + compDef: pika-group - name: etcd - compDef: componentdefinition-etcd - - name: pika-exporter - compDef: componentdefinition-pika-exporter + compDef: pika-etcd - name: codis-proxy - compDef: componentdefinition-codis-proxy + compDef: pika-codis-proxy - name: codis-fe - compDef: componentdefinition-codis-fe + compDef: pika-codis-fe - name: codis-dashboard - compDef: componentdefinition-codis-dashboard + compDef: pika-codis-dashboard default: true diff --git a/tools/kubeblocks_helm/pika/templates/component-pika-group.yaml b/tools/kubeblocks_helm/pika/templates/component-pika-group.yaml new file mode 100644 index 0000000000..1638732439 --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/component-pika-group.yaml @@ -0,0 +1,18 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentVersion +metadata: + name: pika-group + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + compatibilityRules: + - compDefs: + - pika-group + releases: + - 3.5.3 + releases: + - name: 3.5.3 + changes: + serviceVersion: 3.5.3 + images: + codis-dashboard: {{ include "pika.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-codis-dashboard.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-codis-dashboard.yaml new file mode 100644 index 0000000000..2d1f6fb15d --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentversion-codis-dashboard.yaml @@ -0,0 +1,18 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentVersion +metadata: + name: pika-codis-dashboard + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + compatibilityRules: + - compDefs: + - pika-codis-dashboard + releases: + - 3.5.3 + releases: + - name: 3.5.3 + changes: + serviceVersion: 3.5.3 + images: + codis-dashboard: {{ include "codis.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml new file mode 100644 index 0000000000..0b2163975c --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml @@ -0,0 +1,18 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentVersion +metadata: + name: pika-codis-fe + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + compatibilityRules: + - compDefs: + - pika-codis-fe + releases: + - 3.5.3 + releases: + - name: 3.5.3 + changes: + serviceVersion: 3.5.3 + images: + codis-dashboard: {{ include "codis.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml new file mode 100644 index 0000000000..18f1a1ec0b --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml @@ -0,0 +1,18 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentVersion +metadata: + name: pika-codis-proxy + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + compatibilityRules: + - compDefs: + - pika-codis-proxy + releases: + - 3.5.3 + releases: + - name: 3.5.3 + changes: + serviceVersion: 3.5.3 + images: + codis-dashboard: {{ include "codis.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml new file mode 100644 index 0000000000..c74e7c04a6 --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml @@ -0,0 +1,18 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentVersion +metadata: + name: pika-etcd + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + compatibilityRules: + - compDefs: + - pika-etcd + releases: + - 3.5.9 + releases: + - name: 3.5.9 + changes: + serviceVersion: 3.5.9 + images: + codis-dashboard: {{ include "etcd.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml new file mode 100644 index 0000000000..1c9b873611 --- /dev/null +++ b/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml @@ -0,0 +1,18 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentVersion +metadata: + name: pika-exporter + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + compatibilityRules: + - compDefs: + - pika-exporter + releases: + - 3.5.3 + releases: + - name: 3.5.3 + changes: + serviceVersion: 3.5.3 + images: + codis-dashboard: {{ include "pikaExporter.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion.yaml b/tools/kubeblocks_helm/pika/templates/componentversion.yaml deleted file mode 100644 index d5e472987f..0000000000 --- a/tools/kubeblocks_helm/pika/templates/componentversion.yaml +++ /dev/null @@ -1,48 +0,0 @@ -apiVersion: apps.kubeblocks.io/v1alpha1 -kind: ComponentVersion -metadata: - name: pika-{{ default .Chart.AppVersion .Values.clusterVersionOverride }} - labels: - {{- include "pika.labels" . | nindent 4 }} -spec: - releases: - - name: pika-group - serviceVersion: 3.5.3 - images: - pika: {{ include "pika.image" . }} - codis-admin: {{ include "codis.image" . }} - - name: etcd - serviceVersion: 3.5.9 - images: - etcd: {{ include "etcd.image" . }} - - name: pika-exporter - serviceVersion: 3.5.3 - images: - pika-exporter: {{ include "pikaExporter.image" . }} - - name: codis-proxy - serviceVersion: 3.5.3 - images: - codis-proxy: {{ include "codis.image" . }} - - name: codis-fe - serviceVersion: 3.5.3 - images: - codis-fe: {{ include "codis.image" . }} - - name: codis-dashboard - serviceVersion: 3.5.3 - images: - codis-dashboard: {{ include "codis.image" . }} - compatibilityRules: - - compDefs: - - pika-group - - etcd - - pika-exporter - - codis-proxy - - codis-fe - - codis-dashboard - releases: - - 3.5.3 - - 3.5.9 - - 3.5.3 - - 3.5.3 - - 3.5.3 - - 3.5.3 \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/values.yaml b/tools/kubeblocks_helm/pika/values.yaml index 333f902479..9158b21877 100644 --- a/tools/kubeblocks_helm/pika/values.yaml +++ b/tools/kubeblocks_helm/pika/values.yaml @@ -42,9 +42,6 @@ roleProbe: failureThreshold: 2 periodSeconds: 1 timeoutSeconds: 1 - -componentVersionOverride: 3.5.3 nameOverride: "" fullnameOverride: "" - clusterDomain: ".cluster.local" From 45736588a3f7e8a6ffb9f3cdfbbcc90b9159e174 Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Wed, 24 Jul 2024 20:10:37 +0800 Subject: [PATCH 04/10] Deselect topology --- .../pika-cluster/templates/cluster.yaml | 33 ------------------- tools/kubeblocks_helm/pika/script/admin.sh | 2 +- .../pika/templates/clusterdefinition.yaml | 15 --------- ....yaml => componentversion-pika-group.yaml} | 0 4 files changed, 1 insertion(+), 49 deletions(-) rename tools/kubeblocks_helm/pika/templates/{component-pika-group.yaml => componentversion-pika-group.yaml} (100%) diff --git a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml index 138f0badd8..cdbd9c2a93 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml +++ b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml @@ -5,8 +5,6 @@ metadata: namespace: {{ .Release.Namespace }} labels: {{ include "pika-cluster.labels" . | nindent 4 }} spec: - clusterDefinitionRef: pika # ref clusterDefinition.name - topology: replication-codis terminationPolicy: {{ .Values.terminationPolicy }} affinity: {{- with .Values.topologyKeys }} @@ -15,7 +13,6 @@ spec: {{- with $.Values.tolerations }} tolerations: {{ . | toYaml | nindent 4 }} {{- end }} - ## define pika group with shardingSpecs API which is supported in KubeBlocks v0.8.2 shardingSpecs: - name: group shards: {{ .Values.groupCount }} @@ -48,36 +45,6 @@ spec: {{- end }} {{- end }} componentSpecs: - - name: pika-group # user-defined - componentDef: pika-group # ref clusterDefinition.componentDefs[x].name - monitor: {{ $.Values.monitor.enabled | default false }} - enabledLogs: {{ $.Values.enabledLogs | toJson | indent 4 }} - replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }} - serviceAccountName: {{ include "pika-cluster.serviceAccountName" $ }} - switchPolicy: - type: {{ $.Values.switchPolicy.type}} - {{- with $.Values.resources.pikaGroup }} - 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 clusterdefinition components.containers.volumeMounts.name - spec: - storageClassName: {{ .storageClassName }} - accessModes: - - ReadWriteOnce - resources: - requests: - storage: {{ .size }} - {{- end }} - {{- end }} - name: etcd # user-defined componentDef: pika-etcd # ref componentDefinition name #monitor: {{ .Values.monitor.enabled | default false }} diff --git a/tools/kubeblocks_helm/pika/script/admin.sh b/tools/kubeblocks_helm/pika/script/admin.sh index b6f614f84b..c8b7871ac9 100755 --- a/tools/kubeblocks_helm/pika/script/admin.sh +++ b/tools/kubeblocks_helm/pika/script/admin.sh @@ -9,7 +9,7 @@ set_instance_role() { # set group id set_group_id() { - GROUP_ID=${KB_POD_NAME##*-} + GROUP_ID=${KB_COMP_NAME##*-} echo "GROUP_ID: "${GROUP_ID} } diff --git a/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml b/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml index 9595da8ecb..486d97035c 100644 --- a/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml +++ b/tools/kubeblocks_helm/pika/templates/clusterdefinition.yaml @@ -4,18 +4,3 @@ metadata: name: pika labels: {{- include "pika.labels" . | nindent 4 }} -spec: - topologies: - - name: replication-codis - components: - - name: pika-group - compDef: pika-group - - name: etcd - compDef: pika-etcd - - name: codis-proxy - compDef: pika-codis-proxy - - name: codis-fe - compDef: pika-codis-fe - - name: codis-dashboard - compDef: pika-codis-dashboard - default: true diff --git a/tools/kubeblocks_helm/pika/templates/component-pika-group.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml similarity index 100% rename from tools/kubeblocks_helm/pika/templates/component-pika-group.yaml rename to tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml From b07a93244b43376b16f4e35e0421eb6c8f151bd6 Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Sat, 27 Jul 2024 19:33:39 +0800 Subject: [PATCH 05/10] recover componentSpecs --- .../pika-cluster/templates/cluster.yaml | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml index cdbd9c2a93..b8f61d826d 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml +++ b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml @@ -13,6 +13,7 @@ spec: {{- with $.Values.tolerations }} tolerations: {{ . | toYaml | nindent 4 }} {{- end }} + {{- if not .Values.useLegacyCompDef }} shardingSpecs: - name: group shards: {{ .Values.groupCount }} @@ -44,7 +45,39 @@ spec: storage: {{ .size }} {{- end }} {{- end }} + {{- end }} componentSpecs: + {{- if .Values.useLegacyCompDef }} + {{- range $i := until (int .Values.groupCount) }} + - name: pika-group-{{ add ($i) 1 }} # user-defined + componentDef: pika-group # ref clusterDefinition.componentDefs[x].name + enabledLogs: {{ $.Values.enabledLogs | toJson | indent 4 }} + replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }} + serviceAccountName: {{ include "pika-cluster.serviceAccountName" $ }} + {{- with $.Values.resources.pikaGroup }} + 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 clusterdefinition components.containers.volumeMounts.name + spec: + storageClassName: {{ .storageClassName }} + accessModes: + - ReadWriteOnce + resources: + requests: + storage: {{ .size }} + {{- end }} + {{- end }} + {{- end }} + {{- end }} - name: etcd # user-defined componentDef: pika-etcd # ref componentDefinition name #monitor: {{ .Values.monitor.enabled | default false }} @@ -110,4 +143,4 @@ spec: requests: cpu: {{ .requests.cpu | quote }} memory: {{ .requests.memory | quote }} - {{- end }} + {{- end }} \ No newline at end of file From 8daf590e16468fe4acfbaf28e5c9b184d82f0a4b Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Fri, 2 Aug 2024 20:01:10 +0800 Subject: [PATCH 06/10] Update kb-0.9 --- .../pika-cluster/templates/cluster.yaml | 20 +++++++++++++---- .../componentdefinition-codis-dashboard.yaml | 4 ++-- .../componentdefinition-codis-fe.yaml | 4 ++-- .../componentdefinition-codis-proxy.yaml | 4 ++-- .../componentdefinition-pika-etcd.yaml | 4 ++-- .../componentdefinition-pika-exporter.yaml | 9 +++++++- .../componentdefinition-pika-group.yaml | 22 ++++++++++++++++--- .../pika/templates/configmap.yaml | 1 + .../pika/templates/script.yaml | 1 + 9 files changed, 53 insertions(+), 16 deletions(-) diff --git a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml index b8f61d826d..7e7ba65839 100644 --- a/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml +++ b/tools/kubeblocks_helm/pika-cluster/templates/cluster.yaml @@ -50,7 +50,7 @@ spec: {{- if .Values.useLegacyCompDef }} {{- range $i := until (int .Values.groupCount) }} - name: pika-group-{{ add ($i) 1 }} # user-defined - componentDef: pika-group # ref clusterDefinition.componentDefs[x].name + componentDef: pika-group # Ref componentdefinition.name enabledLogs: {{ $.Values.enabledLogs | toJson | indent 4 }} replicas: {{ add (int $.Values.slaveCount) 1 | default 2 }} serviceAccountName: {{ include "pika-cluster.serviceAccountName" $ }} @@ -66,7 +66,7 @@ spec: {{- if $.Values.persistence.enabled }} volumeClaimTemplates: {{- with $.Values.persistence.pikaData }} - - name: data # ref clusterdefinition components.containers.volumeMounts.name + - name: data # ref componentDefinition.containers.volumeMounts.name spec: storageClassName: {{ .storageClassName }} accessModes: @@ -80,7 +80,6 @@ spec: {{- end }} - name: etcd # user-defined componentDef: pika-etcd # ref componentDefinition name - #monitor: {{ .Values.monitor.enabled | default false }} replicas: {{ .Values.etcdReplicaCount| default 3 }} {{- with .Values.resources.etcd }} resources: @@ -98,7 +97,7 @@ spec: {{- if .Values.persistence.enabled }} volumeClaimTemplates: {{- with $.Values.persistence.etcdData }} - - name: data # ref clusterdefinition components.containers.volumeMounts.name + - name: data # ref componentDefinition.containers.volumeMounts.name spec: storageClassName: {{ .storageClassName }} accessModes: @@ -120,6 +119,19 @@ spec: cpu: {{ .requests.cpu | quote }} memory: {{ .requests.memory | quote }} {{- end }} + - name: pika-exporter + componentDef: pika-exporter # ref componentDefinition name + monitor: {{ .Values.monitor.enabled | default false }} + replicas: 1 + {{- with .Values.resources.pikaExporter }} + resources: + limits: + cpu: {{ .limits.cpu | quote }} + memory: {{ .limits.memory | quote }} + requests: + cpu: {{ .requests.cpu | quote }} + memory: {{ .requests.memory | quote }} + {{- end }} - name: codis-fe componentDef: pika-codis-fe # ref componentDefinition name replicas: {{ .Values.codisFeReplicaCount | default 1 }} diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-dashboard.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-dashboard.yaml index 3bc8ca087d..d0407d5e61 100644 --- a/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-dashboard.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-dashboard.yaml @@ -2,16 +2,16 @@ apiVersion: apps.kubeblocks.io/v1alpha1 kind: ComponentDefinition metadata: name: pika-codis-dashboard + namespace: {{ .Release.Namespace }} labels: {{- include "pika.labels" . | nindent 4 }} spec: provider: pika description: A pika codis dashboard component definition serviceKind: pika-codis-dashboard - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} services: - name: dashboard - serviceName: dashboard spec: ports: - name: dashboard diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-fe.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-fe.yaml index daf920b9e3..8ff2ddb9c5 100644 --- a/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-fe.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-fe.yaml @@ -2,16 +2,16 @@ apiVersion: apps.kubeblocks.io/v1alpha1 kind: ComponentDefinition metadata: name: pika-codis-fe + namespace: {{ .Release.Namespace }} labels: {{- include "pika.labels" . | nindent 4 }} spec: provider: pika description: A pika codis frontend component definition serviceKind: pika-codis-fe - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} services: - name: fe - serviceName: fe spec: ports: - name: fe diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-proxy.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-proxy.yaml index 598e288739..d004a04245 100644 --- a/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-proxy.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-codis-proxy.yaml @@ -2,16 +2,16 @@ apiVersion: apps.kubeblocks.io/v1alpha1 kind: ComponentDefinition metadata: name: pika-codis-proxy + namespace: {{ .Release.Namespace }} labels: {{- include "pika.labels" . | nindent 4 }} spec: provider: pika description: A pika codis proxy component definition serviceKind: pika-codis-proxy - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} services: - name: proxy - serviceName: proxy spec: ports: - name: proxy diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-etcd.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-etcd.yaml index d259690e27..3d646bd87f 100644 --- a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-etcd.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-etcd.yaml @@ -2,16 +2,16 @@ apiVersion: apps.kubeblocks.io/v1alpha1 kind: ComponentDefinition metadata: name: pika-etcd + namespace: {{ .Release.Namespace }} labels: {{- include "pika.labels" . | nindent 4 }} spec: provider: pika description: A pika etcd component definition serviceKind: pika-etcd - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} services: - name: etcd - serviceName: etcd spec: ports: - name: client diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-exporter.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-exporter.yaml index 292c496fc5..3b2b42930e 100644 --- a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-exporter.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-exporter.yaml @@ -2,6 +2,7 @@ apiVersion: apps.kubeblocks.io/v1alpha1 kind: ComponentDefinition metadata: name: pika-exporter + namespace: {{ .Release.Namespace }} labels: {{- include "pika.labels" . | nindent 4 }} spec: @@ -11,7 +12,6 @@ spec: serviceVersion: {{ .Chart.AppVersion }} services: - name: expoter - serviceName: expoter spec: ports: - name: expoter @@ -21,6 +21,7 @@ spec: configs: - name: pika-config templateRef: pika-conf-template + namespace: {{ .Release.Namespace }} volumeName: config vars: ## reference to the pika-codis-dashboard service @@ -34,6 +35,9 @@ spec: runtime: initContainers: - name: wait-codis-dashboard + env: + - name: DASHBOARD_ADDR + value: "$(KB_CLUSTER_NAME)-codis-dashboard" image: busybox:1.28 command: - 'sh' @@ -49,6 +53,9 @@ spec: volumeMounts: - name: config mountPath: /etc/pika + env: + - name: DASHBOARD_ADDR + value: "$(KB_CLUSTER_NAME)-codis-dashboard" command: - "/pika/bin/pika_exporter" args: diff --git a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml index 69c1384bae..3ce656c04d 100644 --- a/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentdefinition-pika-group.yaml @@ -2,16 +2,16 @@ apiVersion: apps.kubeblocks.io/v1alpha1 kind: ComponentDefinition metadata: name: pika-group + namespace: {{ .Release.Namespace }} labels: {{- include "pika.labels" . | nindent 4 }} spec: provider: pika description: A pika group component definition serviceKind: pika-group - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} services: - name: pika - serviceName: pika spec: ports: - name: pika @@ -29,6 +29,8 @@ spec: namespace: {{ .Release.Namespace }} volumeName: script defaultMode: 0555 + volumes: + - name: data lifecycleActions: postProvision: customHandler: @@ -50,6 +52,20 @@ spec: optional: true host: Optional runtime: + initContainers: + - name: init-config + image: busybox:1.28 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -ec + - | + if [ ! -f "/data/pika.conf" ];then cp /etc/pika/pika.conf /data/pika.conf; fi + volumeMounts: + - name: config + mountPath: /etc/pika + - name: data + mountPath: /data containers: - name: pika image: {{ include "pika.image" . }} @@ -66,7 +82,7 @@ spec: - "/pika/bin/pika" args: - "-c" - - "/etc/pika/pika.conf" + - "/data/pika.conf" - name: codis-admin image: {{ include "codis.image" . }} imagePullPolicy: {{ include "codis.imagePullPolicy" . }} diff --git a/tools/kubeblocks_helm/pika/templates/configmap.yaml b/tools/kubeblocks_helm/pika/templates/configmap.yaml index 20e9448f4c..70a628a4f7 100644 --- a/tools/kubeblocks_helm/pika/templates/configmap.yaml +++ b/tools/kubeblocks_helm/pika/templates/configmap.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: pika-conf-template + namespace: {{ .Release.Namespace }} labels: {{- include "pika.labels" . | nindent 4 }} data: diff --git a/tools/kubeblocks_helm/pika/templates/script.yaml b/tools/kubeblocks_helm/pika/templates/script.yaml index fe1625d769..f378f49f61 100644 --- a/tools/kubeblocks_helm/pika/templates/script.yaml +++ b/tools/kubeblocks_helm/pika/templates/script.yaml @@ -2,6 +2,7 @@ apiVersion: v1 kind: ConfigMap metadata: name: pika-script-template + namespace: {{ .Release.Namespace }} labels: {{- include "pika.labels" . | nindent 4 }} data: From 63c8f1166dfaa4016a09cfa78424659b1283cc5f Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Fri, 9 Aug 2024 20:36:39 +0800 Subject: [PATCH 07/10] adjust script --- tools/kubeblocks_helm/README.md | 2 +- tools/kubeblocks_helm/pika-cluster/Chart.yaml | 2 +- tools/kubeblocks_helm/pika/Chart.yaml | 2 +- tools/kubeblocks_helm/pika/script/admin.sh | 4 ++-- .../pika/templates/componentversion-codis-dashboard.yaml | 6 +++--- .../pika/templates/componentversion-codis-fe.yaml | 6 +++--- .../pika/templates/componentversion-codis-proxy.yaml | 6 +++--- .../pika/templates/componentversion-pika-etcd.yaml | 6 +++--- .../pika/templates/componentversion-pika-exporter.yaml | 6 +++--- .../pika/templates/componentversion-pika-group.yaml | 6 +++--- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/tools/kubeblocks_helm/README.md b/tools/kubeblocks_helm/README.md index 187ca5b07a..c657a4458c 100644 --- a/tools/kubeblocks_helm/README.md +++ b/tools/kubeblocks_helm/README.md @@ -23,7 +23,7 @@ kubectl get cluster --watch ### Add Pika instance to codis Then connect codis front end. ```bash - kubectl port-forward svc/pika-cluster-codis-fe 8080 +kubectl port-forward svc/pika-cluster-codis-fe 8080 ``` Open browser and visit `http://localhost:8080` diff --git a/tools/kubeblocks_helm/pika-cluster/Chart.yaml b/tools/kubeblocks_helm/pika-cluster/Chart.yaml index 8893b8b19f..2b5e85debe 100644 --- a/tools/kubeblocks_helm/pika-cluster/Chart.yaml +++ b/tools/kubeblocks_helm/pika-cluster/Chart.yaml @@ -4,7 +4,7 @@ description: A Pika Codis Cluster Helm chart for KubeBlocks. type: application -version: 0.7.1-beta.1 +version: 0.9.0 appVersion: "3.5.3" diff --git a/tools/kubeblocks_helm/pika/Chart.yaml b/tools/kubeblocks_helm/pika/Chart.yaml index c6e3c6ae47..ff316124f7 100644 --- a/tools/kubeblocks_helm/pika/Chart.yaml +++ b/tools/kubeblocks_helm/pika/Chart.yaml @@ -4,7 +4,7 @@ description: A Pika Codis cluster definition Helm chart for Kubernetes type: application -version: 0.7.1-beta.1 +version: 0.9.0 appVersion: "3.5.3" diff --git a/tools/kubeblocks_helm/pika/script/admin.sh b/tools/kubeblocks_helm/pika/script/admin.sh index c8b7871ac9..9b524bf7ea 100755 --- a/tools/kubeblocks_helm/pika/script/admin.sh +++ b/tools/kubeblocks_helm/pika/script/admin.sh @@ -81,8 +81,8 @@ reload_until_success() { register_server() { reload_until_success - if [ ${POD_ID} -gt 0 ]; then wait_all_master_registered; fi - $CODIS_ADMIN --create-group --gid=${GROUP_ID} 1>/dev/null 2>&1 + if [ ${POD_ID} -eq 0 ]; then $CODIS_ADMIN --create-group --gid=${GROUP_ID} 1>/dev/null 2>&1; fi + if [ ${POD_ID} -gt 0 ]; then wait_all_master_registered; sleep 5; fi $CODIS_ADMIN --group-add --gid=${GROUP_ID} --addr=${KB_POD_FQDN}:9221 $CODIS_ADMIN --sync-action --create --addr=${KB_POD_FQDN}:9221 1>/dev/null 2>&1 } diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-codis-dashboard.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-codis-dashboard.yaml index 2d1f6fb15d..a015af9fe4 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-codis-dashboard.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-codis-dashboard.yaml @@ -9,10 +9,10 @@ spec: - compDefs: - pika-codis-dashboard releases: - - 3.5.3 + - {{ .Chart.AppVersion }} releases: - - name: 3.5.3 + - name: {{ .Chart.AppVersion }} changes: - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} images: codis-dashboard: {{ include "codis.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml index 0b2163975c..cf3bb12d6a 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml @@ -9,10 +9,10 @@ spec: - compDefs: - pika-codis-fe releases: - - 3.5.3 + - {{ .Chart.AppVersion }} releases: - - name: 3.5.3 + - name: {{ .Chart.AppVersion }} changes: - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} images: codis-dashboard: {{ include "codis.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml index 18f1a1ec0b..98349009d9 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml @@ -9,10 +9,10 @@ spec: - compDefs: - pika-codis-proxy releases: - - 3.5.3 + - {{ .Chart.AppVersion }} releases: - - name: 3.5.3 + - name: {{ .Chart.AppVersion }} changes: - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} images: codis-dashboard: {{ include "codis.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml index c74e7c04a6..3a03709a84 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml @@ -9,10 +9,10 @@ spec: - compDefs: - pika-etcd releases: - - 3.5.9 + - {{ .Chart.AppVersion }} releases: - - name: 3.5.9 + - name: {{ .Chart.AppVersion }} changes: - serviceVersion: 3.5.9 + serviceVersion: {{ .Chart.AppVersion }} images: codis-dashboard: {{ include "etcd.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml index 1c9b873611..38b211e93d 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml @@ -9,10 +9,10 @@ spec: - compDefs: - pika-exporter releases: - - 3.5.3 + - {{ .Chart.AppVersion }} releases: - - name: 3.5.3 + - name: {{ .Chart.AppVersion }} changes: - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} images: codis-dashboard: {{ include "pikaExporter.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml index 1638732439..c07145d60a 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml @@ -9,10 +9,10 @@ spec: - compDefs: - pika-group releases: - - 3.5.3 + - {{ .Chart.AppVersion }} releases: - - name: 3.5.3 + - name: {{ .Chart.AppVersion }} changes: - serviceVersion: 3.5.3 + serviceVersion: {{ .Chart.AppVersion }} images: codis-dashboard: {{ include "pika.image" . }} \ No newline at end of file From 5d93ea564a3f945467f7013df02ac5640c20d8fa Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Tue, 10 Sep 2024 08:28:06 +0800 Subject: [PATCH 08/10] "pika-master-slave-group,but still need adjust" --- .../kubeblocks_helm/pika-cluster/values.yaml | 2 +- .../pika-master-slave-group/.helmignore | 23 + .../pika-master-slave-group/Chart.yaml | 21 + .../config/pika-config.tpl | 552 ++++++++++++++++++ .../pika-master-slave-group/script/admin.sh | 20 + .../templates/_helpers.tpl | 62 ++ .../templates/clusterdefinition.yaml | 6 + .../templates/componentdefinition-pika.yaml | 68 +++ .../templates/componentversion-pika.yaml | 18 + .../templates/configmap.yaml | 10 + .../templates/script.yaml | 10 + .../pika-master-slave-group/values.yaml | 16 + .../pika-master-slave/.helmignore | 23 + .../pika-master-slave/Chart.yaml | 22 + .../pika-master-slave/templates/_helpers.tpl | 62 ++ .../pika-master-slave/templates/cluster.yaml | 43 ++ .../pika-master-slave/templates/role.yaml | 14 + .../templates/rolebinding.yaml | 15 + .../templates/serviceaccount.yaml | 7 + .../pika-master-slave/values.yaml | 52 ++ 20 files changed, 1045 insertions(+), 1 deletion(-) create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/.helmignore create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/Chart.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/config/pika-config.tpl create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/script/admin.sh create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/templates/_helpers.tpl create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/templates/clusterdefinition.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/templates/componentdefinition-pika.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/templates/componentversion-pika.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/templates/configmap.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/templates/script.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave-group/values.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave/.helmignore create mode 100644 tools/kubeblocks_helm/pika-master-slave/Chart.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave/templates/_helpers.tpl create mode 100644 tools/kubeblocks_helm/pika-master-slave/templates/cluster.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave/templates/role.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave/templates/rolebinding.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave/templates/serviceaccount.yaml create mode 100644 tools/kubeblocks_helm/pika-master-slave/values.yaml diff --git a/tools/kubeblocks_helm/pika-cluster/values.yaml b/tools/kubeblocks_helm/pika-cluster/values.yaml index 328a3c4216..e3b467cdd4 100644 --- a/tools/kubeblocks_helm/pika-cluster/values.yaml +++ b/tools/kubeblocks_helm/pika-cluster/values.yaml @@ -13,7 +13,7 @@ fullnameOverride: "" groupCount: 2 -slaveCount: 1 +slaveCount: 2 etcdReplicaCount: 3 diff --git a/tools/kubeblocks_helm/pika-master-slave-group/.helmignore b/tools/kubeblocks_helm/pika-master-slave-group/.helmignore new file mode 100644 index 0000000000..368cb0dd5e --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/.helmignore @@ -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/ diff --git a/tools/kubeblocks_helm/pika-master-slave-group/Chart.yaml b/tools/kubeblocks_helm/pika-master-slave-group/Chart.yaml new file mode 100644 index 0000000000..422ee2184d --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/Chart.yaml @@ -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.3" + +home: https://github.com/OpenAtomFoundation/pika +keywords: + - pika + - redis + - database + - nosql + - replication + +maintainers: + - name: pika + url: https://github.com/OpenAtomFoundation/pika/tools/kubeblocks_helm diff --git a/tools/kubeblocks_helm/pika-master-slave-group/config/pika-config.tpl b/tools/kubeblocks_helm/pika-master-slave-group/config/pika-config.tpl new file mode 100644 index 0000000000..43e4b9ce11 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/config/pika-config.tpl @@ -0,0 +1,552 @@ +########################### +# Pika configuration file # +########################### + +# Pika port, the default value is 9221. +# [NOTICE] Port Magic offsets of port+1000 / port+2000 are used by Pika at present. +# Port 10221 is used for Rsync, and port 11221 is used for Replication, while the listening port is 9221. +port : 9221 + +# Random value identifying the Pika server, its string length must be 40. +# If not set, Pika will generate a random string with a length of 40 random characters. +# run-id : + +# Master's run-id +# master-run-id : + +# The number of threads for running Pika. +# It's not recommended to set this value exceeds +# the number of CPU cores on the deployment server. +thread-num : 1 + +# Size of the thread pool, The threads within this pool +# are dedicated to handling user requests. +thread-pool-size : 12 + +# Size of the low level thread pool, The threads within this pool +# are dedicated to handling slow user requests. +slow-cmd-thread-pool-size : 4 + +# Slow cmd list e.g. hgetall, mset +slow-cmd-list : + +# The number of sync-thread for data replication from master, those are the threads work on slave nodes +# and are used to execute commands sent from master node when replicating. +sync-thread-num : 6 + +# Directory to store log files of Pika, which contains multiple types of logs, +# Including: INFO, WARNING, ERROR log, as well as binglog(write2fine) file which +# is used for replication. +log-path : /data/log/ + +# Directory to store the data of Pika. +db-path : /data/db/ + +# The size of a single RocksDB memtable at the Pika's bottom layer(Pika use RocksDB to store persist data). +# [Tip] Big write-buffer-size can improve writing performance, +# but this will generate heavier IO load when flushing from buffer to disk, +# you should configure it based on you usage scenario. +# Supported Units [K|M|G], write-buffer-size default unit is in [bytes]. +write-buffer-size : 256M + +# The size of one block in arena memory allocation. +# If <= 0, a proper value is automatically calculated. +# (usually 1/8 of writer-buffer-size, rounded up to a multiple of 4KB) +# Supported Units [K|M|G], arena-block-size default unit is in [bytes]. +arena-block-size : + +# Timeout of Pika's connection, counting down starts When there are no requests +# on a connection (it enters sleep state), when the countdown reaches 0, the connection +# will be closed by Pika. +# [Tip] The issue of running out of Pika's connections may be avoided if this value +# is configured properly. +# The Unit of timeout is in [seconds] and its default value is 60(s). +timeout : 60 + +# The [password of administrator], which is empty by default. +# [NOTICE] If this admin password is the same as user password (including both being empty), +# the value of userpass will be ignored and all users are considered as administrators, +# in this scenario, users are not subject to the restrictions imposed by the userblacklist. +# PS: "user password" refers to value of the parameter below: userpass. +requirepass : + +# Password for replication verify, used for authentication when a slave +# connects to a master to request replication. +# [NOTICE] The value of this parameter must match the "requirepass" setting on the master. +masterauth : + +# The [password of user], which is empty by default. +# [NOTICE] If this user password is the same as admin password (including both being empty), +# the value of this parameter will be ignored and all users are considered as administrators, +# in this scenario, users are not subject to the restrictions imposed by the userblacklist. +# PS: "admin password" refers to value of the parameter above: requirepass. +userpass : + +# The blacklist of commands for users that logged in by userpass, +# the commands that added to this list will not be available for users except for administrator. +# [Advice] It's recommended to add high-risk commands to this list. +# [Format] Commands should be separated by ",". For example: FLUSHALL, SHUTDOWN, KEYS, CONFIG +# By default, this list is empty. +userblacklist : + +# Running Mode of Pika, The current version only supports running in "classic mode". +# If set to 'classic', Pika will create multiple DBs whose number is the value of configure item "databases". +instance-mode : classic + +# The number of databases when Pika runs in classic mode. +# The default database id is DB 0. You can select a different one on +# a per-connection by using SELECT. The db id range is [0, 'databases' value -1]. +# The value range of this parameter is [1, 8]. +databases : 1 + +# The number of followers of a master. Only [0, 1, 2, 3, 4] is valid at present. +# By default, this num is set to 0, which means this feature is [not enabled] +# and the Pika runs in standalone mode. +replication-num : 0 + +# consensus level defines the num of confirms(ACKs) the leader node needs to receive from +# follower nodes before returning the result to the client that sent the request. +# The [value range] of this parameter is: [0, ...replicaiton-num]. +# The default value of consensus-level is 0, which means this feature is not enabled. +consensus-level : 0 + +# The Prefix of dump file's name. +# All the files that generated by command "bgsave" will be name with this prefix. +dump-prefix : + +# daemonize [yes | no]. +#daemonize : yes + +# The directory to stored dump files that generated by command "bgsave". +dump-path : /data/dump/ + +# TTL of dump files that generated by command "bgsave". +# Any dump files which exceed this TTL will be deleted. +# Unit of dump-expire is in [days] and the default value is 0(day), +# which means dump files never expire. +dump-expire : 0 + +# Pid file Path of Pika. +pidfile : ./pika.pid + +# The Maximum number of Pika's Connection. +maxclients : 20000 + +# The size of sst file in RocksDB(Pika is based on RocksDB). +# sst files are hierarchical, the smaller the sst file size, the higher the performance and the lower the merge cost, +# the price is that the number of sst files could be huge. On the contrary, the bigger the sst file size, the lower +# the performance and the higher the merge cost, while the number of files is fewer. +# Supported Units [K|M|G], target-file-size-base default unit is in [bytes] and the default value is 20M. +target-file-size-base : 20M + +# Expire-time of binlog(write2file) files that stored within log-path. +# Any binlog(write2file) files that exceed this expire time will be cleaned up. +# The unit of expire-logs-days is in [days] and the default value is 7(days). +# The [Minimum value] of this parameter is 1(day). +expire-logs-days : 7 + +# The maximum number of binlog(write2file) files. +# Once the total number of binlog files exceed this value, +# automatic cleaning will start to ensure the maximum number +# of binlog files is equal to expire-logs-nums. +# The [Minimum value] of this parameter is 10. +expire-logs-nums : 10 + +# The number of guaranteed connections for root user. +# This parameter guarantees that there are 2(By default) connections available +# for root user to log in Pika from 127.0.0.1, even if the maximum connection limit is reached. +# PS: The maximum connection refers to the parameter above: maxclients. +# The default value of root-connection-num is 2. +root-connection-num : 2 + +# Slowlog-write-errorlog +slowlog-write-errorlog : no + +# The time threshold for slow log recording. +# Any command whose execution time exceeds this threshold will be recorded in pika-ERROR.log, +# which is stored in log-path. +# The unit of slowlog-log-slower-than is in [microseconds(μs)] and the default value is 10000 μs / 10 ms. +slowlog-log-slower-than : 10000 + +# Slowlog-max-len +slowlog-max-len : 128 + +# Pika db sync path +db-sync-path : /data/dbsync/ + +# The maximum Transmission speed during full synchronization. +# The exhaustion of network can be prevented by setting this parameter properly. +# The value range of this parameter is [1,1024] with unit in [MB/s]. +# [NOTICE] If this parameter is set to an invalid value(smaller than 0 or bigger than 1024), +# it will be automatically reset to 1024. +# The default value of db-sync-speed is -1 (1024MB/s). +db-sync-speed : -1 + +# The priority of slave node when electing new master node. +# The slave node with [lower] value of slave-priority will have [higher priority] to be elected as the new master node. +# This parameter is only used in conjunction with sentinel and serves no other purpose. +# The default value of slave-priority is 100. +slave-priority : 100 + +# Specify network interface that work with Pika. +#network-interface : eth1 + +# The IP and port of the master node are specified by this parameter for +# replication between master and slaves. +# [Format] is "ip:port" , for example: "192.168.1.2:6666" indicates that +# the slave instances that configured with this value will automatically send +# SLAVEOF command to port 6666 of 192.168.1.2 after startup. +# This parameter should be configured on slave nodes. +#slaveof : master-ip:master-port + + +# Daily/Weekly Automatic full compaction task is configured by compact-cron. +# +# [Format-daily]: start time(hour)-end time(hour)/disk-free-space-ratio, +# example: with value of "02-04/60", Pika will perform full compaction task between 2:00-4:00 AM everyday if +# the disk-free-size / disk-size > 60%. +# +# [Format-weekly]: week/start time(hour)-end time(hour)/disk-free-space-ratio, +# example: with value of "3/02-04/60", Pika will perform full compaction task between 2:00-4:00 AM every Wednesday if +# the disk-free-size / disk-size > 60%. +# +# [Tip] Automatic full compaction is suitable for scenarios with multiple data structures +# and lots of items are expired or deleted, or key names are frequently reused. +# +# [NOTICE]: If compact-interval is set, compact-cron will be masked and disabled. +# +#compact-cron : 3/02-04/60 + + +# Automatic full synchronization task between a time interval is configured by compact-interval. +# [Format]: time interval(hour)/disk-free-space-ratio, example: "6/60", Pika will perform full compaction every 6 hours, +# if the disk-free-size / disk-size > 60%. +# [NOTICE]: compact-interval is prior than compact-cron. +#compact-interval : + +# The disable_auto_compactions option is [true | false] +disable_auto_compactions : false + +# Rocksdb max_subcompactions +max-subcompactions : 1 +# The minimum disk usage ratio for checking resume. +# If the disk usage ratio is lower than min-check-resume-ratio, it will not check resume, only higher will check resume. +# Its default value is 0.7. +#min-check-resume-ratio : 0.7 + +# The minimum free disk space to trigger db resume. +# If the db has a background error, only the free disk size is larger than this configuration can trigger manually resume db. +# Its default value is 256MB. +# [NOTICE]: least-free-disk-resume-size should not smaller than write-buffer-size! +#least-free-disk-resume-size : 256M + +# Manually trying to resume db interval is configured by manually-resume-interval. +# If db has a background error, it will try to manually call resume() to resume db if satisfy the least free disk to resume. +# Its default value is 60 seconds. +#manually-resume-interval : 60 + +# This window-size determines the amount of data that can be transmitted in a single synchronization process. +# [Tip] In the scenario of high network latency. Increasing this size can improve synchronization efficiency. +# Its default value is 9000. the [maximum] value is 90000. +sync-window-size : 9000 + +# Maximum buffer size of a client connection. +# [NOTICE] Master and slaves must have exactly the same value for the max-conn-rbuf-size. +# Supported Units [K|M|G]. Its default unit is in [bytes] and its default value is 268435456(256MB). The value range is [64MB, 1GB]. +max-conn-rbuf-size : 268435456 + + +#######################################################################E####### +#! Critical Settings !# +#######################################################################E####### + +# write_binlog [yes | no] +write-binlog : yes + +# The size of binlog file, which can not be modified once Pika instance started. +# [NOTICE] Master and slaves must have exactly the same value for the binlog-file-size. +# The [value range] of binlog-file-size is [1K, 2G]. +# Supported Units [K|M|G], binlog-file-size default unit is in [bytes] and the default value is 100M. +binlog-file-size : 104857600 + +# Automatically triggers a small compaction according to statistics +# Use the cache to store up to 'max-cache-statistic-keys' keys +# If 'max-cache-statistic-keys' set to '0', that means turn off the statistics function +# and this automatic small compaction feature is disabled. +max-cache-statistic-keys : 0 + +# When 'delete' or 'overwrite' a specific multi-data structure key 'small-compaction-threshold' times, +# a small compact is triggered automatically if the small compaction feature is enabled. +# small-compaction-threshold default value is 5000 and the value range is [1, 100000]. +small-compaction-threshold : 5000 +small-compaction-duration-threshold : 10000 + +# The maximum total size of all live memtables of the RocksDB instance that owned by Pika. +# Flushing from memtable to disk will be triggered if the actual memory usage of RocksDB +# exceeds max-write-buffer-size when next write operation is issued. +# [RocksDB-Basic-Tuning](https://github.com/facebook/rocksdb/wiki/Setup-Options-and-Basic-Tuning) +# Supported Units [K|M|G], max-write-buffer-size default unit is in [bytes]. +max-write-buffer-size : 10737418240 + +# The maximum number of write buffers(memtables) that are built up in memory for one ColumnFamily in DB. +# The default and the minimum number is 2. It means that Pika(RocksDB) will write to a write buffer +# when it flushes the data of another write buffer to storage. +# If max-write-buffer-num > 3, writing will be slowed down. +max-write-buffer-num : 2 + +# `min_write_buffer_number_to_merge` is the minimum number of memtables +# that need to be merged before placing the order. For example, if the +# option is set to 2, immutable memtables will only be flushed if there +# are two of them - a single immutable memtable will never be flushed. +# If multiple memtables are merged together, less data will be written +# to storage because the two updates are merged into a single key. However, +# each Get() must linearly traverse all unmodifiable memtables and check +# whether the key exists. Setting this value too high may hurt performance. +min-write-buffer-number-to-merge : 1 + +# rocksdb level0_stop_writes_trigger +level0-stop-writes-trigger : 36 + +# rocksdb level0_slowdown_writes_trigger +level0-slowdown-writes-trigger : 20 + +# rocksdb level0_file_num_compaction_trigger +level0-file-num-compaction-trigger : 4 + +# The maximum size of the response package to client to prevent memory +# exhaustion caused by commands like 'keys *' and 'Scan' which can generate huge response. +# Supported Units [K|M|G]. The default unit is in [bytes]. +max-client-response-size : 1073741824 + +# The compression algorithm. You can not change it when Pika started. +# Supported types: [snappy, zlib, lz4, zstd]. If you do not wanna compress the SST file, please set its value as none. +# [NOTICE] The Pika official binary release just linking the snappy library statically, which means that +# you should compile the Pika from the source code and then link it with other compression algorithm library statically by yourself. +compression : snappy + +# if the vector size is smaller than the level number, the undefined lower level uses the +# last option in the configurable array, for example, for 3 level +# LSM tree the following settings are the same: +# configurable array: [none:snappy] +# LSM settings: [none:snappy:snappy] +# When this configurable is enabled, compression is ignored, +# default l0 l1 noCompression, l2 and more use `compression` option +# https://github.com/facebook/rocksdb/wiki/Compression +#compression_per_level : [none:none:snappy:lz4:lz4] + +# The number of background flushing threads. +# max-background-flushes default value is 1 and the value range is [1, 4]. +max-background-flushes : 1 + +# The number of background compacting threads. +# max-background-compactions default value is 2 and the value range is [1, 8]. +max-background-compactions : 2 + +# The number of background threads. +# max-background-jobs default value is 3 and the value range is [2, 12]. +max-background-jobs : 3 + +# maximum value of RocksDB cached open file descriptors +max-cache-files : 5000 + +# The ratio between the total size of RocksDB level-(L+1) files and the total size of RocksDB level-L files for all L. +# Its default value is 10(x). You can also change it to 5(x). +max-bytes-for-level-multiplier : 10 + +# slotmigrate is mainly used to migrate slots, usually we will set it to no. +# When you migrate slots, you need to set it to yes, and reload slotskeys before. +# slotmigrate [yes | no] +slotmigrate : no + +# slotmigrate thread num +slotmigrate-thread-num : 8 + +# thread-migrate-keys-num 1/8 of the write_buffer_size_ +thread-migrate-keys-num : 64 + +# BlockBasedTable block_size, default 4k +# block-size: 4096 + +# block LRU cache, default 8M, 0 to disable +# Supported Units [K|M|G], default unit [bytes] +# block-cache: 8388608 + +# num-shard-bits default -1, the number of bits from cache keys to be use as shard id. +# The cache will be sharded into 2^num_shard_bits shards. +# https://github.com/EighteenZi/rocksdb_wiki/blob/master/Block-Cache.md#lru-cache +# num-shard-bits: -1 + +# whether the block cache is shared among the RocksDB instances, default is per CF +# share-block-cache: no + +# The slot number of pika when used with codis. +default-slot-num : 1024 + +# whether or not index and filter blocks is stored in block cache +# cache-index-and-filter-blocks: no + +# pin_l0_filter_and_index_blocks_in_cache [yes | no] +# When `cache-index-and-filter-blocks` is enabled, `pin_l0_filter_and_index_blocks_in_cache` is suggested to be enabled +# pin_l0_filter_and_index_blocks_in_cache : no + +# when set to yes, bloomfilter of the last level will not be built +# optimize-filters-for-hits: no +# https://github.com/facebook/rocksdb/wiki/Leveled-Compaction#levels-target-size +# level-compaction-dynamic-level-bytes: no + +################################## RocksDB Rate Limiter ####################### +# rocksdb rate limiter +# https://rocksdb.org/blog/2017/12/18/17-auto-tuned-rate-limiter.html +# https://github.com/EighteenZi/rocksdb_wiki/blob/master/Rate-Limiter.md +#######################################################################E####### + +# rate limiter bandwidth, default 200MB/s +#rate-limiter-bandwidth : 209715200 + +#rate-limiter-refill-period-us : 100000 +# +#rate-limiter-fairness: 10 + +# rate limiter auto tune https://rocksdb.org/blog/2017/12/18/17-auto-tuned-rate-limiter.html. the default value is false. +#rate-limiter-auto-tuned : true + +################################## RocksDB Blob Configure ##################### +# rocksdb blob configure +# https://rocksdb.org/blog/2021/05/26/integrated-blob-db.html +# wiki https://github.com/facebook/rocksdb/wiki/BlobDB +#######################################################################E####### + +# enable rocksdb blob, default no +# enable-blob-files : yes + +# values at or above this threshold will be written to blob files during flush or compaction. +# Supported Units [K|M|G], default unit is in [bytes]. +# min-blob-size : 4K + +# the size limit for blob files +# Supported Units [K|M|G], default unit is in [bytes]. +# blob-file-size : 256M + +# the compression type to use for blob files. All blobs in the same file are compressed using the same algorithm. +# Supported types: [snappy, zlib, lz4, zstd]. If you do not wanna compress the SST file, please set its value as none. +# [NOTICE] The Pika official binary release just link the snappy library statically, which means that +# you should compile the Pika from the source code and then link it with other compression algorithm library statically by yourself. +# blob-compression-type : lz4 + +# set this to open to make BlobDB actively relocate valid blobs from the oldest blob files as they are encountered during compaction. +# The value option is [yes | no] +# enable-blob-garbage-collection : no + +# the cutoff that the GC logic uses to determine which blob files should be considered “old“. +# This parameter can be tuned to adjust the trade-off between write amplification and space amplification. +# blob-garbage-collection-age-cutoff : 0.25 + +# if the ratio of garbage in the oldest blob files exceeds this threshold, +# targeted compactions are scheduled in order to force garbage collecting the blob files in question +# blob_garbage_collection_force_threshold : 1.0 + +# the Cache object to use for blobs, default not open +# blob-cache : 0 + +# blob-num-shard-bits default -1, the number of bits from cache keys to be use as shard id. +# The cache will be sharded into 2^blob-num-shard-bits shards. +# blob-num-shard-bits : -1 + +# Rsync Rate limiting configuration 200MB/s +throttle-bytes-per-second : 207200000 +max-rsync-parallel-num : 4 + +# The synchronization mode of Pika primary/secondary replication is determined by ReplicationID. ReplicationID in one replication_cluster are the same +# replication-id : + +################### +## Cache Settings +################### +# the number of caches for every db +cache-num : 16 + +# cache-model 0:cache_none 1:cache_read +cache-model : 1 +# cache-type: string, set, zset, list, hash, bit +cache-type: string, set, zset, list, hash, bit + +# Maximum number of keys in the zset redis cache +# On the disk DB, a zset field may have many fields. In the memory cache, we limit the maximum +# number of keys that can exist in a zset, which is zset-zset-cache-field-num-per-key, with a +# default value of 512. +zset-cache-field-num-per-key : 512 + +# If the number of elements in a zset in the DB exceeds zset-cache-field-num-per-key, +# we determine whether to cache the first 512[zset-cache-field-num-per-key] elements +# or the last 512[zset-cache-field-num-per-key] elements in the zset based on zset-cache-start-direction. +# +# If zset-cache-start-direction is 0, cache the first 512[zset-cache-field-num-per-key] elements from the header +# If zset-cache-start-direction is -1, cache the last 512[zset-cache-field-num-per-key] elements +zset-cache-start-direction : 0 + +# the cache maxmemory of every db, configuration 10G +cache-maxmemory : 10737418240 + +# cache-maxmemory-policy +# 0: volatile-lru -> Evict using approximated LRU among the keys with an expire set. +# 1: allkeys-lru -> Evict any key using approximated LRU. +# 2: volatile-lfu -> Evict using approximated LFU among the keys with an expire set. +# 3: allkeys-lfu -> Evict any key using approximated LFU. +# 4: volatile-random -> Remove a random key among the ones with an expire set. +# 5: allkeys-random -> Remove a random key, any key. +# 6: volatile-ttl -> Remove the key with the nearest expire time (minor TTL) +# 7: noeviction -> Don't evict anything, just return an error on write operations. +cache-maxmemory-policy : 1 + +# cache-maxmemory-samples +cache-maxmemory-samples: 5 + +# cache-lfu-decay-time +cache-lfu-decay-time: 1 + + +# is possible to manage access to Pub/Sub channels with ACL rules as well. The +# default Pub/Sub channels permission if new users is controlled by the +# acl-pubsub-default configuration directive, which accepts one of these values: +# +# allchannels: grants access to all Pub/Sub channels +# resetchannels: revokes access to all Pub/Sub channels +# +# acl-pubsub-default defaults to 'resetchannels' permission. +# acl-pubsub-default : resetchannels + +# ACL users are defined in the following format: +# user : ... acl rules ... +# +# For example: +# +# user : worker on >password ~key* +@all + +# Using an external ACL file +# +# Instead of configuring users here in this file, it is possible to use +# a stand-alone file just listing users. The two methods cannot be mixed: +# if you configure users here and at the same time you activate the external +# ACL file, the server will refuse to start. +# +# The format of the external ACL user file is exactly the same as the +# format that is used inside pika.conf to describe users. +# +# aclfile : ../conf/users.acl + +# (experimental) +# It is possible to change the name of dangerous commands in a shared environment. +# For instance the CONFIG command may be renamed into something Warning: To prevent +# data inconsistency caused by different configuration files, do not use the rename +# command to modify write commands on the primary and secondary servers. If necessary, +# ensure that the configuration files of the primary and secondary servers are consistent +# In addition, when using the command rename, you must not use "" to modify the command, +# for example, rename-command: FLUSHDB "360flushdb" is incorrect; instead, use +# rename-command: FLUSHDB 360flushdb is correct. After the rename command is executed, +# it is most appropriate to use a numeric string with uppercase or lowercase letters +# for example: rename-command : FLUSHDB joYAPNXRPmcarcR4ZDgC81TbdkSmLAzRPmcarcR +# Warning: Currently only applies to flushdb, slaveof, bgsave, shutdown, config command +# Warning: Ensure that the Settings of rename-command on the master and slave servers are consistent +# +# Example: +# rename-command : FLUSHDB 360flushdb diff --git a/tools/kubeblocks_helm/pika-master-slave-group/script/admin.sh b/tools/kubeblocks_helm/pika-master-slave-group/script/admin.sh new file mode 100644 index 0000000000..6a79247112 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/script/admin.sh @@ -0,0 +1,20 @@ +#! /bin/bash +set -x + +# 获取当前Pod的索引 +INDEX=${HOSTNAME##*-} +echo "index:${INDEX}" +# Redis配置文件路径 +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 : ${KB_POD_FQDN}:9221/" $PIKA_CONF + ../pika/bin/pika -c ../data/pika.conf +fi diff --git a/tools/kubeblocks_helm/pika-master-slave-group/templates/_helpers.tpl b/tools/kubeblocks_helm/pika-master-slave-group/templates/_helpers.tpl new file mode 100644 index 0000000000..5c5c04f6e3 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/templates/_helpers.tpl @@ -0,0 +1,62 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "pika.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.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.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "pika.labels" -}} +helm.sh/chart: {{ include "pika.chart" . }} +{{ include "pika.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "pika.selectorLabels" -}} +app.kubernetes.io/name: {{ include "pika.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Define image +*/}} +{{- define "pika.image" -}} +{{ .Values.image.pika.registry | default "docker.io" }}/{{ .Values.image.pika.repository }}:{{ .Values.image.pika.tag }} +{{- end }} + +{{- define "pika.imagePullPolicy" -}} +{{ .Values.image.pika.pullPolicy | default "IfNotPresent" }} +{{- end }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave-group/templates/clusterdefinition.yaml b/tools/kubeblocks_helm/pika-master-slave-group/templates/clusterdefinition.yaml new file mode 100644 index 0000000000..486d97035c --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/templates/clusterdefinition.yaml @@ -0,0 +1,6 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ClusterDefinition +metadata: + name: pika + labels: + {{- include "pika.labels" . | nindent 4 }} diff --git a/tools/kubeblocks_helm/pika-master-slave-group/templates/componentdefinition-pika.yaml b/tools/kubeblocks_helm/pika-master-slave-group/templates/componentdefinition-pika.yaml new file mode 100644 index 0000000000..ab95de9e73 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/templates/componentdefinition-pika.yaml @@ -0,0 +1,68 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentDefinition +metadata: + name: pika + namespace: {{ .Release.Namespace }} + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + provider: pika + description: Pika component definition + serviceKind: pika + serviceVersion: {{ .Chart.AppVersion }} + services: + - name: pika + spec: + ports: + - name: pika + port: 9221 + targetPort: pika + updateStrategy: Serial + configs: + - name: pika-config + templateRef: pika-conf-template + namespace: {{ .Release.Namespace }} + volumeName: config + scripts: + - name: pika-script + templateRef: pika-script-template + namespace: {{ .Release.Namespace }} + volumeName: script + defaultMode: 0555 + volumes: + - name: data + Vars: + runtime: + initContainers: + - name: init-config + image: busybox:1.28 + imagePullPolicy: IfNotPresent + command: + - /bin/sh + - -ec + - | + if [ ! -f "/data/pika.conf" ];then cp /etc/pika/pika.conf /data/pika.conf; fi + volumeMounts: + - name: config + mountPath: /etc/pika + - name: data + mountPath: /data + containers: + - name: pika + image: {{ include "pika.image" . }} + imagePullPolicy: {{ include "pika.imagePullPolicy" . }} + ports: + - name: pika + containerPort: 9221 + volumeMounts: + - name: config + mountPath: /etc/pika + - name: data + mountPath: /data + - name: script + mountPath: /script + command: + - "/bin/bash" + args: + - "-c" + - "sh /script/admin.sh" \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave-group/templates/componentversion-pika.yaml b/tools/kubeblocks_helm/pika-master-slave-group/templates/componentversion-pika.yaml new file mode 100644 index 0000000000..5d5ccc810c --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/templates/componentversion-pika.yaml @@ -0,0 +1,18 @@ +apiVersion: apps.kubeblocks.io/v1alpha1 +kind: ComponentVersion +metadata: + name: pika + labels: + {{- include "pika.labels" . | nindent 4 }} +spec: + compatibilityRules: + - compDefs: + - pika + releases: + - {{ .Chart.AppVersion }} + releases: + - name: {{ .Chart.AppVersion }} + changes: + serviceVersion: {{ .Chart.AppVersion }} + images: + codis-dashboard: {{ include "pika.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave-group/templates/configmap.yaml b/tools/kubeblocks_helm/pika-master-slave-group/templates/configmap.yaml new file mode 100644 index 0000000000..4053282906 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/templates/configmap.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: pika-conf-template + namespace: {{ .Release.Namespace }} + labels: + {{- include "pika.labels" . | nindent 4 }} +data: + pika.conf: |- + {{- .Files.Get "config/pika-config.tpl" | nindent 4 }} diff --git a/tools/kubeblocks_helm/pika-master-slave-group/templates/script.yaml b/tools/kubeblocks_helm/pika-master-slave-group/templates/script.yaml new file mode 100644 index 0000000000..f378f49f61 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/templates/script.yaml @@ -0,0 +1,10 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: pika-script-template + namespace: {{ .Release.Namespace }} + labels: + {{- include "pika.labels" . | nindent 4 }} +data: + admin.sh: |- + {{- .Files.Get "script/admin.sh" | nindent 4 }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave-group/values.yaml b/tools/kubeblocks_helm/pika-master-slave-group/values.yaml new file mode 100644 index 0000000000..d900fbb05f --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave-group/values.yaml @@ -0,0 +1,16 @@ +pika: + version: v3.5.3 +image: + pika: + registry: docker.io + repository: pikadb/pika + tag: 3.5.3 + pullPolicy: IfNotPresent +roleProbe: + pika: + failureThreshold: 2 + periodSeconds: 1 + timeoutSeconds: 1 +nameOverride: "" +fullnameOverride: "" +clusterDomain: ".cluster.local" diff --git a/tools/kubeblocks_helm/pika-master-slave/.helmignore b/tools/kubeblocks_helm/pika-master-slave/.helmignore new file mode 100644 index 0000000000..0e8a0eb36f --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave/.helmignore @@ -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/ diff --git a/tools/kubeblocks_helm/pika-master-slave/Chart.yaml b/tools/kubeblocks_helm/pika-master-slave/Chart.yaml new file mode 100644 index 0000000000..eb227e1dfb --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave/Chart.yaml @@ -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.3" + +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 diff --git a/tools/kubeblocks_helm/pika-master-slave/templates/_helpers.tpl b/tools/kubeblocks_helm/pika-master-slave/templates/_helpers.tpl new file mode 100644 index 0000000000..314d556c11 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave/templates/_helpers.tpl @@ -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 }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave/templates/cluster.yaml b/tools/kubeblocks_helm/pika-master-slave/templates/cluster.yaml new file mode 100644 index 0000000000..2b34b0d363 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave/templates/cluster.yaml @@ -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.pikaGroup }} + 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 }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave/templates/role.yaml b/tools/kubeblocks_helm/pika-master-slave/templates/role.yaml new file mode 100644 index 0000000000..4792625f6a --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave/templates/role.yaml @@ -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 diff --git a/tools/kubeblocks_helm/pika-master-slave/templates/rolebinding.yaml b/tools/kubeblocks_helm/pika-master-slave/templates/rolebinding.yaml new file mode 100644 index 0000000000..c55a9eb989 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave/templates/rolebinding.yaml @@ -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 }} diff --git a/tools/kubeblocks_helm/pika-master-slave/templates/serviceaccount.yaml b/tools/kubeblocks_helm/pika-master-slave/templates/serviceaccount.yaml new file mode 100644 index 0000000000..439b7d7218 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave/templates/serviceaccount.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "pika-cluster.serviceAccountName" . }} + namespace: {{ .Release.Namespace }} + labels: + {{ include "pika-cluster.labels" . | nindent 4 }} diff --git a/tools/kubeblocks_helm/pika-master-slave/values.yaml b/tools/kubeblocks_helm/pika-master-slave/values.yaml new file mode 100644 index 0000000000..cb451d0b44 --- /dev/null +++ b/tools/kubeblocks_helm/pika-master-slave/values.yaml @@ -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:'. + pikaGroup: + 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: "" From 49c5c4dc6d5a9377b22708f3f27eda687102aae2 Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Wed, 11 Sep 2024 01:44:28 +0800 Subject: [PATCH 09/10] fix admin.sh --- tools/kubeblocks_helm/pika-master-slave-group/script/admin.sh | 4 ++-- .../templates/componentdefinition-pika.yaml | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/tools/kubeblocks_helm/pika-master-slave-group/script/admin.sh b/tools/kubeblocks_helm/pika-master-slave-group/script/admin.sh index 6a79247112..3b4c0864df 100644 --- a/tools/kubeblocks_helm/pika-master-slave-group/script/admin.sh +++ b/tools/kubeblocks_helm/pika-master-slave-group/script/admin.sh @@ -4,7 +4,7 @@ set -x # 获取当前Pod的索引 INDEX=${HOSTNAME##*-} echo "index:${INDEX}" -# Redis配置文件路径 +# PIKA配置文件路径 PIKA_CONF="../data/pika.conf" # 确保配置文件存在 @@ -15,6 +15,6 @@ if [ "$INDEX" = "0" ]; then ../pika/bin/pika -c ../data/pika.conf else # 如果不是pika-0,配置为从节点 - sed -i "s/#slaveof : master-ip:master-port/slaveof : ${KB_POD_FQDN}:9221/" $PIKA_CONF + 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 ../pika/bin/pika -c ../data/pika.conf fi diff --git a/tools/kubeblocks_helm/pika-master-slave-group/templates/componentdefinition-pika.yaml b/tools/kubeblocks_helm/pika-master-slave-group/templates/componentdefinition-pika.yaml index ab95de9e73..1791a955cd 100644 --- a/tools/kubeblocks_helm/pika-master-slave-group/templates/componentdefinition-pika.yaml +++ b/tools/kubeblocks_helm/pika-master-slave-group/templates/componentdefinition-pika.yaml @@ -31,7 +31,6 @@ spec: defaultMode: 0555 volumes: - name: data - Vars: runtime: initContainers: - name: init-config From e790dcea04c6dff716bccce3bcd0cdf3db3fc90b Mon Sep 17 00:00:00 2001 From: XiaoLiang2333 <1159025475@qq.com> Date: Thu, 12 Sep 2024 02:08:27 +0800 Subject: [PATCH 10/10] Add readme about pika-master-slave-group --- tools/kubeblocks_helm/README.md | 20 +++++++++++++++++++ .../templates/componentversion-pika.yaml | 2 +- .../templates/componentversion-codis-fe.yaml | 2 +- .../componentversion-codis-proxy.yaml | 2 +- .../templates/componentversion-pika-etcd.yaml | 2 +- .../componentversion-pika-exporter.yaml | 2 +- .../componentversion-pika-group.yaml | 2 +- 7 files changed, 26 insertions(+), 6 deletions(-) diff --git a/tools/kubeblocks_helm/README.md b/tools/kubeblocks_helm/README.md index c657a4458c..92e127f149 100644 --- a/tools/kubeblocks_helm/README.md +++ b/tools/kubeblocks_helm/README.md @@ -46,3 +46,23 @@ 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-group ./pika-master-slave-group +helm install pika-master-slave ./pika-master-slave-group +``` +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 +```bash +kubectl port-forward svc/pika-master-slave-pika 9221 +#start new terminal +redis-cli -p 9221 +``` \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika-master-slave-group/templates/componentversion-pika.yaml b/tools/kubeblocks_helm/pika-master-slave-group/templates/componentversion-pika.yaml index 5d5ccc810c..4d128810f9 100644 --- a/tools/kubeblocks_helm/pika-master-slave-group/templates/componentversion-pika.yaml +++ b/tools/kubeblocks_helm/pika-master-slave-group/templates/componentversion-pika.yaml @@ -15,4 +15,4 @@ spec: changes: serviceVersion: {{ .Chart.AppVersion }} images: - codis-dashboard: {{ include "pika.image" . }} \ No newline at end of file + pika: {{ include "pika.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml index cf3bb12d6a..1fd76d51b1 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-codis-fe.yaml @@ -15,4 +15,4 @@ spec: changes: serviceVersion: {{ .Chart.AppVersion }} images: - codis-dashboard: {{ include "codis.image" . }} \ No newline at end of file + codis-fe: {{ include "codis.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml index 98349009d9..29a6d3e17a 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-codis-proxy.yaml @@ -15,4 +15,4 @@ spec: changes: serviceVersion: {{ .Chart.AppVersion }} images: - codis-dashboard: {{ include "codis.image" . }} \ No newline at end of file + codis-proxy: {{ include "codis.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml index 3a03709a84..21b1ce2a84 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-pika-etcd.yaml @@ -15,4 +15,4 @@ spec: changes: serviceVersion: {{ .Chart.AppVersion }} images: - codis-dashboard: {{ include "etcd.image" . }} \ No newline at end of file + pika-etcd: {{ include "etcd.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml index 38b211e93d..1acd20d312 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-pika-exporter.yaml @@ -15,4 +15,4 @@ spec: changes: serviceVersion: {{ .Chart.AppVersion }} images: - codis-dashboard: {{ include "pikaExporter.image" . }} \ No newline at end of file + pika-exporter: {{ include "pikaExporter.image" . }} \ No newline at end of file diff --git a/tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml b/tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml index c07145d60a..7b909941fa 100644 --- a/tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml +++ b/tools/kubeblocks_helm/pika/templates/componentversion-pika-group.yaml @@ -15,4 +15,4 @@ spec: changes: serviceVersion: {{ .Chart.AppVersion }} images: - codis-dashboard: {{ include "pika.image" . }} \ No newline at end of file + pika-group: {{ include "pika.image" . }} \ No newline at end of file