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!!

I’ve got the same issue, and the above didn’t completely solve the issue.

root@controlplane ~ ➜  k logs -n development jekyll -c copy-jekyll-site
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............

Hi @Sam-Bentley ,
Please check the solution for this task: -

Regards,