News
Faster Speeds: Bandwidth for vStack Servers in Kazakhstan Increased to 200 Mbps
BS
June 25 2025
Updated June 24 2025

Kubernetes Deployment Guide Hosting OpenCart as a Containerized eCommerce Solution

E-commerce is a domain where stability and scalability directly impact revenue. Imagine an online store during a major sale: thousands of users placing orders simultaneously, but traditional infrastructure buckles under the load. The site slows down, customers leave, and the business loses money. OpenCart is a popular platform for small and medium businesses, but its performance on standard servers is limited. Kubernetes addresses these challenges by providing automatic scaling, fault tolerance, and flexibility. This guide will walk you through deploying OpenCart in Kubernetes, transforming your store into a reliable and elastic system ready for any load.

Stage 1 - Preparing the Container — The Foundation

Option 1 - Official Image (Quick Start)

Ideal for quick setup, this image includes pre-installed dependencies and configurations.

# Pull the optimized Bitnami image for OpenCart

docker pull bitnami/opencart:latest

# Test run to verify functionality

docker run -d -p 8080:8080 -p 8443:8443 \

-e OPENCART_USERNAME=admin \

-e OPENCART_PASSWORD=StrongPassword \

bitnami/opencart

Option 2 - Custom Build (Full Control)

A custom image provides control over versions and settings, ideal for specific requirements.

1. Create `Dockerfile`:

FROM php:8.1-apache

# Install dependencies required for OpenCart

RUN apt-get update && apt-get install -y \

libzip-dev libpng-dev libjpeg-dev libfreetype6-dev libonig-dev libxml2-dev \

&& docker-php-ext-configure gd --with-freetype --with-jpeg \

&& docker-php-ext-install -j$(nproc) gd mysqli pdo_mysql zip opcache

# Download and extract OpenCart

ENV OPENCART_VERSION 4.0.2.2

RUN curl -O https://github.com/opencart/opencart/releases/download/${OPENCART_VERSION}/opencart-${OPENCART_VERSION}.zip \

&& unzip opencart-${OPENCART_VERSION}.zip \

&& mv upload /var/www/html \

&& rm opencart-${OPENCART_VERSION}.zip

# Configure permissions and configuration files

RUN chown -R www-data:www-data /var/www/html \

&& mv /var/www/html/config-dist.php /var/www/html/config.php \

&& mv /var/www/html/admin/config-dist.php /var/www/html/admin/config.php

# Optimize PHP for performance

COPY opcache.ini /usr/local/etc/php/conf.d/opcache.ini

COPY 000-default.conf /etc/apache2/sites-available/000-default.conf

EXPOSE 8080

2. Build the image:

docker build -t mycompany/opencart:3.0 .

Stage 2 - Deployment in Kubernetes — Orchestrating Success

Solution Architecture:

Cloudflare provides protection and caching, Ingress manages traffic, Redis speeds up sessions, and MySQL stores data.

[Пользователь] → [Ingress] → [PrestaShop Pods] → [Redis] → [MariaDB] - visual selection (3)
Picture 1 - OpenCart

Step 1 - Install MySQL via Helm

Helm simplifies MySQL installation with preconfigured settings.

# Add Bitnami repo and install MySQL

helm repo add bitnami https://charts.bitnami.com/bitnami

helm install opencart-db bitnami/mysql \

--namespace opencart \

--set auth.rootPassword=DB_ROOT_PASS \

--set auth.database=opencart_db \

--set auth.username=opencart_user \

--set auth.password=OPENCART_DB_PASS \

--set persistence.size=20Gi

Step 2 - Configure OpenCart

ConfigMap stores settings injected into containers.

`opencart-configmap.yaml`:

apiVersion: v1

kind: ConfigMap

metadata:

name: opencart-config

namespace: opencart

data:

OPENCART_HOST: "shop.example.com" # Store domain

OPENCART_USERNAME: "admin" # Admin username

DB_HOST: "opencart-db-mysql" # Database host

DB_NAME: "opencart_db" # Database name

DB_USER: "opencart_user" # Database user

SESSION_DRIVER: "redis" # Session driver

REDIS_HOST: "opencart-redis-master" # Redis host

Step 3 - Deploy StatefulSet

StatefulSet ensures stable pod state with persistent storage.

`opencart-statefulset.yaml`:

apiVersion: apps/v1

kind: StatefulSet

metadata:

name: opencart

namespace: opencart

spec:

serviceName: opencart

replicas: 3

selector:

matchLabels:

app: opencart

template:

metadata:

labels:

app: opencart

spec:

initContainers:

- name: init-permissions

image: busybox:1.36

command: ['sh', '-c', 'chown -R 33:33 /var/www/html']

volumeMounts:

- name: opencart-data

mountPath: /var/www/html

containers:

- name: opencart

image: mycompany/opencart:3.0

envFrom:

- configMapRef:

name: opencart-config

- secretRef:

name: opencart-secrets

ports:

- containerPort: 8080

volumeMounts:

- name: opencart-data

mountPath: /var/www/html

livenessProbe:

httpGet:

path: /index.php

port: 8080

readinessProbe:

httpGet:

path: /health-check.php

port: 8080

volumeClaimTemplates:

- metadata:

name: opencart-data

spec:

accessModes: ["ReadWriteOnce"]

storageClassName: "ssd"

resources:

requests:

storage: 10Gi

Step 4 - Service and Ingress

Service and Ingress provide access to OpenCart via a single domain with HTTPS support.

`opencart-service.yaml`:

apiVersion: v1

kind: Service

metadata:

name: opencart-service

namespace: opencart

spec:

selector:

app: opencart

ports:

- protocol: TCP

port: 80

targetPort: 8080

apiVersion: networking.k8s.io/v1

kind: Ingress

metadata:

name: opencart-ingress

namespace: opencart

annotations:

nginx.ingress.kubernetes.io/affinity: "cookie"

cert-manager.io/cluster-issuer: "letsencrypt-prod"

spec:

tls:

- hosts:

- shop.example.com

secretName: opencart-tls

rules:

- host: shop.example.com

http:

paths:

- path: /

pathType: Prefix

backend:

service:

name: opencart-service

port:

number: 80

Stage 3 - Final Setup — Launching the Store

Used for `readinessProbe` to ensure Kubernetes correctly determines pod readiness.

Initial Setup:

Open `https://shop.example.com`.

Follow the setup wizard:

- Database Configuration:

Host: opencart-db-mysql

User: opencart_user

Database: opencart_db

Password: from Kubernetes Secrets

- Administrator: Specify email and password for admin access.

Create health-check.php:

Create `/var/www/html/health-check.php`:

 

Configure Redis for Sessions:

// In /config.php

define('SESSION_DRIVER', 'redis');

define('CACHE_HOSTNAME', 'opencart-redis-master:6379');

Performance Optimization:

In the admin panel: System → Settings → Server

Enable caching: Yes

Output compression: GZIP

Cache duration: 86400

Configure CDN for static assets:

// In /config.php and /admin/config.php

define('HTTP_SERVER', 'https://cdn.example.com/');

Autoscaling:

HPA automatically scales pods based on CPU load.

`opencart-hpa.yaml`:

apiVersion: autoscaling/v2

kind: HorizontalPodAutoscaler

metadata:

name: opencart-hpa

namespace: opencart

spec:

scaleTargetRef:

apiVersion: apps/v1

kind: StatefulSet

name: opencart

minReplicas: 3

maxReplicas: 12

metrics:

- type: Resource

resource:

name: cpu

target:

type: Utilization

averageUtilization: 70

OpenCart in Kubernetes provides:

  • Fault Tolerance:
    • Automatic recovery from failures.
  • Scalability:
    • Flexible resource scaling under load.
  • Performance:
    • Optimization via Redis and CDN.

By following this guide, you’ll create a store ready for growth and high traffic.

Vote:
5 out of 5
Аverage rating : 5
Rated by: 1
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.