This tutorial walks you through the process of deploying a Redis cluster. The instructions work on all clouds supported by Juju—even bare metal servers—but this tutorial includes specific instructions to deploy the cluster to AWS, Google Compute Platform or Azure.
You will be able to configure the exact scale that you require and deploy it into any region supported by each cloud.
What you’ll learn
- Deploy a Redis cluster
- Tweak the cluster’s settings to add authentication
- Test our deployment
What you’ll need
- Juju installed (install it by running
snap install juju --classicor by following the instructions on the Juju documentation)
- (Optional) An Ubuntu SSO account (visit login.ubuntu.com to create one)
- (Optional) Credential information for AWS, GCP or Azure (created when you create an account with your preferred cloud provider)
(Optional) Log in to JAAS
juju login jaas
What is JAAS?
JAAS is a hosted service provided by Canonical, the company behind Ubuntu. It provides a “Juju controller”. The Juju controller talks to the cloud provider programmatically to provision machines. Once they’re online, the controller then installs the software that we care about: Redis.
What do I do if I don’t want to log into JAAS?
No problem. Follow the instructions provided by the Juju team about how to get started with Juju. You’ll be able use those instructions to deploy to any cloud, including private clouds or how to use your own computer as a virtual cloud.
juju add-model redis-cluster-tutorial aws/us-west-1
What’s a model and why I am creating one?
A “model” is Juju a term to describe a logical service made up applications. A model might represent a whole web app, including its web server, databases and work queues.
For our purposes, we’ll only be deploying a single application. Our Redis cluster will make up the entire model. So we’ll use the name
Where can I deploy my model?
The command at the top of this page uses the US West 1 region from the AWS cloud provider by specifying
aws/us-west-1. That’s by no means necessary!
To get a list of cloud providers and their regions that are supported, just omit one:
juju add-model redis-cluster-tutorial
After a few moments, you’ll see output similar to this appear in your console window:
Please specify which cloud/region to use: juju add-model [options] <model-name> cloud[/region] The clouds/regions supported by this controller are: Cloud Regions aws ap-northeast-1, ap-northeast-2, ap-south-1, ap-southeast-1, ap-southeast-2, eu-central-1, eu-west-1, eu-west-3, me-south-1, sa-east-1, us-east-1, us-east-2, us-west-1, us-west-2, ap-east-1, ap-northeast-3, ca-central-1, eu-north-1, eu-west-2 azure brazilsouth, canadaeast, centralindia, centralus, eastasia, eastus, eastus2, japaneast, japanwest, koreacentral, koreasouth, northeurope, southindia, uksouth, ukwest, westindia, westus2, australiaeast, australiasoutheast, canadacentral, northcentralus, southcentralus, southeastasia, westcentralus, westeurope, westus, francesouth, francecentral, southafricanorth, southafricawest google asia-east2, asia-east1, europe-west1, us-central1, us-east1, asia-northeast1, asia-south1, asia-southeast1, australia-southeast1, europe-north1, europe-west2, europe-west3, europe-west4, northamerica-northeast1, southamerica-east1, us-east4, us-west1, us-west2
Why am I being asked to sign in?
juju add-model command will probably launch a browser window asking you to log in.
Juju (and JAAS) need to be granted permission to act on your behalf. Juju works by talking to the cloud provider programmatically. This login process confirms that you’re willing to delegate authority to Juju to do so.
Deploy Redis Cluster
juju deploy cs:~omnivector/redis \ --config cluster-enabled=true \ --constraints 'mem=4G' \ --num-units 3
Here is a video of what is going on behind scenes when that command is executed (make sure you don’t forget to use
--config cluster-enabled-true in your own deployment!):
Explaining the syntax
That command can be a little confusing if you haven’t encountered Juju before. Here is an explanation of each part of the command:
||This is the charm that we're deploying. It is made up of the parts "
||Sets the configuration option
||Specify that the virtual machines that we want Juju to deploy on our behalf have at least 4GB of RAM.|
||Set the desired scale of our cluster to be 3 virtual machines|
What is a charm?
A charm is software that deploys other software and makes it easy to maintain.
What is “Omnivector”?
cs:~omnivector/redis is the Juju Charm Store account for Omnivector Solutions. Omnivector Solutions is a commercial enterpise based in the Oregon, USA.
Omnivector is a member of the Juju Experts program. Their team has written the Redis charm that we’re deploying and released it as open source software. (Thanks @jamesbeedy!)
Expose the cluster to the Internet
juju expose command talks to the cloud’s firewall systems to make them publicly accessible.
Wait for Redis to be deployed
Will eventually produce an output similar to this:
Model Controller Cloud/Region Version SLA Timestamp redis-cluster-tutorial jaas aws/us-west-1 2.6.8 unsupported 16:54:19+13:00 App Version Status Scale Charm Store Rev OS Notes redis 5.0.5 active 3 redis jujucharms 25 ubuntu Unit Workload Agent Machine Public address Ports Message redis/0* active idle 0 18.104.22.168 6379/tcp successfully clustered redis/1 active idle 1 22.214.171.124 6379/tcp successfully clustered redis/2 active idle 2 126.96.36.199 6379/tcp successfully clustered Machine State DNS Inst id Series AZ Message 0 started 188.8.131.52 i-0924efebda490847f bionic us-west-1b running 1 started 184.108.40.206 i-0865d0af27dae812f bionic us-west-1c running 2 started 220.127.116.11 i-037f8bdc3cf0b3d22 bionic us-west-1b running
Once all of the workloads are in the “active” state, it’s time to move on.
Hint: use the watch command to avoid retyping
watchcommand enables you to repeatedly execute a command without needing to retype it. Try
watch -c -n5 juju status --color
Add password authentication and enable TCP Keep Alive
If you would like to require that clients specify a password when they execute commands, use the
juju config command. The command supports setting multiple options at the same time by adding additional setting=value pairs.
juju config redis \ password=password123 \ tcp-keepalive=10
How do I view what the settings are?
juju config redis without any arguments:
juju config redis
Juju will happily report the settings that are in place:
application: redis application-config: trust: default: false description: Does this application have access to trusted credentials source: default type: bool value: false charm: redis settings: cluster-enabled: default: false description: | Enable or disable redis-cluster. This config can only be set pre-deploy. source: user type: boolean value: true # ... timeout: default: 0 description: | Close the connection after a client is idle for N seconds (0 to disable). source: default type: int value: 0
Overwhelmed by the
If you’re a a bit lost, pipe the output into
lessand you’ll be able to scroll through it at your own pace:
juju config redis | less
How do I unset a value?
Use an empty value to “unset” it:
juju config redis password=""
Install the Redis CLI command:
sudo apt install -y redis-tools
Find the public address of one of the cluster units:
juju status --format=oneline
Will spend a moment or two probing the model, then reporting something similar to this:
- redis/0: 18.104.22.168 (agent:idle, workload:active) 6379/tcp - redis/1: 22.214.171.124 (agent:idle, workload:active) 6379/tcp - redis/2: 126.96.36.199 (agent:idle, workload:active) 6379/tcp
Now let’s ping the cluster!
redis-cli -h 188.8.131.52 ping;
Will produce this encouraging response: