[Infrastructure as Code (IaC) Pulumi] Use Pulumi kubernetes (K8S) Helm Chart to deploy Bitnami Redis Cluster

Bitnami Redis Cluster

Bitnami makes it easy to get your favorite open source software up and running on any platform, including your laptop, Kubernetes and all the major clouds. In addition to popular community offerings, Bitnami, now part of VMware, provides IT organizations with an enterprise offering that is secure, compliant, continuously maintained and customizable to your organizational policies.

Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker. Redis provides data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. Redis has built-in replication, Lua scripting, LRU eviction, transactions, and different levels of on-disk persistence, and provides high availability via Redis Sentinel and automatic partitioning with Redis Cluster.

This article is about how to use Pulumi, kubernetes (K8S) provider, Helm Chart and TypeScript SDK to deploy Bitnami Redis within Kubernetes (K8S).

Prerequisites

Usage

Pulumi New

Create the workspace directory.

1
2
3
$ mkdir -p col-example-pulumi-typescript-bitnami-redis-cluster

$ cd col-example-pulumi-typescript-bitnami-redis-cluster

Pulumi login into local file system.

1
2
3
$ pulumi login file://.
Logged in to cloudolife as cloudolife (file://.)
or visit https://pulumi.com/docs/reference/install/ for manual instructions and release notes.

Pulumi new a project with kubernetes-typescript SDK.

1
$ pulumi new kubernetes-typescript

The above command will create some files within the current directory.

1
2
3
4
5
6
7
8
tree . -L 1
.
├── node_modules/
├── package.json
├── package.json.lock
├── Pulumi.dev.yaml
├── Pulumi.yaml
└── main.ts

Install js-yaml package to load and parse yaml file.

1
$ npm i js-yaml

Pulumi Configuration

Configure Kubernetes

By default, Pulumi will look for a kubeconfig file in the following locations, just like kubectl:

  • The environment variable: $KUBECONFIG,

  • Or in current user’s default kubeconfig directory: ~/.kube/config

If the kubeconfig file is not in either of these locations, Pulumi will not find it, and it will fail to authenticate against the cluster. Set one of these locations to a valid kubeconfig file, if you have not done so already.

Configure Values.yaml

Edit values.yaml and replace content within {{ }}.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# values.yaml

# charts/values.yaml at master · bitnami/charts
# https://github.com/bitnami/charts/blob/master/bitnami/redis/values.yaml

## @param global.imageRegistry Global Docker image registry
## @param global.imagePullSecrets Global Docker registry secret names as an array
## @param global.storageClass Global StorageClass for Persistent Volume(s)
## @param global.redis.password Global Redis™ password (overrides `auth.password`)
##
global:

redis:
password: {{ .Values.redis.password }}

See and modify main.ts file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// main.ts

import * as pulumi from "@pulumi/pulumi";

import * as k8s from "@pulumi/kubernetes";

const yaml = require('js-yaml');
const fs = require('fs');

const nameBitnamiRedisCluster = "bitnami-redis-cluster"

const namespaceBitnamiRedisCluster = new k8s.core.v1.Namespace(nameBitnamiRedisCluster, {
metadata: {
name: nameBitnamiRedisCluster,
},
})

const values = yaml.safeLoad(fs.readFileSync("./values.yaml", 'utf8'))

const charNameRedisCluster = "redis-cluster"

// bitnami-redis-cluster 4.0.1 · kubernetes/bitnami-redis-cluster
// https://artifacthub.io/packages/helm/bitnami-redis-cluster/bitnami-redis-cluster
const charBitnamiRedisCluster = new k8s.helm.v3.Chart(charNameRedisCluster, {
chart: charNameRedisCluster,
version: "7.0.7",
fetchOpts:{
repo: "https://charts.bitnami.com/bitnami",
},
namespace: namespaceBitnamiRedisCluster.metadata.name,
values: values,
});

Pulumi Up

Run pulumi up to create the namespace and pods.

1
$ pulumi up

See pods about bitnami-redis-cluster.

1
2
3
4
5
6
7
8
$ kubectl get pods -n bitnami-redis-cluster
NAME READY STATUS RESTARTS AGE
redis-cluster-0 1/1 Running 0 5h49m
redis-cluster-1 1/1 Running 0 5h49m
redis-cluster-2 1/1 Running 0 5h49m
redis-cluster-3 1/1 Running 0 5h49m
redis-cluster-4 1/1 Running 0 5h49m
redis-cluster-5 1/1 Running 0 5h49m

Pulumi Destroy

Destroy all resources created by Pulumi.

1
$ pulumi destroy

FAQs

(error) MOVED

1
2
3
I have no name!@redis-cluster-0:/$ redis-cli -h redis-cluster
redis-cluster:6379> get "a"
(error) MOVED 15495 10.200.111.151:6379

Connect Redis with Cluster mode -c.

1
2
3
4
5
redis-cluster:6379> 
I have no name!@redis-cluster-0:/$ redis-cli -c -h redis-cluster
redis-cluster:6379> get "key"
-> Redirected to slot [0] located at 10.200.111.151:6379
(nil)

References

[1] charts/bitnami/redis at master · bitnami/charts - https://github.com/bitnami/charts/tree/master/bitnami/redis

[2] charts/values.yaml at master · bitnami/charts - https://github.com/bitnami/charts/blob/master/bitnami/redis/values.yaml

[3] Redis - https://redis.io/

[4] Bitnami: Packaged Applications for Any Platform - Cloud, Container, Virtual Machine - https://bitnami.com/

[5] Kubernetes Getting Started | Pulumi - https://www.pulumi.com/docs/get-started/kubernetes/

[6] Pulumi - Modern Infrastructure as Code - https://www.pulumi.com/

[7] Kubernetes - https://kubernetes.io/

[8] TypeScript: Typed JavaScript at Any Scale. - https://www.typescriptlang.org/

[9] Helm - https://helm.sh/