Skip to main content

Deploy to Kubernetes Cluster

This tutorial goes through the procedure of cluster setup to achieve high availablity and scalability when OneDev is deployed to Kubernetes.

Deploy Database​

First, deploy a standalone database in Kubernetes. OneDev supports MySQL, MariaDB and PostgreSQL. This tutorial uses PostgreSQL 17:

  1. Create file postgresql.yaml with below content:

    apiVersion: v1
    kind: Secret
    metadata:
    name: onedev-postgresql
    stringData:
    password: changeit # change this if your password is different
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: onedev-postgresql
    labels:
    app.kubernetes.io/name: postgresql
    app.kubernetes.io/instance: postgresql
    spec:
    ports:
    - port: 5432
    selector:
    app.kubernetes.io/name: postgresql
    app.kubernetes.io/instance: postgresql
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: onedev-postgresql
    labels:
    app.kubernetes.io/name: postgresql
    app.kubernetes.io/instance: postgresql
    spec:
    selector:
    matchLabels:
    app.kubernetes.io/name: postgresql
    app.kubernetes.io/instance: postgresql
    strategy:
    type: Recreate
    template:
    metadata:
    name: onedev-postgresql
    labels:
    app.kubernetes.io/name: postgresql
    app.kubernetes.io/instance: postgresql
    spec:
    nodeSelector:
    kubernetes.io/os: linux
    containers:
    - name: postgresql
    image: postgres:17-bookworm
    env:
    - name: POSTGRES_DB
    value: onedev
    - name: POSTGRES_USER
    value: onedev
    - name: PGDATA
    value: /var/lib/postgresql/data/pgdata
    - name: POSTGRES_PASSWORD
    valueFrom:
    secretKeyRef:
    name: onedev-postgresql
    key: password
    ports:
    - containerPort: 5432
    resources:
    requests:
    memory: 256Mi
    volumeMounts:
    - name: postgresql
    mountPath: /var/lib/postgresql/data
    readinessProbe:
    exec:
    command:
    - pg_isready
    - "-h"
    - "127.0.0.1"
    - "-U"
    - onedev
    - "-d"
    - onedev
    initialDelaySeconds: 5
    periodSeconds: 2
    timeoutSeconds: 1
    volumes:
    - name: postgresql
    persistentVolumeClaim:
    claimName: onedev-postgresql
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: onedev-postgresql
    spec:
    resources:
    requests:
    storage: 10Gi
    accessModes:
    - ReadWriteOnce
  2. Run below commands to deploy the database:

    kubectl create namespace onedev
    kubectl apply -f postgresql.yaml -n onedev
    kubectl rollout status deployment/onedev-postgresql -n onedev --timeout=180s

Deploy OneDev​

Now lets run below command to deploy OneDev with two replicas:

helm repo add onedev https://code.onedev.io/onedev/~helm
helm repo update onedev
helm install onedev onedev/onedev -n onedev --set onedev.replicas=2 --set database.external=true --set database.type=postgresql --set database.host=onedev-postgresql.onedev.svc.cluster.local --set-string database.port=5432 --set database.name=onedev --set database.user=onedev --set database.password=changeit

Wait a while for OneDev to be deployed. Run command kubectl port-forward --namespace onedev svc/onedev 6610:80 and then set up OneDev by accessing http://localhost:6610.

Request a Trial Subscription​

High availability and scalability requires a subscription to use. Switch to menu item Administration / Subscription Management, request a trial subscription key and install it into OneDev if you do not have a subscription yet:

request trial subscription

Configure Project Replicas​

Switch to menu item Administration / High Availability & Scalability (will be available after trial subscription is activated above), and you will see two OneDev servers in the cluster. Let's change project replicas to 2 and click the button Save Settings & Redistribute Projects:

configure project replicas

This tells OneDev to maintain two replicas of each project on different servers. Now create a new project, and you can check the replica status like below:

check replica status

Do something with the project such as pushing files or running builds, you will see that the replica is update to date. In case you need to find projects without enough replicas, or with outdated replicas, run below project query:

without enough replicas or has outdated replicas

Set Up Front End Load Balancer​

Just set up load balancer or ingress as explained in the installation guide, and traffic will be routed to backend pods. If you are using an ingress controller other than nginx, make sure to enable session sticky.

caution
  1. OneDev can be configured to send alert email via Administratio / Alert Settings when a server is down abnormally. After fixing the issue, make sure to redistribute projects again if new pod is added or existing pod is removed
  2. This tutorial does not include HA setup of database. Refer to database specific guide if you need to do that