Skip to main content

Deployed into Kubernetes

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

Deploy Database

Firstable we need to run a standalone database in the Kubernetes. OneDev supports MySQL, PostgreSQL, MariaDB and MS SQL Server. In this tutorial, we simply deploy MySQL:

  1. Create file mysql.yaml with below content:

    apiVersion: v1
    kind: Secret
    metadata:
    name: onedev-mysql
    stringData:
    password: changeit # change this if your password is different
    ---
    apiVersion: v1
    kind: Service
    metadata:
    name: onedev-mysql
    labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql
    spec:
    ports:
    - port: 3306
    selector:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql
    ---
    apiVersion: apps/v1
    kind: Deployment
    metadata:
    name: onedev-mysql
    labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql
    spec:
    selector:
    matchLabels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql
    strategy:
    type: Recreate
    template:
    metadata:
    name: onedev-mysql
    labels:
    app.kubernetes.io/name: mysql
    app.kubernetes.io/instance: mysql
    spec:
    nodeSelector:
    kubernetes.io/os: linux
    containers:
    - name: mysql
    image: mysql:5.7
    args:
    - "--character-set-server=utf8mb4"
    - "--collation-server=utf8mb4_unicode_ci"
    - "--ignore-db-dir=lost+found"
    env:
    - name: MYSQL_DATABASE
    value: onedev
    - name: MYSQL_ROOT_PASSWORD
    valueFrom:
    secretKeyRef:
    name: onedev-mysql
    key: password
    ports:
    - containerPort: 3306
    resources:
    requests:
    memory: 256Mi
    volumeMounts:
    - name: mysql
    mountPath: /var/lib/mysql
    readinessProbe:
    exec:
    command:
    - bash
    - "-c"
    - |
    mysql -uroot -p$MYSQL_ROOT_PASSWORD -e 'SELECT 1'
    initialDelaySeconds: 5
    periodSeconds: 2
    timeoutSeconds: 1
    volumes:
    - name: mysql
    persistentVolumeClaim:
    claimName: onedev-mysql
    ---
    apiVersion: v1
    kind: PersistentVolumeClaim
    metadata:
    name: onedev-mysql
    spec:
    resources:
    requests:
    storage: 10Gi
    accessModes:
    - ReadWriteOnce
  2. Run below commands to deploy the database:

    kubectl create namespace onedev
    kubectl apply -f mysql.yaml -n onedev

Deploy OneDev

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

helm repo add onedev https://dl.cloudsmith.io/public/onedev/onedev/helm/charts
helm repo update onedev
helm install onedev onedev/onedev -n onedev --set onedev.replicas=2 --set database.external=true --set database.type=mysql --set database.host=onedev-mysql.onedev.svc.cluster.local --set-string database.port=3306 --set database.name=onedev --set database.user=root --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