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

张开发
2026/4/18 12:15:21 15 分钟阅读

分享文章

minikube+docker desktop搭建k8s环境部署SpringBoot应用(仅仅是玩玩,端口映射很麻烦)
1)先运行起来DockerDesktop2)下载地址kubernetes/minikube: Run Kubernetes locally3)创建2c4g的k8s集群minikube start --force --driverdocker --cpus2 --memory4096mb --base-imageregistry.cn-hangzhou.aliyuncs.com/google_containers/kicbase:v0.0.444)检查k8s集群状态minikube.exe status minikube type: Control Plane host: Running kubelet: Running apiserver: Running kubeconfig: Configured5)DockerfileFROM 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 --frombuild /build/target/netty-game-server-0.0.1-SNAPSHOT.jar app.jar EXPOSE 7000 ENTRYPOINT [java, -jar, /app/app.jar]6)k8s下编写deployment.ymalapiVersion: 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: 20service.yamlapiVersion: 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: 307007)部署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 appnetty-game-server kubectl get svc netty-game-server8)打开UI界面查看当前minikube中运行了哪些应用minikube dashboard9)查看日志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

更多文章