1. Answers
  2. Deploy The Redis Docker Image On Digital Ocean Kubernetes Service With TypeScript.

Deploy the Redis Docker Image on Digital Ocean Kubernetes Service With TypeScript.

This Pulumi program will deploy the Redis Docker image on a DigitalOcean Kubernetes Service (DOKS) cluster using TypeScript. The key services involved are DigitalOcean Kubernetes, a Kubernetes Deployment, and a Kubernetes Service to expose Redis.

Step-by-Step Explanation

Step 1: Set up the DigitalOcean Kubernetes Cluster

  1. Create a new DigitalOcean Kubernetes cluster.
  2. Configure the cluster with the necessary node pool.
  3. Obtain the kubeconfig for the cluster.

Step 2: Create the Kubernetes Deployment for Redis

  1. Define a Kubernetes Deployment resource to deploy the Redis Docker image.
  2. Specify the container image as redis.
  3. Configure the necessary ports and environment variables.

Step 3: Create the Kubernetes Service to Expose Redis

  1. Define a Kubernetes Service resource to expose the Redis deployment.
  2. Configure the service type as ClusterIP or LoadBalancer based on your requirements.
  3. Set the appropriate ports for the Redis service.

Step 4: Deploy the Resources

  1. Use Pulumi to deploy the Kubernetes Deployment and Service resources.
  2. Verify that the Redis service is running and accessible.

Summary and Conclusion

In this Pulumi program, we deployed the Redis Docker image on a DigitalOcean Kubernetes Service (DOKS) cluster using TypeScript. We created a Kubernetes Deployment to manage the Redis pods and a Kubernetes Service to expose Redis. This setup ensures that Redis is highly available and can be accessed within the Kubernetes cluster or externally based on the service type configuration.

Full Code Example

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

// Step 1: Set up the DigitalOcean Kubernetes Cluster
const cluster = new digitalocean.KubernetesCluster("my-cluster", {
    region: "nyc1",
    version: "1.21.5-do.0",
    nodePool: {
        name: "default",
        size: "s-2vcpu-4gb",
        nodeCount: 3,
    },
});

// Obtain the kubeconfig for the cluster
const kubeconfig = cluster.kubeConfigs[0].rawConfig;
const provider = new k8s.Provider("do-k8s", { kubeconfig });

// Step 2: Create the Kubernetes Deployment for Redis
const appLabels = { app: "redis" };
const deployment = new k8s.apps.v1.Deployment("redis-deployment", {
    metadata: { namespace: "default" },
    spec: {
        selector: { matchLabels: appLabels },
        replicas: 1,
        template: {
            metadata: { labels: appLabels },
            spec: {
                containers: [{
                    name: "redis",
                    image: "redis",
                    ports: [{ containerPort: 6379 }],
                }],
            },
        },
    },
}, { provider });

// Step 3: Create the Kubernetes Service to Expose Redis
const service = new k8s.core.v1.Service("redis-service", {
    metadata: { namespace: "default" },
    spec: {
        selector: appLabels,
        ports: [{ port: 6379, targetPort: 6379 }],
        type: "ClusterIP", // Change to "LoadBalancer" if needed
    },
}, { provider });

// Step 4: Deploy the Resources
export const redisServiceName = service.metadata.name;
export const redisDeploymentName = deployment.metadata.name;
export { kubeconfig };

Deploy this code

Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.

Sign up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up