build.gradle
jar {
enabled = false
}
Dockerfile
FROM openjdk:11-jdk
VOLUME /tmp
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-jar","/app.jar"]
kubernetes deployment 배치를 위한 파일 준비합니다.
k8s-example-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: springboot-k8s-deployment
# labels:
# app: springboot-k8s-deployment
spec:
replicas: 3 # Number of replicas that will be created for this deployment
selector:
matchLabels:
app: springboot-k8s-deployment
template:
metadata:
labels:
app: springboot-k8s-deployment
spec:
containers:
- name: springboot-k8s-example
image: mooh2jj/springboot-k8s-example # Image that will be used to containers int the cluster
ports:
- containerPort: 8080 # The port that the container is running on in the cluster
TestController
@RestController
public class TestController {
@GetMapping("/dsg")
public String dsg() {
return "dsg!!";
}
}
minikube start
kubectl apply -f kubernate-example-deployment.yaml
# deployment.apps/springboot-k8s-deployment created
kubectl get pods
kubectl get deployments
그중에 하나 컨테이너 log를 확인하자.
kubectl logs springboot-k8s-deployment-5cddc89bc7-485vg
제대로 나오는거 확인
k8s-service.yaml
apiVersion: v1
kind: Service
metadata:
name: springboot-k8s-service
spec:
selector:
app: springboot-k8s
ports:
- protocol: "TCP"
port: 8080 # The port that the container is running on in the cluster
targetPort: 8080 # The port exposed by the service
type: NodePort # type of the service
kubectl apply -f k8s-service.yaml
kubectl get service
minikube ip
# 192.168.49.2
❗{192.168.49.2}:{30135}
로컬에서 확인이 안됨 (2023-01-08)
문제
minikube dashboard