Deploy a Redis cluster at any scale on any cloud

tutorial

#1

Welcome

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 --classic or 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.

Create model

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 redis-cluster-tutorial.

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?

Running 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:

Command Fragment Explanation
juju deploy The juju deploy command instructs Juju to deploy a charm (a software application) into machines that
cs:~omnivector/redis This is the charm that we're deploying. It is made up of the parts "cs:" to denote the public charm store, "~omnivector" to denote the omnivector user account (as the author of the charm) and "redis" as the charm's name.
--config cluster-enabled=true Sets the configuration option cluster-enabled to true. This instructs the charm code to deploy a Redis as a cluster.
--constraints 'mem=4G' Specify that the virtual machines that we want Juju to deploy on our behalf have at least 4GB of RAM.
--num-units 3 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”?

omnivector in 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 

The juju expose command talks to the cloud’s firewall systems to make them publicly accessible.

Wait for Redis to be deployed

juju status

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        54.67.107.206   6379/tcp  successfully clustered
redis/1   active    idle   1        54.219.173.144  6379/tcp  successfully clustered
redis/2   active    idle   2        13.52.185.251   6379/tcp  successfully clustered

Machine  State    DNS             Inst id              Series  AZ          Message
0        started  54.67.107.206   i-0924efebda490847f  bionic  us-west-1b  running
1        started  54.219.173.144  i-0865d0af27dae812f  bionic  us-west-1c  running
2        started  13.52.185.251   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 juju status

The watch command 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?

Run 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 juju config output?

If you’re a a bit lost, pipe the output into less and 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=""

Test deployment

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: 54.67.107.206 (agent:idle, workload:active) 6379/tcp
- redis/1: 54.219.173.144 (agent:idle, workload:active) 6379/tcp
- redis/2: 13.52.185.251 (agent:idle, workload:active) 6379/tcp

Now let’s ping the cluster!

redis-cli -h 54.67.107.206 ping; 

Will produce this encouraging response:

PONG

:rocket:

Next steps


#2

typo: “No problem!.”

Also looks like a partial edit in the What’s a model section: “For our purposes, we’ll only be our Redis cluster will make up the entire model.”

In Explaining the syntax: --constrains should be --constraints

Missing a capital i in the first sentence of Add password authentication section.

I’d expand the What’s a charm? section to express that it’s the bridge between Juju and deployed applications (in this case Redis).


#3

One day I’ll get one of these through error-free first time! Thanks for checking :slight_smile:

I’ve fixed the typos and will come back to the “What’s a charm” section tomorrow or when I get a block of time to ponder.


#4

Sorry, should have done a compliment sandwich! Also this is great!

It’s hard to see typos in things you’ve written yourself because your brain just fills in what it knows you wrote instead of what you actually wrote.


#5

This is really awesome! Thanks @timClicks

<3 the video too!

I’m speechless.