Deploy the Gitea/Gitea:1.15 Docker Image on Kubernetes With TypeScript.
Introduction
In this guide, we will deploy the gitea/gitea:1.15
Docker image on a Kubernetes cluster using Pulumi with TypeScript. Gitea is a lightweight Git service, and we will use Kubernetes resources such as Deployments, Services, and PersistentVolumeClaims to manage its deployment.
Step-by-Step Explanation
Step 1: Set Up Pulumi Project
- Initialize a new Pulumi project:
pulumi new typescript
- Install the necessary Pulumi packages:
npm install @pulumi/pulumi @pulumi/kubernetes
Step 2: Define Kubernetes Resources
- Create a new file
index.ts
and import the required packages:import * as pulumi from "@pulumi/pulumi"; import * as k8s from "@pulumi/kubernetes";
- Define a PersistentVolumeClaim for Gitea’s data storage:
const pvc = new k8s.core.v1.PersistentVolumeClaim("gitea-pvc", { metadata: { name: "gitea-pvc" }, spec: { accessModes: ["ReadWriteOnce"], resources: { requests: { storage: "10Gi" } }, }, });
- Create a Deployment for the Gitea application:
const appLabels = { app: "gitea" }; const deployment = new k8s.apps.v1.Deployment("gitea-deployment", { metadata: { name: "gitea" }, spec: { selector: { matchLabels: appLabels }, replicas: 1, template: { metadata: { labels: appLabels }, spec: { containers: [{ name: "gitea", image: "gitea/gitea:1.15", ports: [{ containerPort: 3000 }], volumeMounts: [{ mountPath: "/data", name: "gitea-data", }], }], volumes: [{ name: "gitea-data", persistentVolumeClaim: { claimName: pvc.metadata.name }, }], }, }, }, });
- Expose the Gitea service using a LoadBalancer Service:
const service = new k8s.core.v1.Service("gitea-service", { metadata: { name: "gitea" }, spec: { type: "LoadBalancer", selector: appLabels, ports: [{ port: 80, targetPort: 3000 }], }, });
Step 3: Deploy the Resources
- Run
pulumi up
to deploy the resources to your Kubernetes cluster:pulumi up
Conclusion
In this guide, we have successfully deployed the gitea/gitea:1.15
Docker image on a Kubernetes cluster using Pulumi with TypeScript. We created a PersistentVolumeClaim for data storage, a Deployment for the Gitea application, and a LoadBalancer Service to expose the application. Pulumi makes it easy to manage and deploy cloud resources using familiar programming languages.
Full Code Example
import * as pulumi from "@pulumi/pulumi";
import * as k8s from "@pulumi/kubernetes";
// Define a PersistentVolumeClaim for Gitea's data storage
const pvc = new k8s.core.v1.PersistentVolumeClaim("gitea-pvc", {
metadata: { name: "gitea-pvc" },
spec: {
accessModes: ["ReadWriteOnce"],
resources: { requests: { storage: "10Gi" } },
},
});
// Define labels for the Gitea application
const appLabels = { app: "gitea" };
// Create a Deployment for the Gitea application
const deployment = new k8s.apps.v1.Deployment("gitea-deployment", {
metadata: { name: "gitea" },
spec: {
selector: { matchLabels: appLabels },
replicas: 1,
template: {
metadata: { labels: appLabels },
spec: {
containers: [{
name: "gitea",
image: "gitea/gitea:1.15",
ports: [{ containerPort: 3000 }],
volumeMounts: [{
mountPath: "/data",
name: "gitea-data",
}],
}],
volumes: [{
name: "gitea-data",
persistentVolumeClaim: { claimName: pvc.metadata.name },
}],
},
},
},
});
// Expose the Gitea service using a LoadBalancer Service
const service = new k8s.core.v1.Service("gitea-service", {
metadata: { name: "gitea" },
spec: {
type: "LoadBalancer",
selector: appLabels,
ports: [{ port: 80, targetPort: 3000 }],
},
});
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.