Ruby error in jekyll app

Couple of issues for Deploy Jekyll App on Kubernetes:

  1. The description says the PV already exists but for me it did not, in the 3-4 times I ran the exercise. I got around this by using kubectl apply -f /opt/k8s/jekyll-pv.yaml (can’t remember exact path now)
  2. I created the pvc and pod but the kodekloud/jekyll init container was exiting because of a ruby exception, strong indication that something wrong with kodekloud/jekyll. When I looked online, it seems that there is a dependency out of date, which I confirmed: if I start a pod with just kodekloud/jekyll and kubectl exec into it, and run jekyll new /site, I get the ruby exception; if I then run bundle update, many gems update, and then if I run the jekyll new /site again it does not raise exception.

So short of waiting for a patch from kodekloud, I tried a temporary fix just to get me through the challenge.

I forgot that you can actually run multiple commands in a container so my first attempt wsa to create an additional init container to update the gems. The pod yaml was then:

apiVersion: v1
kind: Pod
metadata:
  labels:
    run: jekyll-pod-nautilus
  name: jekyll-pod-nautilus
  namespace: jekyll-namespace-nautilus
spec:
  volumes:
  - name: site
    persistentVolumeClaim:
      claimName: jekyll-site-nautilus
  initContainers:
  - image: kodekloud/jekyll
    name: jekyll-update-bundler
    command: [ "bundle","update" ]
  - image: kodekloud/jekyll
    name: jekyll-init-nautilus
    command: [ "jekyll", "new", "/site" ]
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: site
      mountPath: /site
  containers:
  - image: kodekloud/jekyll-serve
    name: jekyll-container-nautilus
    volumeMounts:
    - name: site
      mountPath: /site

The bundle update init container worked and exited with 0; but the jekyll init container showed the same ruby exception. This is likely because the bundle update writes in /usr/local which is not shared via a volume. I think the only way with this approach would be to tell bundle update to put the updated gems in a shared volume like /gems and then set an env var in the other containers to use the additional gems. However I could not get bundle to put gems in a different place.

So I got it to work by using just one init container but extending the command to have the bundle update:

  initContainers:
  - image: kodekloud/jekyll
    name: jekyll-init-nautilus
    command: [ "/bin/bash", "-c", "bundle update; jekyll new /site" ]
    imagePullPolicy: IfNotPresent
    volumeMounts:
    - name: site
      mountPath: /site

This allowed the jekyll to run.

1 Like

Thanks for your answer, i 've got the same error with the init container related to the image kodekloud/jekyll : Could not find public_suffix-4.0.6 in any of the sources (Bundler::GemNotFound)

with bundle update;
i can pass the task

Thank you @Schollii for this very helpful post!!