Create an Kubernetes.apps/V1.Deployment Resource
Introduction
In this guide, we will create a Kubernetes Deployment resource using Pulumi in TypeScript. The kubernetes.apps/v1.Deployment
resource allows you to manage and deploy containerized applications in a Kubernetes cluster. We will define the deployment configuration, including the container image, replicas, and other necessary settings.
Step-by-Step Explanation
Step 1: Set Up Your Pulumi Project
- Ensure you have Pulumi installed. If not, follow the installation guide.
- Create a new Pulumi project:
pulumi new typescript
. - Install the Pulumi Kubernetes provider:
npm install @pulumi/kubernetes
.
Step 2: Define the Deployment Resource
Create a new TypeScript file (e.g., index.ts
) and add the following code to define the Kubernetes Deployment resource:
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
const appLabels = { app: "nginx" };
const deployment = new k8s.apps.v1.Deployment("nginx-deployment", {
metadata: { name: "nginx-deployment" },
spec: {
selector: { matchLabels: appLabels },
replicas: 2,
template: {
metadata: { labels: appLabels },
spec: {
containers: [{
name: "nginx",
image: "nginx:1.14.2",
ports: [{ containerPort: 80 }],
}],
},
},
},
});
Step 3: Deploy the Resource
- Run
pulumi up
to preview and deploy the changes. - Confirm the deployment to create the Kubernetes resources.
Conclusion
In this guide, we created a Kubernetes Deployment resource using Pulumi in TypeScript. This deployment will manage and deploy an NGINX container with two replicas. You can customize the deployment configuration to suit your application’s requirements. For more information, refer to the Pulumi Kubernetes documentation.
Full Code Example
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
const appLabels = { app: "nginx" };
const deployment = new k8s.apps.v1.Deployment("nginx-deployment", {
metadata: { name: "nginx-deployment" },
spec: {
selector: { matchLabels: appLabels },
replicas: 2,
template: {
metadata: { labels: appLabels },
spec: {
containers: [{
name: "nginx",
image: "nginx:1.14.2",
ports: [{ containerPort: 80 }],
}],
},
},
},
});
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.