Using Wordpress CLI image on Kubernetes

2/5/2018

We have a custom docker image based on the official wordpress image that holds a custom theme that we are developing. We have CI/CD on this project using Gitlab CI and deploying branches on a bare-metal Kubernetes Cluster v1.6 for review. It works fine, however we are trying to enhance the process by automating the required manual actions when a new instance is deployed:

  • Installing Wordpress
    • Setting admin credential
    • Setting site name and url
  • Activating theme
  • Activating plugins
  • Importing data
  • etc.

wp-cli has all the commands needed. But how to use it with containers and K8S? We are aware that there are two options:

  • Installing the tool in our WordPress based image.
  • Using a second container that contains only wp-cli and communicates with the main container.

There are WordPress images with preinstalled wp-cli (e.g. tutum-docker-wordpress), but we don't feel this is the correct way. At some point we would like to use a CronJob resource with the cli image to export data each day and we are trying to make the process as generic as possible and we would like to stick with the official images so the second option is preferred. Based on our research in order to implement the second option we will need to achieve two things:

  • Access the files of the WordPress installation from the CLI container.
  • Do not retry after successful execution.

We researched couple of option with no complete success:

  • Second container in the same pod - It looks possible to share files between both containers using EmptyDir, however even if the container succeeds it will be restarted.
  • InitContainer - This one sounds very tempting because database migrations are done this way. However it seems impossible to get the files unless you use a custom image.
  • Job - It is designed exactly to handle one-time tasks, however accessing the files of a container in a pod does not seem to be possible.

This seems like a pretty common feature when you deploy review deployments of Wordpress on Kubernetes and someone should have already done that. But we could not find any specific info about this use case.

Please advice on what is the best way to achieve the desired implementation according to you and how?

-- kmotsov
kubernetes
wordpress
wp-cli

1 Answer

1/22/2019

You can use an NFS based file system and mount your wordpress content into any type of workload.

If you need something to help you get started check out https://matthewdavis.io/highly-available-wordpress-on-kubernetes/.

-- yomateo
Source: StackOverflow