1. Answers
  2. Deploy the redis:latest Docker image on Kubernetes

How do I deploy the redis:latest Docker image on Kubernetes with TypeScript?

In this tutorial, we will deploy the redis:latest Docker image on a Kubernetes cluster using Pulumi and TypeScript. We will create a Kubernetes Deployment and a Service to manage and expose the Redis instance.

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

// Define the Redis Deployment
const redisDeployment = new k8s.apps.v1.Deployment("redis-deployment", {
    spec: {
        selector: { matchLabels: { app: "redis" } },
        replicas: 1, // number of Redis instances
        template: {
            metadata: { labels: { app: "redis" } },
            spec: {
                containers: [{
                    name: "redis",
                    image: "redis:latest",
                    ports: [{ containerPort: 6379 }]
                }]
            }
        }
    }
});

// Define the Redis Service
const redisService = new k8s.core.v1.Service("redis-service", {
    metadata: {
        labels: redisDeployment.spec.template.metadata.labels,
    },
    spec: {
        ports: [{ port: 6379, targetPort: 6379 }],
        selector: redisDeployment.spec.template.metadata.labels,
    },
});

// Export the Redis Service URL
export const redisServiceUrl = redisService.metadata.name.apply(name => `${name}:6379`);

Key Points

  • We created a Kubernetes Deployment for Redis using the redis:latest Docker image.
  • We set up a Kubernetes Service to expose the Redis instance on port 6379.
  • We exported the Redis Service URL for easy access.

Summary

We successfully deployed the redis:latest Docker image on a Kubernetes cluster using Pulumi and TypeScript. This setup includes a Deployment to manage the Redis pods and a Service to expose Redis to other applications within the cluster.

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