How do I deploy the strapi/strapi docker image on Kubernetes with TypeScript?
In this guide, we will deploy the strapi/strapi
Docker image on a Kubernetes cluster using Pulumi with TypeScript. We will create a Kubernetes Deployment and a Service to expose the Strapi application.
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
// Define the namespace
const namespace = new k8s.core.v1.Namespace("strapi-ns", {
metadata: { name: "strapi" },
});
// Define the Strapi deployment
const appLabels = { app: "strapi" };
const deployment = new k8s.apps.v1.Deployment("strapi-deployment", {
metadata: {
namespace: namespace.metadata.name,
},
spec: {
selector: { matchLabels: appLabels },
replicas: 1,
template: {
metadata: { labels: appLabels },
spec: {
containers: [{
name: "strapi",
image: "strapi/strapi",
ports: [{ containerPort: 1337 }],
}],
},
},
},
});
// Define the Strapi service
const service = new k8s.core.v1.Service("strapi-service", {
metadata: {
namespace: namespace.metadata.name,
labels: appLabels,
},
spec: {
type: "LoadBalancer",
ports: [{ port: 1337, targetPort: 1337 }],
selector: appLabels,
},
});
// Export the service URL
export const serviceUrl = service.status.loadBalancer.ingress[0].hostname;
Key Points
- Namespace: We created a namespace
strapi
to isolate our resources. - Deployment: We defined a deployment for the
strapi/strapi
Docker image with a single replica. - Service: We created a LoadBalancer service to expose the Strapi application on port 1337.
Summary
We deployed the strapi/strapi
Docker image on a Kubernetes cluster using Pulumi with TypeScript. We created a namespace, a deployment, and a service to run and expose the Strapi application. The service URL is exported for easy access.
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.