minikube+docker desktop搭建k8s环境部署SpringBoot应用(仅仅是玩玩,端口映射很麻烦)

1)先运行起来DockerDesktop

2)下载地址

kubernetes/minikube: Run Kubernetes locally

3)创建2c4g的k8s集群

复制代码
minikube start --force --driver=docker --cpus=2 --memory=4096mb --base-image=registry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.44

4)检查k8s集群状态

复制代码
minikube.exe status

minikube
type: Control Plane
host: Running
kubelet: Running
apiserver: Running
kubeconfig: Configured

5)Dockerfile

复制代码
FROM maven:3.9.9-eclipse-temurin-17 AS build
WORKDIR /build
COPY pom.xml .
COPY settings.xml /root/.m2/settings.xml
RUN mvn -s /root/.m2/settings.xml -B -DskipTests dependency:go-offline
COPY src ./src
RUN mvn -s /root/.m2/settings.xml -B -DskipTests package

FROM eclipse-temurin:17-jre
WORKDIR /app
COPY --from=build /build/target/netty-game-server-0.0.1-SNAPSHOT.jar app.jar
EXPOSE 7000
ENTRYPOINT ["java", "-jar", "/app/app.jar"]

6)k8s下编写

deployment.ymal

复制代码
apiVersion: apps/v1
kind: Deployment
metadata:
  name: netty-game-server
  labels:
    app: netty-game-server
spec:
  replicas: 1
  selector:
    matchLabels:
      app: netty-game-server
  template:
    metadata:
      labels:
        app: netty-game-server
    spec:
      containers:
        - name: netty-game-server
          image: netty-game-server:0.0.1
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 7000
              protocol: TCP
          readinessProbe:
            tcpSocket:
              port: 7000
            initialDelaySeconds: 5
            periodSeconds: 10
          livenessProbe:
            tcpSocket:
              port: 7000
            initialDelaySeconds: 15
            periodSeconds: 20

service.yaml

复制代码
apiVersion: v1
kind: Service
metadata:
  name: netty-game-server
spec:
  type: NodePort
  selector:
    app: netty-game-server
  ports:
    - name: tcp-game
      protocol: TCP
      port: 7000
      targetPort: 7000
      nodePort: 30700

7)部署

复制代码
minikube image build -t netty-game-server:0.0.1 .
kubectl apply -f k8s/deployment.yaml
kubectl apply -f k8s/service.yaml
kubectl get pods -l app=netty-game-server
kubectl get svc netty-game-server

8)打开UI界面查看当前minikube中运行了哪些应用

复制代码
minikube dashboard

9)查看日志

复制代码
PS C:\Users\Admin\Desktop> kubectl logs -f deploy/netty-game-server

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/

 :: Spring Boot ::                (v3.3.5)

2026-04-01T14:09:26.032Z  INFO 1 --- [netty-game-server] [           main] c.e.g.NettyGameServerApplication         : Starting NettyGameServerApplication v0.0.1-SNAPSHOT using Java 17.0.18 with PID 1 (/app/app.jar started by root in /app)
2026-04-01T14:09:26.035Z  INFO 1 --- [netty-game-server] [           main] c.e.g.NettyGameServerApplication         : No active profile set, falling back to 1 default profile: "default"
2026-04-01T14:09:26.847Z  INFO 1 --- [netty-game-server] [           main] c.e.g.NettyGameServerApplication         : Started NettyGameServerApplication in 1.8 seconds (process running for 2.495)
2026-04-01T14:09:26.994Z  INFO 1 --- [netty-game-server] [           main] com.example.gameserver.NettyTcpServer    : Netty TCP game server started on port 7000
相关推荐
Lvan的前端笔记3 小时前
docker:每个前端项目一个 Nginx 容器还是只有一个Nginx容器
前端·nginx·docker
姜鱼问生3 小时前
Nginx 缓存命中率监控:从 X-Cache-Status 到实时统计
运维·nginx·缓存
Apipi*4 小时前
30天速通Linux 第六章信号及信号处理
linux·运维·信号处理
运维行者_5 小时前
网络性能监控怎么做?从自动发现到根因分析的4个环节
运维·服务器·网络·人工智能·支持向量机
此时不提桶,更待何时5 小时前
06-14-A-Kafka集群运维与迁移实战详解
运维·kafka
IT研究所7 小时前
AI-ITR平台如何减少客户问题反复升级?
大数据·运维·人工智能·低代码·自然语言处理·安全架构·企微
AIgorithmGEEK7 小时前
[Linux]从手写报头到内核套路:序列化、反序列化与自定义协议全链路
linux·运维·服务器·网络·序列化·反序列化
Nil2087 小时前
leetcode 139单词拆分
linux·运维·服务器
Starry-sky(jing)7 小时前
BUG: unable to handle kernel paging request 完整排查:dmesg 四要素与三路定罪
linux·运维·服务器·内核·排障
mounter6258 小时前
从硬件互连到操作系统变革:CXL 技术演进与 Linux 内核工程挑战
linux·运维·服务器