Week One

dockerize the eccomerce site

Posted by Charles Vosloo on Tuesday, March 5, 2024

Step 1: Certification

KodeKloud have excellent resources: The Certified Kubernetes Application Developer (CKAD) and what I enjoyed the most was the Ultimate Certified Kubernetes CKAD Mock Exams. I completed the CKA on 26 may 2021 and the CKS on 18 Nov 2021. cka

Step 2: Containerize Your E-Commerce Website and Database

A. Web Application Containerization

The first step was to set up civo and kubectl cli client running on ubuntu Windows WSL running with Docker Desktop installed.

There are two application to deploy to Kubernetes, which I call web and mysql

  1. Web-app (the ’learning-app-ecomerce site cloned from kodekloudhub)
  2. mariadb:lts (pulled form DockerHub)

The first needs containerizing:

docker build -t journeyman/ecom-web:v1 .

I used the following Dockerfile, arrived at through trial and error:

RUN docker-php-ext-install pdo pdo_mysql mysqli
WORKDIR /var/www/html
COPY  ./Web-app/ /var/www/html/
EXPOSE 80
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]

I initially included in the line:

COPY ./db-load-script.sql /docker-entrypoint-initdb.d/

but then pulled it because the task is to run this database initialization script, which populates the database, (db-load-script.sql) as a Kubernetes configMap.

For mysql to communicate with the PHP website, requires default password(s) and usernames, which as a best practice, is not a good idea to hard code into the Dockefile or environment variables. Therefore I didn’t wait for step 12 to add another configmap for the mysql host, port and database and to add a kubernetes secret for the mysql user,password and root password.

The other basic security measure is to put the project in a namespace.