Wiki.js and Kubernetes

Posted by
Documentation is good, eat it :)

Wiki.js is a modern Wiki software who is still in development. It has a lot of functionalities and I really like its interface. It’s clear, fast and evolving quickly. The documentation has a Kubernetes section who is empty, in this article I will explain you who to deploy it with K8s.

First we will create a namespace for our new Wiki

apiVersion: v1
kind: Namespace
metadata:
  name: wikijs
  labels:
    name: wikijs

I have selected MariaDB as Database, but you can easily switch to PostgreSQL or an other DB. I have configured the storage to use local volumes.

---
apiVersion: v1
kind: Service
metadata:
  name: mariadb
  namespace: wikijs
spec:
  selector:
    app: mariadb
  ports:
  - name: mariadb
    protocol: TCP
    port: 3306
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mariadb
  namespace: wikijs
  labels:
    app: mariadb
spec:
  selector:
    matchLabels:
      app: mariadb
  template:
    metadata:
      labels:
        app: mariadb
    spec:
      containers:
      - name: mariadb
        image: mariadb:10.4
        env:
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mariadb-secret
              key: ROOT_PASSWORD
        - name: MYSQL_DATABASE
          valueFrom:
            secretKeyRef:
              name: mariadb-secret
              key: DATABASE
        - name: MYSQL_USER
          valueFrom:
            secretKeyRef:
              name: mariadb-secret
              key: USER
        - name: MYSQL_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mariadb-secret
              key: PASSWORD
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mariadb-storage
          mountPath: /var/lib/mysql
      volumes:
      - name: mariadb-storage
        hostPath:
          path: /var/wikijs
          type: Directory

Now we will configure Wiki.js. I have set the imagePullPolicy parameter to Always in order to always get the latest Wiki.js release.

---
apiVersion: v1
kind: Service
metadata:
  name: "wikijs"
  namespace: wikijs
spec:
  ports:
    - name: http
      port: 3000
  selector:
    app: "wikijs"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: wikijs
  namespace: wikijs
  labels:
    app: wikijs
spec:
  selector:
    matchLabels:
      app: wikijs
  template:
    metadata:
      labels:
        app: wikijs
    spec:
      containers:
      - name: wikijs
        image: requarks/wiki:beta
        imagePullPolicy: Always
        env:
        - name: DB_TYPE
          value: "mariadb"
        - name: DB_HOST
          value: "mariadb"
        - name: DB_PORT
          value: "3306"
        - name: DB_NAME
          valueFrom:
            secretKeyRef:
              name: mariadb-secret
              key: database
        - name: DB_USER
          valueFrom:
            secretKeyRef:
              name: mariadb-secret
              key: USER
        - name: DB_PASS
          valueFrom:
            secretKeyRef:
              name: mariadb-secret
              key: PASSWORD
        ports:
        - containerPort: 3000
          name: http

We just need to configure the Database parameters and we will be good. Don’t forget to change the passwords in the file (ROOT and PASSWORD).

apiVersion: v1
kind: Secret
metadata:
  name: mariadb-secret
  namespace: wikijs
type: Opaque
data:
  ROOT: cGFzc3dvcmQ=
  DATABASE: d2lraWpz
  USER: d2lraWpz
  PASSWORD: cGFzc3dvcmQ=

The parameters must be encoded in base 64. To generate the string on GNU/Linux and Mac:

echo -n 'yourstring' | base64

Put everything in a YML file, wikijs.yml in the following example and deploy.

kubectl apply -f wikijs.yml

Your wiki is now ready to be configured and available from http://wikijs.wikijs.svc.cluster.local:3000. Configure your reverse proxy and you will be able to access to it.

Leave a Reply

Your email address will not be published. Required fields are marked *