Deployment with Kubernetes
This tutorial explains how to deploy an application created in the setup guide to Kubernetes using a Digital Ocean Managed Kubernetes cluster.
Notice
Setting up WebSight CMS on Digital Ocean via the steps presented in this tutorial will incur Digital Ocean hosting costs of approximately 2 dollars per day.
Prerequisites
After finishing Creating and developing WebSight CMS project guide you should already have:
- Docker installed and running on your local machine.
- Java 17 (e.g. AdoptOpenJDK 17) and Maven installed on your local machine.
To complete this tutorial, you will also need:
- A Digital Ocean account
- The Digital Ocean CLI installed
kubectl
installed (if you use Docker Desktop, kubectl should already be installed)helm
installed
Step 1: Digital Ocean configuration
Digital Ocean does not support persistent volumes
with ReadWriteMany
access mode. For simplicity sake, we create a single node Kubernetes cluster to work with ReadWriteOnce
access mode.
- Start by Authenticating
doctl
with an API token. Set API token scopes as follows:Read
andWrite
-
Create a Kubernetes cluster using the Control Panel with the following options:
- scaling type:
Fixed size
- machine type:
Basic nodes
- node plan:
Professional plans 8 GB RAM / 4 vCPUs
- nodes:
1
- scaling type:
- Create a Container Registry. The
Basic
plan is sufficient.
Step 2: Kubernetes cluster configuration
Step 2: Project configuration
Maven
- Update the
io.fabric8:docker-maven-plugin
plugin configuration indistribution/pom.xml
as follows.- Add the following
buildx
extension to the cms and nginx images<build>
sections: - Add the following
execution
:
- Add the following
- Add
<docker.skip.push>true</docker.skip.push>
property to the mainpom.xml
.
Environment
-
Create a
values.yml
file in theenvironment/k8s
directory with the following content:-cms: image: repository: registry.digitalocean.com/<YOUR_REGISTRY_NAME>/cms tag: latest nginx: replicas: 1 image: repository: registry.digitalocean.com/<YOUR_REGISTRY_NAME>/nginx tag: latest ingress: enabled: true hosts: cms: "cms.<YOUR_CLUSTER_IP>.nip.io" site: "site.<YOUR_CLUSTER_IP>.nip.io"
YOUR_REGISTRY_NAME
- replace with Digital Ocean Container Registry name -YOUR_CLUSTER_IP
- replace with Digital Ocean Load Balancer IP (you can obtain it by runningdoctl compute load-balancer list
)See WebSight Helm chart documentation for more details.
Step 3: Build and deployment
- Configure Docker to
push
to andpull
from Container Registry. - In the project root run:
- Switch the
kubectl
context to your cluster in Digital Ocean (kubectl config use-context <CONTEXT_NAME>
) - From
environment/k8s
run:Usehelm repo add websight https://websight-io.github.io/charts helm repo update websight helm install my-websight websight/websight-cms -f values.yml
helm upgrade my-websight websight/websight-cms -f values.yml
for updating the installation. It may take a couple of minutes to finish. - Route your domain to the Application Load Balancer (which you created using Docker Compose in the previous step) by creating a new Hosted Zone.
Step 4: Verification
- Check the Kubernetes Dashboard to verify that all pods are running.
- Open the WebSight CMS admin panel on
https://cms.<YOUR_CLUSTER_IP>.nip.io/
(SSL is not covered in this guide). Use the credentialswsadmin
/wsadmin
to log in.
Cleanup
- When finished, you can delete your Kubernetes cluster along with the Load Balancer and volumes.
- You may also delete your Container Registry.