Cloud Native 15 min read

Deploy Mall‑Swarm on Kubernetes with Rancher: Full Step‑by‑Step Guide

This article walks through deploying the open‑source mall‑swarm project using Docker for supporting services on a base server and Kubernetes on an application server, covering image packaging, Docker Compose setup, Rancher installation, Nacos configuration, YAML deployments, and Nginx reverse‑proxy access, with full command examples.

macrozheng
macrozheng
macrozheng
Deploy Mall‑Swarm on Kubernetes with Rancher: Full Step‑by‑Step Guide
Due to the popularity of Kubernetes, we finally provide a K8s deployment solution for the mall‑swarm project. After completing the K8s tutorial series, this guide demonstrates the practical steps using the mall‑swarm source.

Server Planning

We use two servers instead of a single‑machine deployment:

Base server (192.168.3.101) runs dependency services such as MySQL, Redis, Elasticsearch, etc., deployed with Docker.

Application server (192.168.3.102) runs the mall‑swarm application services (mall‑admin, mall‑portal, mall‑search, …) deployed with Kubernetes.

Image Packaging and Pushing

Modify

pom.xml

to set your Docker host, then package the project with Maven:

<code>&lt;properties&gt;
    &lt;!-- Change to your Docker remote address --&gt;
    &lt;docker.host&gt;http://192.168.3.101:2375&lt;/docker.host&gt;
&lt;/properties&gt;
</code>

Run the Maven

package

command to build all images, then retag them for the remote repository:

<code>docker tag mall/mall-gateway:1.0-SNAPSHOT macrodocker/mall-gateway:1.0-SNAPSHOT
docker tag mall/mall-auth:1.0-SNAPSHOT macrodocker/mall-auth:1.0-SNAPSHOT
docker tag mall/mall-monitor:1.0-SNAPSHOT macrodocker/mall-monitor:1.0-SNAPSHOT
docker tag mall/mall-admin:1.0-SNAPSHOT macrodocker/mall-admin:1.0-SNAPSHOT
docker tag mall/mall-portal:1.0-SNAPSHOT macrodocker/mall-portal:1.0-SNAPSHOT
docker tag mall/mall-search:1.0-SNAPSHOT macrodocker/mall-search:1.0-SNAPSHOT
</code>

Push the images to Docker Hub (or use the pre‑uploaded images):

<code># Login Docker Hub
docker login
# Push to remote repository
docker push macrodocker/mall-gateway:1.0-SNAPSHOT
docker push macrodocker/mall-auth:1.0-SNAPSHOT
docker push macrodocker/mall-monitor:1.0-SNAPSHOT
docker push macrodocker/mall-admin:1.0-SNAPSHOT
docker push macrodocker/mall-portal:1.0-SNAPSHOT
docker push macrodocker/mall-search:1.0-SNAPSHOT
</code>

Base Server Deployment

Deploy the dependency services with Docker Compose. The project provides a

docker-compose‑env.yml

script; run:

<code>docker-compose -f docker-compose-env.yml up -d
</code>
Docker Compose deployment
Docker Compose deployment

Application Server Deployment

Install Rancher

Pull and run the Rancher Docker image:

<code>docker pull rancher/rancher:v2.5-head
docker run -p 80:80 -p 443:443 --name rancher \
  --privileged \
  --restart=unless-stopped \
  -d rancher/rancher:v2.5-head
</code>
Rancher UI
Rancher UI

After Rancher starts, access it at

http://192.168.3.102

and add the configuration files from the

config

directory to Nacos.

Modify Nacos Configuration

Update the YAML files with the new IP addresses of MySQL, Redis, MongoDB, RabbitMQ, etc.

<code>spring:
  datasource:
    url: jdbc:mysql://192.168.3.101:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
    username: root
    password: root
  redis:
    host: 192.168.3.101
    database: 0
    port: 6379
    password: # no password
</code>

Similar changes are required in

mall-gateway-prod.yaml

,

mall-portal-prod.yaml

,

mall-search-prod.yaml

, etc.

Deploy Applications with Rancher

If image pulling is slow, enter the Rancher container and pull images manually:

<code>docker exec -it rancher /bin/bash
k3s crictl pull macrodocker/mall-gateway:1.0-SNAPSHOT
k3s crictl pull macrodocker/mall-auth:1.0-SNAPSHOT
k3s crictl pull macrodocker/mall-monitor:1.0-SNAPSHOT
k3s crictl pull macrodocker/mall-admin:1.0-SNAPSHOT
k3s crictl pull macrodocker/mall-portal:1.0-SNAPSHOT
k3s crictl pull macrodocker/mall-search:1.0-SNAPSHOT
</code>

Then create Deployments and Services in Rancher using the YAML files located in the

k8s

directory, e.g.,

mall-admin-deployment.yaml

and

mall-admin-service.yaml

.

Deployment YAML
Deployment YAML
Service YAML
Service YAML

Result Verification

View all Deployments in Rancher (screenshot).

View all Services (screenshot).

Check pod logs with

docker ps

or Rancher UI.

Deployments list
Deployments list
Services list
Services list
Pod logs
Pod logs

Expose Services via Nginx Reverse Proxy

Run an Nginx container and configure it to forward

api.macrozheng.com

to the gateway service:

<code>docker run -p 2080:2080 --name nginx \
  -v /mydata/nginx/html:/usr/share/nginx/html \
  -v /mydata/nginx/logs:/var/log/nginx \
  -v /mydata/nginx/conf:/etc/nginx \
  -d nginx:1.10
</code>

Obtain the Rancher container IP (e.g.,

172.17.0.2

) and add the following

api.conf

:

<code>server {
    listen       2080;
    server_name  api.macrozheng.com;

    location / {
        proxy_set_header Host $host:$server_port;
        proxy_pass   http://172.17.0.2:30201;
        index  index.html index.htm;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}
</code>

Add a host entry on the client machine:

<code>192.168.3.102 api.macrozheng.com
</code>

After the reverse proxy is set up, the API documentation is reachable at

http://api.macrozheng.com:2080/doc.html

.

API documentation
API documentation

Conclusion

Deploying the mall‑swarm project to Kubernetes shows that K8s is not as difficult as it seems; many concepts overlap with Docker. New technologies build on existing ones, so mastering Docker and traditional deployment methods helps you adopt Kubernetes more easily.

Project source code: https://github.com/macrozheng/mall-swarm

Cloud NativeDockermicroservicesKubernetesDevOpsRancher
macrozheng
Written by

macrozheng

Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.