This document describes how to improve the performance of your Redis workloads on Google Kubernetes Engine (GKE) by generating optimized application-level and node-level configurations. For more details, see Optimize for workloads on GKE.
The optimizations for Redis were determined for a Redis 7 instance being used as a single-node look-aside cache with a read-write ratio of 4:1 (4 reads to 1 write), with performance measured using Memtier 2.2.1. Consider how the Redis workload is used on your cluster compared to this use case. If your use case differs, then the recommended optimizations might need to be adjusted for your context.
Before you begin
Before you start, make sure that you have performed the following tasks:
- Enable the GKE Recommender API and the Google Kubernetes Engine API. Enable APIs
- To use the Google Cloud CLI for this task,
install and then
initialize the
gcloud CLI. If you previously installed the gcloud CLI, get the latest
version by running the
gcloud components updatecommand. Earlier gcloud CLI versions might not support running the commands in this document.
Requirements
Use GKE version 1.31.1-gke.12000 or later.
Optimize for Redis workloads
We recommend using a dedicated node pool for your Redis workload. By default, a new node pool is created when you complete the following steps.
To optimize the performance of a Redis workload, do the following:
Create the manifests with optimizations for the Redis workload by doing the following:
Generate manifests with recommended optimizations by running the following command:
gcloud container workload profiles manifests create \ --workload=redis-7-caching \ --cluster-version=CLUSTER_VERSION \ --options=machineType=MACHINE_TYPE \ --output-path=/tmp/manifests.yamlReplace the following:
CLUSTER_VERSION: the GKE version. Recommendation is GKE version 1.31.1-gke.12000 or later.MACHINE_TYPE: the wanted machine type.
The
--output-path=/tmp/manifests.yamlflag is optional. If it is not specified, then the manifests are printed to the terminal, but are not saved to a file.This command generates a single YAML file containing two Kubernetes resources:
- A ConfigMap specifying a Redis config named
redis.conf. - A ComputeClass object. This specifies machines for Redis to run on, which is optional. For details about how machine types are specified, see About custom ComputeClasses
The following is a sample of the generated manifest:
apiVersion: v1 kind: ConfigMap metadata: name: redis.conf data: redis.conf: | io-threads 2 io-threads-do-reads yes save "" --- apiVersion: cloud.google.com/v1 kind: ComputeClass metadata: generateName: optimized-gke-redis-7-caching- spec: nodePoolAutoCreation: enabled: true priorities: - machineType: c4-standard-4 whenUnsatisfiable: DoNotScaleUpReview the recommendations and modify the manifests so that they include your preferred optimizations. To assess the recommendations, you can do the following:
- Review the Redis documentation to assess the recommended configuration for your context.
- Consider how the Redis workload is used on your cluster compared to the following use case. If your use case differs, then the recommended optimizations might need to be adjusted for your context.
The optimizations for Redis were determined for a Redis 7 instance being used as a single-node look-aside cache with a read-write ratio of 4:1 (4 reads to 1 write), with performance measured using Memtier 2.2.1.
Edit the manifest file if you want to modify the configuration or add to the configuration.
Apply the manifests to the cluster by using the following command:
kubectl create -f /tmp/manifests.yaml
Deploy a Pod referencing the optimizations. For example:
apiVersion: v1 kind: Pod metadata: name: redis spec: containers: - name: redis image: redis:7 args: - /etc/gke/optimization/redis.conf volumeMounts: - name: gke-optimized-workload-config subPath: redis.conf mountPath: /etc/gke/optimization/redis.conf readOnly: true volumes: - name: gke-optimized-workload-config configMap: name: redis.conf nodeSelector: cloud.google.com/compute-class: optimized-gke-redis-7-caching-abc123Then, apply your Pod manifest to the cluster:
kubectl apply -f pod.yamlConfirm Redis is using the optimized configuration. To do so, you can run the following command to ensure Redis is using the optimized configuration:
kubectl exec redis -- redis-cli INFO server | grep config_fileYou should see an output similar to the following:
config_file:/etc/gke/optimization/redis.confYou can also use the
redis-clicommand to query the individual directives that are set in the optimized configuration, such asio-threads.
When you deploy the workload, the cluster creates a new node pool that adheres to the optimized configuration, and assigns your Pods to those node pools.
Pods that already exist are not modified. Only Pods that reference the optimized configurations are optimized. If you have previously deployed Redis workloads in your cluster, then you need to redeploy these workloads to run them with the optimized configurations.
What's next
- Learn more about workload optimization on GKE.
- Learn more about how to Deploy a Redis cluster on GKE
- Learn more about GKE ComputeClasses.
- To optimize for MySQL workloads, see Optimize MySQL workload performance on GKE.