From 7a3fb5baa861707238ccdeb2bb65da6241c559c0 Mon Sep 17 00:00:00 2001 From: Igor Koshchyts Date: Thu, 21 Nov 2024 14:50:42 -0800 Subject: [PATCH 1/2] fixing redis cluster to use dns instead of ip --- examples/redis/scripts/redis-start.sh | 26 +---------------------- examples/redis/templates/redis-start.yaml | 2 +- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/examples/redis/scripts/redis-start.sh b/examples/redis/scripts/redis-start.sh index 73b1390..5f0df5a 100644 --- a/examples/redis/scripts/redis-start.sh +++ b/examples/redis/scripts/redis-start.sh @@ -4,57 +4,41 @@ set -ex cp /usr/local/etc/redis/redis-default.conf /usr/local/etc/redis/redis.conf - ip=$(hostname -I) # Find which member of the Stateful Set this pod is running - # e.g. "redis-cluster-0" -> "0" - PET_ORDINAL=$(echo "$POD_NAME" | rev | cut -d'-' -f 1 | rev) - WORKLOAD_NAME=$(echo $CPLN_WORKLOAD | sed 's|.*/workload/\([^/]*\)$|\1|') - NODE_LIST="" echo "" >> /usr/local/etc/redis/redis.conf - -echo "cluster-announce-ip $ip" >> /usr/local/etc/redis/redis.conf - +echo "cluster-announce-ip $WORKLOAD_NAME-$PET_ORDINAL.$WORKLOAD_NAME" >> /usr/local/etc/redis/redis.conf redis-server /usr/local/etc/redis/redis.conf > /dev/null 2>&1 & - sleep 10 # Waiting for redis to become Healthy - while true; do - response=$(redis-cli ping 2>&1) - # Check if the response is "PONG" - if [[ "$response" == *"PONG"* ]]; then echo "Redis node is HEALTHY" break else echo "Waiting for Redis node to become healthy" fi - sleep 5 done # Construct NODE_LIST - for (( i=0; i&1) || true - # Check if the response is "PONG" - if [[ "$response" == *"PONG"* ]]; then echo "Node $i is HEALTHY. Received PONG." else @@ -83,10 +62,8 @@ else done # If this is replica *-0, all nodes are healthy, and the cluster is not initiated, create the cluster - if [[ $PET_ORDINAL == 0 && "$all_nodes_healthy" == true ]]; then cluster_status=$(redis-cli cluster info | grep "cluster_state" | cut -d':' -f2 | tr -d '\r') - if [ "$cluster_status" = "ok" ]; then echo "All nodes are healthy and cluster status is OK." break @@ -98,7 +75,6 @@ else fi # Short delay before restarting loop - sleep 5 done fi diff --git a/examples/redis/templates/redis-start.yaml b/examples/redis/templates/redis-start.yaml index 30a2ca4..7e99f1b 100644 --- a/examples/redis/templates/redis-start.yaml +++ b/examples/redis/templates/redis-start.yaml @@ -5,5 +5,5 @@ tags: {} type: opaque data: encoding: plain - payload: > + payload: |- {{ .Files.Get "scripts/redis-start.sh" | indent 4 }} \ No newline at end of file From 65848ab91582e9afb208a11bed658d3baf40e979 Mon Sep 17 00:00:00 2001 From: Igor Koshchyts Date: Thu, 21 Nov 2024 16:24:46 -0800 Subject: [PATCH 2/2] add single-node helm --- examples/redis/{ => cluster}/Chart.yaml | 0 examples/redis/{ => cluster}/README.md | 2 +- .../{ => cluster}/scripts/redis-start.sh | 0 .../redis-cluster-default-config.yaml | 0 .../templates/redis-cluster.yaml | 0 .../{ => cluster}/templates/redis-start.yaml | 0 examples/redis/{ => cluster}/values.yaml | 0 examples/redis/single-node/Chart.yaml | 6 ++ examples/redis/single-node/README.md | 51 ++++++++++++ .../single-node/templates/volumeset.yaml | 14 ++++ .../redis/single-node/templates/workload.yaml | 81 +++++++++++++++++++ examples/redis/single-node/values.yaml | 29 +++++++ 12 files changed, 182 insertions(+), 1 deletion(-) rename examples/redis/{ => cluster}/Chart.yaml (100%) rename examples/redis/{ => cluster}/README.md (94%) rename examples/redis/{ => cluster}/scripts/redis-start.sh (100%) rename examples/redis/{ => cluster}/templates/redis-cluster-default-config.yaml (100%) rename examples/redis/{ => cluster}/templates/redis-cluster.yaml (100%) rename examples/redis/{ => cluster}/templates/redis-start.yaml (100%) rename examples/redis/{ => cluster}/values.yaml (100%) create mode 100644 examples/redis/single-node/Chart.yaml create mode 100644 examples/redis/single-node/README.md create mode 100644 examples/redis/single-node/templates/volumeset.yaml create mode 100644 examples/redis/single-node/templates/workload.yaml create mode 100644 examples/redis/single-node/values.yaml diff --git a/examples/redis/Chart.yaml b/examples/redis/cluster/Chart.yaml similarity index 100% rename from examples/redis/Chart.yaml rename to examples/redis/cluster/Chart.yaml diff --git a/examples/redis/README.md b/examples/redis/cluster/README.md similarity index 94% rename from examples/redis/README.md rename to examples/redis/cluster/README.md index 3f29b4d..e85c457 100644 --- a/examples/redis/README.md +++ b/examples/redis/cluster/README.md @@ -8,7 +8,7 @@ This example creates a Redis cluster with 6 nodes on the Control Plane Platform The [Helm CLI](https://helm.sh/docs/intro/install/#through-package-managers) and [Control Plane CLI](https://docs.controlplane.com/reference/cli#install-npm) must be installed. -1. Clone this repo and update the [values.yaml](./values.yaml) file as needed. +1. Clone this repo and update the [values.yaml](redis-clsuter/values.yaml) file as needed. 2. Run the command below from this directory. diff --git a/examples/redis/scripts/redis-start.sh b/examples/redis/cluster/scripts/redis-start.sh similarity index 100% rename from examples/redis/scripts/redis-start.sh rename to examples/redis/cluster/scripts/redis-start.sh diff --git a/examples/redis/templates/redis-cluster-default-config.yaml b/examples/redis/cluster/templates/redis-cluster-default-config.yaml similarity index 100% rename from examples/redis/templates/redis-cluster-default-config.yaml rename to examples/redis/cluster/templates/redis-cluster-default-config.yaml diff --git a/examples/redis/templates/redis-cluster.yaml b/examples/redis/cluster/templates/redis-cluster.yaml similarity index 100% rename from examples/redis/templates/redis-cluster.yaml rename to examples/redis/cluster/templates/redis-cluster.yaml diff --git a/examples/redis/templates/redis-start.yaml b/examples/redis/cluster/templates/redis-start.yaml similarity index 100% rename from examples/redis/templates/redis-start.yaml rename to examples/redis/cluster/templates/redis-start.yaml diff --git a/examples/redis/values.yaml b/examples/redis/cluster/values.yaml similarity index 100% rename from examples/redis/values.yaml rename to examples/redis/cluster/values.yaml diff --git a/examples/redis/single-node/Chart.yaml b/examples/redis/single-node/Chart.yaml new file mode 100644 index 0000000..69d86bb --- /dev/null +++ b/examples/redis/single-node/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: redis +description: A single replica Redis helm chart for Control Plan +type: application +version: 0.1.0 +appVersion: "1.0.0" diff --git a/examples/redis/single-node/README.md b/examples/redis/single-node/README.md new file mode 100644 index 0000000..e85c457 --- /dev/null +++ b/examples/redis/single-node/README.md @@ -0,0 +1,51 @@ +## Redis example + +This example creates a Redis cluster with 6 nodes on the Control Plane Platform and can be further customized as needed. + +### Steps to run this example: + +**HELM** + +The [Helm CLI](https://helm.sh/docs/intro/install/#through-package-managers) and [Control Plane CLI](https://docs.controlplane.com/reference/cli#install-npm) must be installed. + +1. Clone this repo and update the [values.yaml](redis-clsuter/values.yaml) file as needed. + +2. Run the command below from this directory. + + ```bash + cpln helm install redis-cluster --gvc mygvc + ``` + Note: Typically, it takes 5 minutes for all replicas of the workload to become ready and for the cluster to be created. + +### Accessing redis-cluster + +Workloads are allowed to access Redis Cluster based on the `firewallConfig` you specify. You can learn more about in our [documentation](https://docs.controlplane.com/reference/workload#internal). + +Improtant: To access workloads listening on a TCP port, the client workload must be in the same GVC. Thus, the Redis cluster is accessible to clients running within the same GVC. + +#### Option 1: + +Syntax: +``` +redis-cli -c -h redis-cluster -p 6379 set mykey "test" +redis-cli -c -h redis-cluster -p 6379 get mykey +``` +#### Option 2: (By replica) + +Syntax: . +``` +redis-cli -c -h redis-cluster-0.redis-cluster -p 6379 set mykey "test" +redis-cli -c -h redis-cluster-1.redis-cluster -p 6379 get mykey +redis-cli -c -h redis-cluster-2.redis-cluster -p 6379 get mykey +redis-cli -c -h redis-cluster-3.redis-cluster -p 6379 get mykey +redis-cli -c -h redis-cluster-4.redis-cluster -p 6379 get mykey +redis-cli -c -h redis-cluster-5.redis-cluster -p 6379 get mykey +``` + +### Cleanup + +**HELM** + +```bash +cpln helm uninstall redis-cluster +``` diff --git a/examples/redis/single-node/templates/volumeset.yaml b/examples/redis/single-node/templates/volumeset.yaml new file mode 100644 index 0000000..49b3f61 --- /dev/null +++ b/examples/redis/single-node/templates/volumeset.yaml @@ -0,0 +1,14 @@ +{{- if .Values.volumeset }} +kind: volumeset +name: volumeset-{{ .Values.name }} +description: volumeset-{{ .Values.name }} +tags: {} +spec: + fileSystemType: {{ .Values.volumeset.volume.fileSystemType }} + initialCapacity: {{ .Values.volumeset.volume.initialCapacity }} + performanceClass: {{ .Values.volumeset.volume.performanceClass }} + snapshots: + createFinalSnapshot: {{ .Values.volumeset.snapshots.createFinalSnapshot }} + retentionDuration: {{ .Values.volumeset.snapshots.retentionDuration }} + schedule: {{ .Values.volumeset.snapshots.schedule }} +{{- end }} \ No newline at end of file diff --git a/examples/redis/single-node/templates/workload.yaml b/examples/redis/single-node/templates/workload.yaml new file mode 100644 index 0000000..0b8cfa6 --- /dev/null +++ b/examples/redis/single-node/templates/workload.yaml @@ -0,0 +1,81 @@ +kind: workload +name: {{ .Values.name }} +gvc: {{ .Values.cpln.gvc }} +description: {{ .Values.name }} +spec: + type: stateful + containers: + - name: {{ .Values.name }} + cpu: '{{ .Values.cpu }}' + memory: {{ .Values.memory }} + env: + - name: CUSTOM_REDIS_PORT + value: '{{ .Values.port }}' + image: {{ .Values.image.repository }} + livenessProbe: + exec: + command: + - /bin/bash + - '-c' + - redis-cli ping + failureThreshold: 10 + initialDelaySeconds: 25 + periodSeconds: 5 + successThreshold: 1 + timeoutSeconds: 4 + readinessProbe: + exec: + command: + - /bin/bash + - '-c' + - redis-cli ping + failureThreshold: 10 + initialDelaySeconds: 20 + periodSeconds: 5 + successThreshold: 1 + timeoutSeconds: 4 + inheritEnv: {{ .Values.inheritEnv }} + ports: + - number: {{ .Values.port }} + protocol: tcp + volumes: + {{- if .Values.volumeset }} + - path: /data + recoveryPolicy: retain + uri: 'cpln://volumeset/volumeset-{{ .Values.name }}' + {{- else }} + [] + {{- end }} + defaultOptions: + autoscaling: + maxConcurrency: 0 + maxScale: 1 + metric: disabled + minScale: 1 + scaleToZeroDelay: 300 + target: 100 + capacityAI: {{ .Values.capacityAI}} + debug: false + suspend: false + timeoutSeconds: 5 +{{- if .Values.firewall }} + firewallConfig: + {{- if or (hasKey .Values.firewall "external_inboundAllowCIDR") (hasKey .Values.firewall "external_outboundAllowCIDR") }} + external: + inboundAllowCIDR: {{- if .Values.firewall.external_inboundAllowCIDR }}{{ .Values.firewall.external_inboundAllowCIDR | splitList "," | toYaml | nindent 8 }}{{- else }} []{{- end }} + outboundAllowCIDR: {{- if .Values.firewall.external_outboundAllowCIDR }}{{ .Values.firewall.external_outboundAllowCIDR | splitList "," | toYaml | nindent 8 }}{{- else }} []{{- end }} + {{- end }} + {{- if hasKey .Values.firewall "internal_inboundAllowType" }} + internal: + inboundAllowType: {{ default "[]" .Values.firewall.internal_inboundAllowType }} + {{- end }} +{{- end }} + localOptions: [] + rolloutOptions: + maxSurgeReplicas: 25% + maxUnavailableReplicas: '1' + minReadySeconds: 0 + scalingPolicy: OrderedReady + securityOptions: + filesystemGroupId: 1001 + supportDynamicTags: {{ .Values.supportDynamicTags }} \ No newline at end of file diff --git a/examples/redis/single-node/values.yaml b/examples/redis/single-node/values.yaml new file mode 100644 index 0000000..42856d4 --- /dev/null +++ b/examples/redis/single-node/values.yaml @@ -0,0 +1,29 @@ +# Default values for redis-cluster. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +image: + repository: docker.io/redis:7.2 + +name: redis-dev-empty +port: 6379 +diskCapacity: 20 # In Gigabytes +memory: 250Mi # EX. 3000Mi = 3Gi +cpu: 200m # vCPU or milicores with; EX. 1.5 = 1500m +inheritEnv: false +capacityAI: false +firewall: + internal_inboundAllowType: "same-org" # Options: same-org / same-gvc(Recommended) + # external_inboundAllowCIDR: 0.0.0.0/0 # Provide a comma-separated list + # external_outboundAllowCIDR: "0.0.0.0/0" # "111.222.333.444/16,111.222.444.333/32" # Provide a comma-separated list +supportDynamicTags: false +timeoutSeconds: 30 +volumeset: {} + # volume: + # initialCapacity: 25 # In Gigabytes. For high-throughput-ssd minimum is '1000' + # fileSystemType: ext4 # ext4 / xfs + # performanceClass: general-purpose-ssd # high-throughput-ssd / general-purpose-ssd + # snapshots: + # createFinalSnapshot: 'true' + # retentionDuration: 7d + # schedule: '0 1 * * *'