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.
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:
<properties>
<!-- Change to your Docker remote address -->
<docker.host>http://192.168.3.101:2375</docker.host>
</properties>Run the Maven package command to build all images, then retag them for the remote repository:
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-SNAPSHOTPush the images to Docker Hub (or use the pre‑uploaded images):
# 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-SNAPSHOTBase Server Deployment
Deploy the dependency services with Docker Compose. The project provides a docker-compose‑env.yml script; run:
docker-compose -f docker-compose-env.yml up -dApplication Server Deployment
Install Rancher
Pull and run the Rancher Docker image:
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-headAfter 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.
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 passwordSimilar 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:
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-SNAPSHOTThen 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.
Result Verification
View all Deployments in Rancher (screenshot).
View all Services (screenshot).
Check pod logs with docker ps or Rancher UI.
Expose Services via Nginx Reverse Proxy
Run an Nginx container and configure it to forward api.macrozheng.com to the gateway service:
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.10Obtain the Rancher container IP (e.g., 172.17.0.2) and add the following api.conf:
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;
}
}Add a host entry on the client machine:
192.168.3.102 api.macrozheng.comAfter the reverse proxy is set up, the API documentation is reachable at http://api.macrozheng.com:2080/doc.html.
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
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
