Add custom init containers
If you want to run migrations or perform other operations that are required before your site starts, you’ll want to do it in an init container, so here are the steps to add one.
If you don’t know what an init container is, read more about them on the Kubernetes docs .
NOTE
This how-to assumes that you know how to connect to your cluster.
1. Edit the site’s WordPress Kubernetes resource
To add an init container, you will currently need to edit the WordPress Kubernetes resource that represents your site. Its details can be found in the
Runtime section
, under the Kubernetes Project Namespace
and Kubernetes Site Name
site fields.
For this example, let’s assume the project namespace is proj-jqojzq and the site name is my-site-com-h9wgm. Run the following command:
kubectl edit wordpress -n proj-jqojzq my-site-com-h9wgm
2. Add init containers
The resource hopefully opened in your text editor. There you will be able
to add your init containers in the .spec.initContainers
section (if it is missing you may safely add it).
3. Update the sync-init-containers annotation
In order to use the same image and environment variables as the WordPress container of your site, you will have to add an annotation that contains the names of your init containers. For this example, let’s assume you’ve added two init containers, named migrations-init and cleanup-init.
The annotation you’ll then add to .metadata.annotations
would be:
dashboard.presslabs.com/sync-init-containers: "migrations-init, cleanup-init"
The Bitpoke App will then sync the image and environment variable fields of the specified init containers with the ones of the WordPress container, everytime they change.