DEV Community

Harish Babu
Harish Babu

Posted on • Originally published at chekkan.com on

Update blog to ghost version 4 running in Kubernetes

Update blog to ghost version 4 running in Kubernetes

My personal blog site is running on the ghost blogging platform at the time of this writing. Its current running version 3.42.x and there was a new major version released recently and its currently on version 4.2.0. There are guides available on ghost documentation site to help make the upgrade when you have installed ghost on a server using the ghost-CLI tooling. However, none exists for ghost running on Kubernetes, or docker containers. ghost-cli update path seemed desirable compared to the clean install option especially because some database migration might be involved I assumed. Also, I didnt want to re-configure my site with google analytics etc.

Follow the initial steps of backing up all the important content as mentioned in the documentation site. Then come back here...

You will have ssh into the docker container in order to copy the content folder across.

kubectl cp <namespace>/<pod_name>:/var/lib/ghost/content ghost-migration-to-4.x/content
Enter fullscreen mode Exit fullscreen mode

I didn't have much luck copying the theme folder in content. But, I haven't made any changes to the theme using the default Casper theme at present. Make sure run the upgrade check for your theme before progressing any further. Download your existing theme from the Admin site and upload the zipped file into the GScan website.

The way I have the blog setup in Kubernetes is by using the base image chekkan/ghost-cloudinary which builds off the ghost-alpine image. I have already gone ahead and published version 4.2.0 of the docker image.

You will need to ssh into the docker container pod and install ghost-cli.

kubectl exec --stdin --tty -n "<namespace>" "<pod_name>" -- /bin/bash
Enter fullscreen mode Exit fullscreen mode
ssh into the pod thats running ghost container
npm install -g ghost-cli@latest
Enter fullscreen mode Exit fullscreen mode
install ghost-cli npm package

Make sure your current working directory is where you've installed ghost. For me, its at /var/lib/ghost.

I used environment variables in deployment spec file together with Kubernetes secrets to configure my database credentials. For some reason, these were not picked up when I ran ghost config get database.connection.host command. So, I decided to configure them again manually.

ghost config --db mysql --dbhost <dbhost> --dbuser <dbuser> \
  --dbpass <dbpass> --dbport <dbport> --dbname <dbname>
Enter fullscreen mode Exit fullscreen mode
Update the ghost config values for database

Running the above command will update the config.production.json file. Review the file to make sure its got the expected values.

su node
Enter fullscreen mode Exit fullscreen mode
switch user to node

ghost-cli stops you from updating as a root user. If you wanted to get back to being a root user again, exit.

Before you can update to version 4, ghost wants you to be in the latest version of the currently installed ghost version.

ghost update v3
Enter fullscreen mode Exit fullscreen mode
updates ghost to the latest version of major version 3
ghost update
Enter fullscreen mode Exit fullscreen mode
updates ghost to the latest version; version 4.2.0 at the time of writing

Once ghost is updated, go ahead and kubectl apply with your deployment spec file thats updated to the same version of ghost.

Top comments (0)