Master Rancher: Visual Kubernetes Management and Deploying MySQL & SpringBoot
Learn how to simplify Kubernetes administration with Rancher by installing Docker, deploying Rancher, creating MySQL and SpringBoot deployments via YAML, configuring services, and exposing the application through Nginx, all illustrated with step‑by‑step commands and screenshots.
Rancher Overview
Rancher is a container management platform designed for companies using containers. It simplifies the Kubernetes workflow, allowing developers to run Kubernetes anywhere, meeting IT standards and empowering DevOps teams.
Docker Installation
Although Rancher can be installed in several ways, using Docker is the simplest. Install Docker first.
Install required packages:
<code>yum install -y yum-utils device-mapper-persistent-data lvm2</code>Add Docker repository:
<code>yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo</code>Install Docker:
<code>yum install docker-ce</code>Start Docker:
<code>systemctl start docker</code>Rancher Installation
After Docker is installed, pull and run the Rancher image. Rancher includes a built‑in Kubernetes cluster, similar to Minikube.
Pull Rancher image:
<code>docker pull rancher/rancher:v2.5-head</code>Run Rancher container (may take a few minutes to start):
<code>docker run -p 80:80 -p 443:443 --name rancher \
--privileged \
--restart=unless-stopped \
-d rancher/rancher:v2.5-head</code>Access Rancher UI at
https://192.168.5.46and set the admin account.
Configure the Server URL so other nodes can reach the Rancher instance.
Rancher Usage
On the Rancher homepage you can view all clusters (only the Rancher‑installed cluster at this point). Clicking a cluster name shows its status and provides a
kubectlcommand button. The dashboard displays Deployments, Services, Pods, etc.
Hands‑On: Deploy MySQL
Create a MySQL Deployment via YAML (Deployments → Create → Edit as YAML).
<code>apiVersion: apps/v1
kind: Deployment
metadata:
# Deployment name
name: mysql-deployment
# Namespace
namespace: default
labels:
app: mysql
spec:
# Number of pod replicas
replicas: 1
selector:
matchLabels:
app: mysql
template:
metadata:
labels:
app: mysql
spec:
containers:
- name: mysql
image: mysql:5.7
ports:
- containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
value: root
volumeMounts:
- mountPath: /var/log/mysql
name: log-volume
- mountPath: /var/lib/mysql
name: data-volume
- mountPath: /etc/mysql
name: conf-volume
volumes:
- name: log-volume
hostPath:
path: /home/docker/mydata/mysql/log
type: DirectoryOrCreate
- name: data-volume
hostPath:
path: /home/docker/mydata/mysql/data
type: DirectoryOrCreate
- name: conf-volume
hostPath:
path: /home/docker/mydata/mysql/conf
type: DirectoryOrCreate</code>You can also configure the Deployment via the UI if you are unfamiliar with the YAML syntax.
Create MySQL Service
Create a Service via YAML (Services → Create → NodePort → Edit as YAML). The
namespacefield is required.
<code>apiVersion: v1
kind: Service
metadata:
# Namespace
namespace: default
# Service name
name: mysql-service
spec:
# Expose via NodePort
type: NodePort
selector:
app: mysql
ports:
- name: http
protocol: TCP
port: 3306
targetPort: 3306
nodePort: 30306</code>After deployment, create a database named
malland import the schema from the provided GitHub SQL file.
Deploy SpringBoot Application
Create a Deployment for the SpringBoot app via YAML (Deployments → Create → Edit as YAML).
<code>apiVersion: apps/v1
kind: Deployment
metadata:
namespace: default
name: mall-tiny-fabric-deployment
labels:
app: mall-tiny-fabric
spec:
replicas: 1
selector:
matchLabels:
app: mall-tiny-fabric
template:
metadata:
labels:
app: mall-tiny-fabric
spec:
containers:
- name: mall-tiny-fabric
image: macrodocker/mall-tiny-fabric:0.0.1-SNAPSHOT
ports:
- containerPort: 8080
env:
- name: spring.datasource.url
value: jdbc:mysql://mysql-service:3306/mall?useUnicode=true&characterEncoding=utf-8&serverTimezone=Asia/Shanghai
- name: logging.path
value: /var/logs
volumeMounts:
- mountPath: /var/logs
name: log-volume
volumes:
- name: log-volume
hostPath:
path: /home/docker/mydata/app/mall-tiny-fabric/logs
type: DirectoryOrCreate</code>Create SpringBoot Service
<code>apiVersion: v1
kind: Service
metadata:
namespace: default
name: mall-tiny-fabric-service
spec:
type: NodePort
selector:
app: mall-tiny-fabric
ports:
- name: http
protocol: TCP
port: 8080
targetPort: 8080
nodePort: 30180</code>After creation, the deployment becomes ready as shown in the Rancher UI.
Expose Application via Nginx Reverse Proxy
Since Rancher occupies port 80, run Nginx on port 2080.
<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>Add an Nginx configuration file
mall-tiny-rancher.confto proxy the domain
mall-tiny.macrozheng.comto the SpringBoot service.
<code>server {
listen 2080;
server_name mall-tiny.macrozheng.com; # modify domain
location / {
proxy_set_header Host $host:$server_port;
proxy_pass http://172.17.0.3:30180; # proxy address
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
</code>Update the host file on the Linux server with
192.168.5.46 mall-tiny.macrozheng.comand access the application at
http://mall-tiny.macrozheng.com:2080/swagger-ui.html.
Conclusion
Using Rancher for visual Kubernetes management greatly reduces deployment and operational complexity. A single Docker command can launch Rancher, and the UI allows you to monitor application status, execute scripts, and configure resources without writing scripts.
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.