How do I deploy the wurstmeister/kafka:latest docker image on DigitalOcean Kubernetes Service with TypeScript?
In this guide, we will deploy the wurstmeister/kafka:latest
Docker image on a DigitalOcean Kubernetes Service using Pulumi with TypeScript. We will create a Kubernetes cluster, a deployment, and a service to expose Kafka.
import * as pulumi from "@pulumi/pulumi";
import * as digitalocean from "@pulumi/digitalocean";
import * as k8s from "@pulumi/kubernetes";
// Create a DigitalOcean Kubernetes Cluster
const cluster = new digitalocean.KubernetesCluster("do-cluster", {
region: digitalocean.Region.NYC3,
version: "1.21.5-do.0",
nodePool: {
name: "default",
size: "s-2vcpu-4gb",
nodeCount: 2,
},
});
// Export the Kubeconfig for the cluster
export const kubeconfig = cluster.kubeConfigs[0].rawConfig;
// Create a Kubernetes provider instance using the cluster's kubeconfig
const k8sProvider = new k8s.Provider("k8sProvider", {
kubeconfig: kubeconfig,
});
// Create a Kubernetes Namespace
const kafkaNamespace = new k8s.core.v1.Namespace("kafka-namespace", {
metadata: { name: "kafka" },
}, { provider: k8sProvider });
// Define the Kafka Deployment
const kafkaDeployment = new k8s.apps.v1.Deployment("kafka-deployment", {
metadata: {
namespace: kafkaNamespace.metadata.name,
name: "kafka",
},
spec: {
replicas: 1,
selector: {
matchLabels: { app: "kafka" },
},
template: {
metadata: {
labels: { app: "kafka" },
},
spec: {
containers: [
{
name: "kafka",
image: "wurstmeister/kafka:latest",
ports: [{ containerPort: 9092 }],
env: [
{ name: "KAFKA_ADVERTISED_HOST_NAME", value: "localhost" },
{ name: "KAFKA_ZOOKEEPER_CONNECT", value: "zookeeper:2181" },
],
},
],
},
},
},
}, { provider: k8sProvider });
// Define the Kafka Service
const kafkaService = new k8s.core.v1.Service("kafka-service", {
metadata: {
namespace: kafkaNamespace.metadata.name,
name: "kafka",
},
spec: {
selector: { app: "kafka" },
ports: [{ port: 9092, targetPort: 9092 }],
type: "LoadBalancer",
},
}, { provider: k8sProvider });
Key Points
- We created a DigitalOcean Kubernetes cluster using the
digitalocean.KubernetesCluster
resource. - We configured a Kubernetes provider using the cluster’s kubeconfig.
- We created a Kubernetes namespace for Kafka.
- We defined a Kafka deployment using the
wurstmeister/kafka:latest
Docker image. - We exposed Kafka using a Kubernetes service of type
LoadBalancer
.
Summary
This guide demonstrated how to deploy the wurstmeister/kafka:latest
Docker image on a DigitalOcean Kubernetes Service using Pulumi with TypeScript. We created a Kubernetes cluster, namespace, deployment, and service to successfully run Kafka on DigitalOcean Kubernetes.
Deploy this code
Want to deploy this code? Sign up for a free Pulumi account to deploy in a few clicks.
Sign upNew to Pulumi?
Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.
Sign upThank you for your feedback!
If you have a question about how to use Pulumi, reach out in Community Slack.
Open an issue on GitHub to report a problem or suggest an improvement.