Joomla is a content management system (CMS) that powers nearly two million active websites worldwide. Joomla is a popular choice for small and large organizations thanks to its flexibility, scalability, and wide customization possibilities. Its open-source nature enables developers to contribute and expand its capabilities via a wide library of extensions and templates.

This tutorial walks you through each step of deploying Joomla on a Civo Kubernetes cluster, ensuring a seamless and successful installation.

Prerequisites

Before you begin, ensure you have the following:

  • A Civo account (create one at Civo).
  • Basic knowledge of Kubernetes concepts.
  • Installed tools: Kubectl.

Setting Up Civo Kubernetes Cluster

To create a cluster using the Civo CLI, run the following command:

civo k3s create joomla_demo  --wait --save --merge --switch

The command above will build a 3-node K3s cluster called joomla_demo with a g4s.kube.medium instance. Wait for the cluster to be live before saving the kubeconfig alongside your current ~/.kube/config file.

After performing the command, the Civo CLI will display the completion time and confirm that your kubeconfig has been merged and that the current context has been switched to the new cluster.

Merged with main kubernetes config: /home/yongdev/.kube/config

Access your cluster with:
kubectl get node
The cluster joomla_demo (81f9d9f6-4662-4ebc-bec1-b16cf72cdf95) has been created in 1 min 36 sec

Setting Up Persistent Storage

You will need Persistent Storage for database data and Joomla configurations and data to guarantee that application-related data is kept. You could create and install MariaDB from scratch, but why would you do that when the Civo marketplace already includes critical Kubernetes technologies like MariaDB?

To install MariaDB from the CLI, run the code below in your terminal:

civo kubernetes applications add mariadb:5GB --cluster=joomla_demo

After a moment, you will get an output similar to this:

The application was installed in the Kubernetes cluster joomla_demo

The installation from the marketplace creates a service, a PV claim, and a deployment. You can view the source here.

You can confirm if the MariaDB pod is operational by inputting:

kubectl get pods -l app=mariadb

While the installation of MariaDB went on, Civo created a password for the root user. This password should be copied from the dashboard in the Installed application section because it is needed for this process.

Setting Up Persistent Storage

Next, you must set up a database and user account in MariaDB for our Joomla service. Run the command shown below:

kubectl exec -it svc/mariadb -- /bin/sh

mariadb -u root -p

This command launches a shell within the MariaDB service instance and will attempt to connect to the server. You will be prompted to enter a password. Enter the password you copied from the dashboard.

After entering the right credentials, you will have access to the server. To create a database and user account, run the SQL statement below. Ensure you tweak the values of the user account (joomla_user and strong-password) at will:

CREATE DATABASE joomla_db;

CREATE USER joomla_user identified by 'strong-password';

GRANT ALL ON joomla_db.* TO joomla_user;

The last thing to do here is to create a persistent volume (PV) for the Joomla deployment instance. Create a joomla-pv.yml file and copy the code below into the new file:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: joomla-pv-claim
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi

Apply the newly created file by running:

kubectl apply -f joomla-pv.yml

You will receive a message confirming its creation.

persistentvolumeclaim/joomla-pv-claim created

Deploying Joomla

Before deploying Joomla, you need to install a cert manager to create a TLS certificate. In the terminal, run the following:

civo kubernetes applications add cert-manager --cluster=joomla_demo

You should receive a message verifying the installation. After a while, check that it's running by inputting:

kubectl get pods -n cert-manager

If all the pods are running, create a file provider.yaml and copy the following code into it. You will need to replace <YOUREMAILHERE> with your Civo registered e-mail:

apiVersion: cert-manager.io/v1
kind: ClusterIssuer
metadata:
  name: letsencrypt-prod
  namespace: default
spec:
  acme:
    # The ACME server URL
    server: https://acme-v02.api.letsencrypt.org/directory
    # Email address used for ACME registration
    email: <YOUR_EMAIL_HERE>
    # Name of a secret used to store the ACME account private key
    privateKeySecretRef:
      name: letsencrypt-prod
    # Enable the HTTP-01 challenge provider
    solvers:
    - http01:
        ingress:
          class: traefik

Apply the certificate on the cluster:

kubectl apply -f provider.yml

Then, create a file named joomla-app.yaml and copy the following code into it:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: joomla
  labels:
    app: joomla
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: joomla
  template:
    metadata:
      labels:
        app: joomla
    spec:
      containers:
        - name: joomla
          image: joomla:5.2
          imagePullPolicy: IfNotPresent
          ports:
          - containerPort: 80
            protocol: TCP
          volumeMounts:
          - name: joomla-persistent-storage
            mountPath: /var/www/html   
          env:
          - name: JOOMLA_DB_HOST
            value: mariadb
          - name: JOOMLA_DB_PASSWORD
            valueFrom:
              secretKeyRef:
                name: mysql-pass
                key: MYSQL_ROOT_PASSWORD 

      volumes:
      - name: joomla-persistent-storage
        persistentVolumeClaim:
          claimName: joomla-pv-claim

You can now create the deployment by running:

kubectl apply -f joomla-app.yml

The next thing to do is to create a service for the application. You can do that by creating a file joomla-svc.yaml and pasting the code below into it:

apiVersion: v1
kind: Service
metadata:
  name: joomla-service
spec:
  selector:
    app: joomla
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80

After the definition of the service, you can now apply it:

kubectl apply -f joomla-svc.yaml

The final step is to publish the just-created service to the web. Civo automatically installs some applications when creating a new cluster, including the Traefik ingress controller, which exposes services to externally reachable URLs.

Copy the code below to a file called ingress.yaml, replacing YOURCLUSTERID with your own available on your Civo dashboard:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: joomla
  annotations:
    ingressClassName: traefik
    cert-manager.io/cluster-issuer: letsencrypt-prod
    ingress.kubernetes.io/ssl-redirect: "true"  
spec:
  tls:
    - hosts:
      - joomla.YOURCLUSTERID.k8s.civo.com
      secretName: letsencrypt-prod  
  rules:
  - host: joomla.YOURCLUSTERID.k8s.civo.com
    http:
      paths:
      - backend:
          service:
            name: joomla-service
            port:
              number: 80
        path: /
        pathType: Prefix

Then, apply this file to your cluster:

kubectl apply -f ingress.yml

After the file has been applied, you can access your Joomla instance from the URL (joomla.YOURCLUSTERID.k8s.civo.com) a few minutes later.

Deploying Joomla on Civo

Run the installer and enjoy your website! Remember to use the user account and database you created before, and the database host is mariadb.

Deploying Joomla on Civo

After the installation is complete, you should have your Joomla site ready. Congratulations! That’s how to deploy Joomla on Civo Kubernetes.

Summary

In this guide, you went through how to successfully deploy Joomla on a Civo Kubernetes cluster with MariaDB and Traefik, set up persistent storage, configure ingress, and secure your installation with HTTPS.

This deployment approach ensures that your Joomla website or application remains robust and resilient in a cloud-native environment as you expand your Joomla project. Happy building!