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

Bitnami Redis

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

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

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 nameBitnamiRedis = "bitnami-redis"

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

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

const charNameRedis = "redis"

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

Pulumi Up

Run pulumi up to create the namespace and pods.

1
$ pulumi up

See pods about bitnami-redis.

1
2
3
4
5
6
$ kubectl get pods -n bitnami-redis
NAME READY STATUS RESTARTS AGE
redis-master-0 1/1 Running 0 10h
redis-replicas-0 1/1 Running 0 10h
redis-replicas-1 1/1 Running 0 10h
redis-replicas-2 1/1 Running 0 10h

Pulumi Destroy

Destroy all resources created by Pulumi.

1
$ pulumi destroy

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/