kubernetes 쿠버네티스 SpringBoot deployment 배치 설정

devdo·2022년 3월 16일
0

Kubernetes

목록 보기
1/1
post-thumbnail

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 에서 확인

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

제대로 나오는거 확인


service 배치

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



참고

profile
배운 것을 기록합니다.

0개의 댓글