Skip to main content

Redis

To deploy a Redis instance on Porter, head to the Community Add-ons tab. You can optionally specify a password for the instance or configure the amount of resources (i.e. CPU and RAM) assigned to the instance.

Redis settings

Connecting to the Database

Redis on Porter is by default only exposed to internal traffic - only applications and add-on's that are deployed in the same Kubernetes cluster can connect to the Redis instance. The DNS name for the instance can be found on the deployment view as shown below. Note that Redis listens on port 6379 by default.

Redis URI

The connection URI for the Redis instance follows this format:

redis://${DNS_NAME}:6379

If you've enabled password, the connection string would look like:

redis://${ARBITRARY_USERNAME}:${PASSWORD}@${DNA_NAME}:6379

You can pass in any string as your username (even an empty string). Redis does not support users but implements this behavior to comply with URI RFC standard.

For the example above that does not have password enabled, the connection string would be:

redis://peaches-redis-master.default.svc.cluster.local:6379

Exposing Redis over NGINX

info

Note that exposing Redis over NGINX isn't natively supported with the Porter Redis addon. This guide walks you through installing and exposing Redis manually, by interacting with the cluster using kubectl.

While exposing Redis over the NGINX instance isn't natively supported with the Porter Redis Addon, it is possible to expose Redis by manually installing the Bitnami Redis Helm chart and tweaking some values on the Porter NGINX instance.

Create a DNS Record

First, create a DNS record for your exposed Redis instance. To do this, you must first find the DNS name assigned to the load balancer of your cluster. This can be found by navigating to the Porter dashboard and copying the load balancer address:

Ingress IP Address

If you're on Digital Ocean or Google Cloud Platform, this will be an IP address, while if you're on AWS, this will be a domain name to your load balancer. For IP addresses, simply create an A record for your redis subdomain and point it to this IP address. For AWS, create a CNAME record on your DNS provider for your desired subdomain, which points to the load balancer URL you have copied above.

info

After you complete the previous steps, it might take up to 30 minutes for DNS records to fully propagate. Please wait before deploying your applications until the DNS propagation is complete. You can check this using tools like dnschecker.org or running nslookup <your-domain>.

Install the Redis Addon

To install the Redis addon, make sure that you've installed helm and kubectl, and that kubectl is configured to connect to your cluster. To confirm this, make sure kubectl get namespace is returning your list of namespaces.

Then, create the following redis-values.yaml file in a secure directory (make sure you don't push this file to Git):

auth:
enabled: true
# TODO: change the password here
password: foo

tls:
enabled: true
authClients: false
autoGenerated: true

ingress:
enabled: true
hosts:
# TODO: change the subdomain here to the DNS record you created above
- redis.example.com

Next, use these values to install a Redis instance on your cluster by running these commands:

helm repo add bitnami https://charts.bitnami.com/bitnami
helm install redis bitnami/redis --values redis-values.yaml

After about 30 seconds, you should see a console message indicating that Redis was successfully installed.

Upgrade NGINX Ingress Controller

Next, update the NGINX ingress controller to expose the Redis instance that you just created. You can find the NGINX ingress controller by navigating to the ingress-nginx namespace and selecting the nginx-ingress application. Upgrade the chart with the following values:

Caution

Warning: make sure to merge these values with the existing values.

tcp:
# service name is {release_name}-master
6379: "default/hello-redis-world-master:6379"
# {ingress_port}: {release_namespace}/{release_name}-master:{service_port}

For more information about exposing TCP directly over the NGINX ingress, see the documentation.

Connect to your Application

You can now connect to your Redis instance over the public DNS record you created! Before running the following commands, make sure your redis-cli installation is up to date (by running redis-cli --version). If you do not have redis-cli installed, you can install it via brew install redis (or view the download instructions here). As of this writing, the latest version is 6.2.6. To connect to your instance with TLS enabled, run:

# NOTE: change the password and domain here
redis-cli -u rediss://foo@example.com --cacert ./ca.crt