Claus Beerta

Syncthing, Hugo and Kubernets put to Work

I’ve been using hugo for this Page for a long time now, as i didn’t want to worry about frequently updating a CMS/Blog software for security. Occasionally updating a nginx is much easier and less time consuming.

So far I’ve only really been using it on the console to post (if at all), but lately I’ve started looking into ways to post more comfortably, and also probably from my cellphone.

I’ve found a solution that works, for me that may be useful to somebody.

I am running this site rendered with hugo from Markdown files that were converted from all the old posts that i did over the past years, in Kubernetes. k3s more specifically, as it is a lot less hassle to get up and running then something like kubeadm.

I’ve also been using syncthing to sync documents across the Systems that i run, and keep multiple copies of my important documents.

I’ve put these pieces together, to allow me to just Post by writing an Article in an editor and store it into my Synced folder.

Syncthing is running in a pod on the cluster, and stores everything to a Volume locally on the VM k3s is running on:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: syncthing
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    spec:
      volumes:
        - name: mypage
          persistentVolumeClaim:
            claimName: mypage-claim
      containers:
        - name: syncthing
          image: "syncthing"
          volumeMounts:
            - mountPath: /Documents
              name: mypage
              subPath: syncthing

This in turn is then mounted into a pod that is running 2 Containers. One with nginx, one with hugo:

---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: hugo
spec:
  replicas: 1
    spec:
      volumes:
        - name: mypage
          persistentVolumeClaim:
            claimName: mypage-claim
        - name: htmldir
          emptyDir: {}
      containers:
        - name: nginx
          image: "nginx"
          volumeMounts:
            - mountPath: /usr/share/nginx/html
              name: htmldir
        - name: hugo
          image: "hugo"
          command: ["hugo"]
          args: ["-d", "/usr/share/nginx/html/", "-w", "--cleanDestinationDir", "--verbose", "--minify"]
          volumeMounts:
            - mountPath: /hugo-src/content
              name: mypage
              subPath: syncthing/Blog/content
              readOnly: true
            - mountPath: /hugo-src/static/img
              name: mypage
              subPath: syncthing/Blog/img
              readOnly: true
            - mountPath: /usr/share/nginx/html
              name: htmldir

Now when i write something, it is synced to my k3s system, where hugo watches the directory for changes, and creates the new page in an emptyDir that nginx serves it’s content from.

Images are handled equally.

Since synching is available on Android too, i can now post from my Cellphone.

To write this post, i’ve used typora on Windows, a nice Markdown capable editor.

(note: These YAML snippets are not actually complete, so don’t expect them to work if you paste them into your Cluster)