This is a Drupal Operator, which makes management of Drupal instances running inside Kuberenetes clusters easy. It was built with the Operator SDK using Ansible Operator.
This Kubernetes Operator is meant to be deployed in your Kubernetes cluster(s) and can manage one or more Drupal instances in any namespace.
First you need to deploy Drupal Operator into your cluster:
kubectl apply -f https://raw.githubusercontent.com/geerlingguy/drupal-operator/master/deploy/drupal-operator.yaml
Then you can create instances of Drupal in any namespace, for example:
-
Create a file named
my-drupal-site.yml
with the following contents:--- apiVersion: drupal.drupal.org/v1alpha1 kind: Drupal metadata: name: my-drupal-site namespace: default spec: # The container image to use for the Drupal deployment. drupal_image: 'drupal:8.8-apache' # Set this to 'true' to use a single-pod database managed by this operator. manage_database: true database_image: mariadb:10 database_pvc_size: 1Gi database_password: change-me # Set this to 'true' to have this operator manage Ingress for the site. manage_ingress: true drupal_hostname: mysite.com
-
Use
kubectl
to create the Drupal site in your cluster:kubectl apply -f my-drupal-site.yml
There are many other options you can provide in the spec
, to control the deployment and how it integrates with external services (e.g. set manage_database
to false
and override the database_
options to integrate with a separate database backend).
You can also deploy
Drupal
applications into other namespaces by changingmetadata.namespace
, or deploy multipleDrupal
instances into the same namespace by changingmetadata.name
.
There are a few moving parts to this project:
- The Docker image which powers Drupal Operator.
- The
drupal-operator.yaml
Kubernetes manifest file which initially deploys the Operator into a cluster.
Each of these must be appropriately built in preparation for a new tag:
Run the following command inside this directory:
operator-sdk build geerlingguy/drupal-operator:0.1.1
Then push the generated image to Docker Hub:
docker push geerlingguy/drupal-operator:0.1.1
Verify the build/chain-operator-files.yml
playbook has the most recent version/tag of the Docker image, then run the playbook in the build/
directory:
ansible-playbook chain-operator-files.yml
After it is built, test it on a local cluster:
minikube start
minikube addons enable ingress
kubectl apply -f deploy/drupal-operator.yaml
kubectl create namespace example-drupal
kubectl apply -f deploy/crds/drupal_v1alpha1_drupal_cr.yaml
<test everything>
minikube delete
If everything is deployed correctly, commit the updated version and push it up to GitHub, tagging a new repository release with the same tag as the Docker image.
molecule test -s test-local
This environment is meant for headless testing (e.g. in a CI environment, or when making smaller changes which don't need to be verified through a web interface). It is difficult to test things like Drupal's front-end or connecting other applications on your local machine to services running inside the cluster, since it is inside a Docker container with no static IP address.
minikube start
minikube addons enable ingress
molecule test -s test-minikube
Minikube is a more full-featured test environment running inside a full VM on your computer, with an assigned IP address. This makes it easier to test things like NodePort services and Ingress from outside the Kubernetes cluster (e.g. in a browser on your computer).
Once the operator is deployed, you can visit the Drupal in your browser by following these steps:
- Make sure you have an entry like
IP_ADDRESS example-drupal.test
in your/etc/hosts
file. (Get the IP address withminikube ip
.) - Visit
http://example-drupal.test/
in your browser.
This is a fork of the original drupal-operator by Thom Toogood. We have long collaborated on Drupal DevOps-related projects and Thom's work is impeccable.
This fork is maintained by Jeff Geerling, author of Ansible for DevOps and Ansible for Kubernetes.