1. Answers
  2. Deploy The Gitea/gitea:1.15 Docker Image On Kubernetes With TypeScript.

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

  1. Initialize a new Pulumi project:
    pulumi new typescript
    
  2. Install the necessary Pulumi packages:
    npm install @pulumi/pulumi @pulumi/kubernetes
    

Step 2: Define Kubernetes Resources

  1. Create a new file index.ts and import the required packages:
    import * as pulumi from "@pulumi/pulumi";
    import * as k8s from "@pulumi/kubernetes";
    
  2. 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" } },
        },
    });
    
  3. 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 },
                    }],
                },
            },
        },
    });
    
  4. 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

  1. 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 up

New to Pulumi?

Want to deploy this code? Sign up with Pulumi to deploy in a few clicks.

Sign up