3.6 KiB
Deploy a Redis cluster on GKE
Objectives
This tutorial covers the following steps:
- Create a GKE cluster.
- Create a Redis Cluster on GKE.
- Confirm the redis is up and running.
- Confirm creation of the volumes for the stateful set.
- Confirm the Pod Disruption Budget (PDB).
Estimated time:
To get started, click Start.
select/create a project
Install Terraform 1.7.4+ version
Install recent version of Terraform by executing following commands:
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor --batch --yes -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
Create the Autopilot GKE cluster
-
Change to the
autopilot-clusterdirectory.cd autopilot-cluster -
Create a new file
terraform.tfvarsin that directory.touch terraform.tfvars -
Open the file for editing.
-
Paste the following content in the file and update any value as needed.
project_id = "<walkthrough-project-name/>"
cluster_name = "gke-patterns-cluster"
cluster_create = {
deletion_protection = false
labels = {
pattern = "redis-cluster"
}
}
region = "europe-west1"
vpc_create = { }
-
Initialize the terraform configuration.
terraform init -
Apply the terraform configuration.
terraform apply -
Fetch the cluster credentials.
gcloud container fleet memberships get-credentials gke-patterns-cluster --project "<walkthrough-project-name/>" -
Check the nodes are ready.
kubectl get pods -n kube-system
Install Redis and create associated resources
-
Change to the
patterns/redis-clusterdirectory.cd ../redis-cluster -
Create a new file
terraform.tfvarsin that directory.touch terraform.tfvars -
Open the file for editing.
-
Paste the following content in the file.
credentials_config = { kubeconfig = { path = "~/.kube/config" } } statefulset_config = { replicas = 8 resource_requests = { cpu = "1" memory = "1.5Gi" } } -
Initialize the terraform configuration.
terraform init -
Apply the terraform configuration.
terraform apply -
Check that the Redis pods are ready
kubectl get pods -n redis -
Check that the Redis volumes match the number of replicas
kubectl get pv -
Confirm the Pod Disruption Budget for redis guarantees at least 3 pods are up during a voluntary disruption
kubectl describe pdb redis-pdb -n redis
Destroy resources (optional)
-
Change to the
patterns/autopilot-clusterdirectory.cd ../autopilot-cluster -
Destroy the cluster with the following command.
terraform destroy
Congratulations
You’re all set!