From f39ec34d7d7a51bef6155292202b6707b4af7e84 Mon Sep 17 00:00:00 2001 From: gjmzj Date: Wed, 30 Jan 2019 21:23:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0helm=E9=83=A8=E7=BD=B2redis-h?= =?UTF-8?q?a=E9=9B=86=E7=BE=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifests/mariadb-cluster/my-values.yaml | 10 +- manifests/redis-cluster/my-values.yaml | 120 ++++++++++++ manifests/redis-cluster/redis-ha/Chart.yaml | 20 ++ manifests/redis-cluster/redis-ha/OWNERS | 4 + manifests/redis-cluster/redis-ha/README.md | 117 +++++++++++ .../redis-ha/templates/NOTES.txt | 25 +++ .../redis-ha/templates/_helpers.tpl | 53 +++++ .../redis-ha/templates/redis-auth-secret.yaml | 11 ++ .../templates/redis-ha-announce-service.yaml | 33 ++++ .../templates/redis-ha-configmap.yaml | 137 +++++++++++++ .../templates/redis-ha-healthchecks.yaml | 41 ++++ .../redis-ha/templates/redis-ha-pdb.yaml | 14 ++ .../redis-ha/templates/redis-ha-service.yaml | 25 +++ .../templates/redis-ha-statefulset.yaml | 183 ++++++++++++++++++ .../tests/test-redis-ha-configmap.yaml | 36 ++++ .../tests/test-redis-ha-service.yaml | 17 ++ manifests/redis-cluster/redis-ha/values.yaml | 120 ++++++++++++ 17 files changed, 961 insertions(+), 5 deletions(-) create mode 100644 manifests/redis-cluster/my-values.yaml create mode 100644 manifests/redis-cluster/redis-ha/Chart.yaml create mode 100644 manifests/redis-cluster/redis-ha/OWNERS create mode 100644 manifests/redis-cluster/redis-ha/README.md create mode 100644 manifests/redis-cluster/redis-ha/templates/NOTES.txt create mode 100644 manifests/redis-cluster/redis-ha/templates/_helpers.tpl create mode 100644 manifests/redis-cluster/redis-ha/templates/redis-auth-secret.yaml create mode 100644 manifests/redis-cluster/redis-ha/templates/redis-ha-announce-service.yaml create mode 100644 manifests/redis-cluster/redis-ha/templates/redis-ha-configmap.yaml create mode 100644 manifests/redis-cluster/redis-ha/templates/redis-ha-healthchecks.yaml create mode 100644 manifests/redis-cluster/redis-ha/templates/redis-ha-pdb.yaml create mode 100644 manifests/redis-cluster/redis-ha/templates/redis-ha-service.yaml create mode 100644 manifests/redis-cluster/redis-ha/templates/redis-ha-statefulset.yaml create mode 100644 manifests/redis-cluster/redis-ha/templates/tests/test-redis-ha-configmap.yaml create mode 100644 manifests/redis-cluster/redis-ha/templates/tests/test-redis-ha-service.yaml create mode 100644 manifests/redis-cluster/redis-ha/values.yaml diff --git a/manifests/mariadb-cluster/my-values.yaml b/manifests/mariadb-cluster/my-values.yaml index 49ced55..403cb9b 100644 --- a/manifests/mariadb-cluster/my-values.yaml +++ b/manifests/mariadb-cluster/my-values.yaml @@ -98,7 +98,7 @@ replication: ## MariaDB replication user password ## ref: https://github.com/bitnami/bitnami-docker-mariadb#setting-up-a-replication-cluster ## - password: replicator + password: R4%forep11CAT0r ## Password is ignored if existingSecret is specified. ## ## Option to force users to specify a password. That is required for 'helm upgrade' to work properly. @@ -167,7 +167,7 @@ master: - ReadWriteOnce ## Persistent Volume size ## - size: 8Gi + size: 5Gi ## extraInitContainers: | # - name: do-something @@ -228,7 +228,7 @@ master: failureThreshold: 3 slave: - replicas: 2 + replicas: 1 ## Mariadb Slave additional pod annotations @@ -262,7 +262,7 @@ slave: - ReadWriteOnce ## Persistent Volume size ## - size: 8Gi + size: 5Gi ## extraInitContainers: | # - name: do-something @@ -324,7 +324,7 @@ slave: failureThreshold: 3 metrics: - enabled: true + enabled: false image: registry: docker.io repository: prom/mysqld-exporter diff --git a/manifests/redis-cluster/my-values.yaml b/manifests/redis-cluster/my-values.yaml new file mode 100644 index 0000000..1dc1dc6 --- /dev/null +++ b/manifests/redis-cluster/my-values.yaml @@ -0,0 +1,120 @@ +## Configure resource requests and limits +## ref: http://kubernetes.io/docs/user-guide/compute-resources/ +## +image: + repository: redis + tag: 5.0.3-alpine + pullPolicy: IfNotPresent +## replicas number for each component +replicas: 2 + +## Redis specific configuration options +redis: + port: 6379 + masterGroupName: mymaster + config: + ## Additional redis conf options can be added below + ## For all available options see http://download.redis.io/redis-stable/redis.conf + min-slaves-to-write: 1 + min-slaves-max-lag: 5 # Value in seconds + maxmemory: "1g" # Max memory to use for each redis instance. Default is unlimited. + maxmemory-policy: "allkeys-lru" # Max memory policy to use for each redis instance. Default is volatile-lru. + # Determines if scheduled RDB backups are created. Default is false. + # Please note that local (on-disk) RDBs will still be created when re-syncing with a new slave. The only way to prevent this is to enable diskless replication. + # save: "900 1" + # When enabled, directly sends the RDB over the wire to slaves, without using the disk as intermediate storage. Default is false. + repl-diskless-sync: "yes" + rdbcompression: "yes" + rdbchecksum: "yes" + + ## Custom redis.conf files used to override default settings. If this file is + ## specified then the redis.config above will be ignored. + # customConfig: |- + # Define configuration here + + resources: + requests: + memory: 500Mi + cpu: 100m + limits: + memory: 1100Mi + +## Sentinel specific configuration options +sentinel: + port: 26379 + quorum: 1 + config: + ## Additional sentinel conf options can be added below. Only options that + ## are expressed in the format simialar to 'sentinel xxx mymaster xxx' will + ## be properly templated. + ## For available options see http://download.redis.io/redis-stable/sentinel.conf + down-after-milliseconds: 10000 + ## Failover timeout value in milliseconds + failover-timeout: 180000 + parallel-syncs: 5 + + ## Custom sentinel.conf files used to override default settings. If this file is + ## specified then the sentinel.config above will be ignored. + # customConfig: |- + # Define configuration here + + resources: + requests: + memory: 200Mi + cpu: 100m + limits: + memory: 200Mi + +securityContext: + runAsUser: 1000 + fsGroup: 1000 + runAsNonRoot: true + +## Node labels, affinity, and tolerations for pod assignment +## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#nodeselector +## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#taints-and-tolerations-beta-feature +## ref: https://kubernetes.io/docs/concepts/configuration/assign-pod-node/#affinity-and-anti-affinity +affinity: | + podAntiAffinity: + requiredDuringSchedulingIgnoredDuringExecution: + - labelSelector: + matchLabels: + app: {{ template "redis-ha.name" . }} + release: {{ .Release.Name }} + topologyKey: kubernetes.io/hostname + preferredDuringSchedulingIgnoredDuringExecution: + - weight: 100 + podAffinityTerm: + labelSelector: + matchLabels: + app: {{ template "redis-ha.name" . }} + release: {{ .Release.Name }} + topologyKey: failure-domain.beta.kubernetes.io/zone + +podDisruptionBudget: {} + # maxUnavailable: 1 + # minAvailable: 1 + +## Configures redis with AUTH (requirepass & masterauth conf params) +auth: true +redisPassword: redis1234 + +## Use existing secret containing "auth" key (ignores redisPassword) +# existingSecret: + +persistentVolume: + enabled: false + ## redis-ha data Persistent Volume Storage Class + ## If defined, storageClassName: + ## If set to "-", storageClassName: "", which disables dynamic provisioning + ## If undefined (the default) or set to null, no storageClassName spec is + ## set, choosing the default provisioner. (gp2 on AWS, standard on + ## GKE, AWS & OpenStack) + ## + storageClass: "nfs-db" + accessModes: + - ReadWriteOnce + size: 3Gi + annotations: {} +init: + resources: {} diff --git a/manifests/redis-cluster/redis-ha/Chart.yaml b/manifests/redis-cluster/redis-ha/Chart.yaml new file mode 100644 index 0000000..be92ddb --- /dev/null +++ b/manifests/redis-cluster/redis-ha/Chart.yaml @@ -0,0 +1,20 @@ +name: redis-ha +home: http://redis.io/ +engine: gotpl +keywords: +- redis +- keyvalue +- database +version: 3.1.3 +appVersion: 5.0.3 +description: Highly available Kubernetes implementation of Redis +icon: https://upload.wikimedia.org/wikipedia/en/thumb/6/6b/Redis_Logo.svg/1200px-Redis_Logo.svg.png +maintainers: +- email: salimsalaues@gmail.com + name: ssalaues +details: + This Helm chart provides a highly available Redis implementation with a master/slave configuration + and uses Sentinel sidecars for failover management +sources: +- https://redis.io/download +- https://github.com/scality/Zenko/tree/development/1.0/kubernetes/zenko/charts/redis-ha diff --git a/manifests/redis-cluster/redis-ha/OWNERS b/manifests/redis-cluster/redis-ha/OWNERS new file mode 100644 index 0000000..c1ffbbc --- /dev/null +++ b/manifests/redis-cluster/redis-ha/OWNERS @@ -0,0 +1,4 @@ +approvers: +- ssalaues +reviewers: +- ssalaues diff --git a/manifests/redis-cluster/redis-ha/README.md b/manifests/redis-cluster/redis-ha/README.md new file mode 100644 index 0000000..9a16ff6 --- /dev/null +++ b/manifests/redis-cluster/redis-ha/README.md @@ -0,0 +1,117 @@ +# Redis + +[Redis](http://redis.io/) is an advanced key-value cache and store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets, sorted sets, bitmaps and hyperloglogs. + +## TL;DR; + +```bash +$ helm install stable/redis-ha +``` + +By default this chart install 3 pods total: + * one pod containing a redis master and sentinel containers + * two pods each containing redis slave and sentinel containers. + +## Introduction + +This chart bootstraps a [Redis](https://redis.io) highly available master/slave statefulset in a [Kubernetes](http://kubernetes.io) cluster using the Helm package manager. + +## Prerequisites + +- Kubernetes 1.8+ with Beta APIs enabled +- PV provisioner support in the underlying infrastructure + +## Upgrading the Chart + +Please note that there have been a number of changes simplifying the redis management strategy (for better failover and elections) in the 3.x version of this chart. These changes allow the use of official [redis](https://hub.docker.com/_/redis/) images that do not require special RBAC or ServiceAccount roles. As a result when upgrading from version >=2.0.1 to >=3.0.0 of this chart, `Role`, `RoleBinding`, and `ServiceAccount` resources should be deleted manually. + +## Installing the Chart + +To install the chart + +```bash +$ helm install stable/redis-ha +``` + +The command deploys Redis on the Kubernetes cluster in the default configuration. By default this chart install one master pod containing redis master container and sentinel container along with 2 redis slave pods each containing their own sentinel sidecars. The [configuration](#configuration) section lists the parameters that can be configured during installation. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the deployment: + +```bash +$ helm delete +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +The following table lists the configurable parameters of the Redis chart and their default values. + +| Parameter | Description | Default | +| -------------------------------- | ----------------------------------------------------- | --------------------------------------------------------- | +| `image` | Redis image | `redis` | +| `tag` | Redis tag | `5.0.3-alpine` | +| `replicas` | Number of redis master/slave pods | `3` | +| `redis.port` | Port to access the redis service | `6379` | +| `redis.masterGroupName` | Redis convention for naming the cluster group | `mymaster` | +| `redis.config` | Any valid redis config options in this section will be applied to each server (see below) | see values.yaml | +| `redis.customConfig` | Allows for custom redis.conf files to be applied. If this is used then `redis.config` is ignored | `` | +| `redis.resources` | CPU/Memory for master/slave nodes resource requests/limits | `{}` | +| `sentinel.port` | Port to access the sentinel service | `26379` | +| `sentinel.quorum` | Minimum number of servers necessary to maintain quorum | `2` | +| `sentinel.config` | Valid sentinel config options in this section will be applied as config options to each sentinel (see below) | see values.yaml | +| `sentinel.customConfig` | Allows for custom sentinel.conf files to be applied. If this is used then `sentinel.config` is ignored | `` | +| `sentinel.resources` | CPU/Memory for sentinel node resource requests/limits | `{}` | +| `init.resources` | CPU/Memory for init Container node resource requests/limits | `{}` +| `auth` | Enables or disables redis AUTH (Requires `redisPassword` to be set) | `false` | +| `redisPassword` | A password that configures a `requirepass` and `masterauth` in the conf parameters (Requires `auth: enabled`) | `` | +| `existingSecret` | An existing secret containing an `auth` key that configures `requirepass` and `masterauth` in the conf parameters (Requires `auth: enabled`, cannot be used in conjunction with `.Values.redisPassword`) | `` | +| `nodeSelector` | Node labels for pod assignment | `{}` | +| `tolerations` | Toleration labels for pod assignment | `[]` | +| `podAntiAffinity.server` | Antiaffinity for pod assignment of servers, `hard` or `soft` | `Hard node and soft zone anti-affinity` | + + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```bash +$ helm install \ + --set image=redis \ + --set tag=5.0.3-alpine \ + stable/redis-ha +``` + +The above command sets the Redis server within `default` namespace. + +Alternatively, a YAML file that specifies the values for the parameters can be provided while installing the chart. For example, + +```bash +$ helm install -f values.yaml stable/redis-ha +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) + +## Custom Redis and Sentinel config options + +This chart allows for most redis or sentinel config options to be passed as a key value pair through the `values.yaml` under `redis.config` and `sentinel.config`. See links below for all available options. + +[Example redis.conf](http://download.redis.io/redis-stable/redis.conf) +[Example sentinel.conf](http://download.redis.io/redis-stable/sentinel.conf) + +For example `repl-timeout 60` would be added to the `redis.config` section of the `values.yaml` as: + +```yml + repl-timeout: "60" +``` + +Sentinel options supported must be in the the `sentinel