Using Wordpress CLI image on Kubernetes Using Wordpress CLI image on Kubernetes kubernetes kubernetes

Using Wordpress CLI image on Kubernetes


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/.


Based on @kotsov's hint above, we got this working using init containers in the deployment.

Steps:

  • The first init container starts the wordpress image, but with args overridden to ["apache2-foreground","-version"]. This will cause it to run the entry-point, installing/setting up wordpress if necessary, but then exiting with the version.
  • The second init container is the wordpress cli with its commands.
  • After these, the wordpress container is let run again.

We also set these up on a persistent volume for /var/www/html so if it's started again it wont have to do all this. The init steps will skip initialisation steps based on directory contents.

In the deployment template:

initContainers:- name: Initialise Wordpress  image: wordpress: <version>  args: ["apache2-foreground","-version"]  env:     <your wordpress env>  volumes:    <shared volume info>- name: Wordpress CLI commands  image: wordpress-cli: <version>  env:     <your wordpress cli env>  volumes:    <shared volume info>containers:- name: Wordpress  image: wordpress: <version>  env:     <your wordpress env>  volumes:    <shared volume info>