๐ŸฌGKE ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ๋ณผ๋ฅจ[PV, PVC] + MySQL ํ™˜๊ฒฝ ๊ตฌ์ถ• & ๐ŸšจํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ…

๊น€์„ฑ์ธยท2023๋…„ 10์›” 14์ผ
0

[DevOps] ๐ŸณDocker & Kubernetes

๋ชฉ๋ก ๋ณด๊ธฐ
31/62
post-thumbnail

SpringBoot application.yml

server:
  port: 8081

  servlet:
    encoding:
      charset: UTF-8
      enabled: true
      force: true

spring:
  datasource:
    url: ${SPRING_DATASOURCE_URL}
    username: ${SPRING_DATASOURCE_USERNAME}
    password: ${SPRING_DATASOURCE_PASSWORD}

PV

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
spec:
  capacity:
    storage: 5Gi  # Adjust the storage size as needed
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
    - ReadOnlyMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual
  hostPath:
          path: /$HOME/mysql

PVC

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi  # Requested storage size should match the PV's capacity
  storageClassName: manual

Deploy [MySql]

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql:latest
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: "1234"
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pvc
@cloudshell:~/prac (jpa-practice)$ kubectl apply -f mysql-deploy.yaml                                                                                                                                                                
Error from server (BadRequest): error when creating "mysql-deploy.yaml": 
Deployment in version "v1" cannot be handled as a Deployment: 
json: cannot unmarshal number into Go struct field EnvVar.spec.template.spec.containers.env.value of type string

-> ํ•ด๊ฒฐ: 1234 ์˜€๋˜ ๊ฐ’์„ "1234"๋กœ ๋ณ€๊ฒฝํ•จ


Service [MySql]

apiVersion: v1
kind: Service
metadata:
  name: mysql-service
spec:
  selector:
    app: mysql
  ports:
    - protocol: TCP
      port: 3306
      targetPort: 3306
  type: ClusterIP 

1. MySql ๋””ํ”Œ๋กœ์ด๋จผํŠธ ์ƒ์„ฑ ์‹คํŒจ

๋‘๋ฒˆ์งธ mysql-pv.deployment

Events:
  Type     Reason     Age               From               Message
  ----     ------     ----              ----               -------
  Normal   Scheduled  34s               default-scheduler  Successfully assigned default/mysql-deployment-7d66f4c884-lbwzx to gke-cluster-1-default-pool-95e5a548-j30p
  Normal   Pulled     21s               kubelet            Successfully pulled image "mysql:latest" in 12.516261682s (12.516316079s including waiting)
  Warning  Failed     21s               kubelet            Error: failed to generate container "11ba5fa7fbd63915575f52ae980c1c1f1f77c2b99fa94ab94171a0153058a9a5" spec: failed to generate spec: failed to mkdir "/$HOME/mysql": mkdir /$HOME: read-only file system
  Normal   Pulled     20s               kubelet            Successfully pulled image "mysql:latest" in 111.568359ms (111.581199ms including waiting)
  Warning  Failed     20s               kubelet            Error: failed to generate container "067d27ba435b1120a531ca22282d6f41cd2d15f3771a30c410b4f8aceb042100" spec: failed to generate spec: failed to mkdir "/$HOME/mysql": mkdir /$HOME: read-only file system
  Normal   Pulling    5s (x3 over 33s)  kubelet            Pulling image "mysql:latest"
  Normal   Pulled     4s                kubelet            Successfully pulled image "mysql:latest" in 95.158065ms (95.169789ms including waiting)
  Warning  Failed     4s                kubelet            Error: failed to generate container "843171203f7adfd56324a440295e6d80c4852cf64b089dfa74860bdb1b43fa11" spec: failed to generate spec: failed to mkdir "/$HOME/mysql": mkdir /$HOME: read-only file system

Warning Failed 4s kubelet Error: failed to generate container "843171203f7adfd56324a440295e6d80c4852cf64b089dfa74860bdb1b43fa11" spec: failed to generate spec: failed to mkdir "/$HOME/mysql": mkdir /$HOME: read-only file system : ํ™˜๊ฒฝ๋ณ€์ˆ˜ $HOME๊ฐ€ ์ž˜๋ชป๋œ ๊ฒƒ ๊ฐ™๋‹ค..

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
spec:
  capacity:
    storage: 5Gi  # Adjust the storage size as needed
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
    - ReadOnlyMany
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual
  hostPath:
          path: /mysql # ๋””๋ ‰ํ„ฐ๋ฆฌ ๋ณ€๊ฒฝ

๋””๋ ‰ํ„ฐ๋ฆฌ ์ž˜๋ชป๋œ๊ฑฐ ์•„๋‹˜

Events:
  Type     Reason     Age                From               Message
  ----     ------     ----               ----               -------
  Normal   Scheduled  67s                default-scheduler  Successfully assigned default/mysql-deployment-7d66f4c884-km58z to gke-cluster-1-default-pool-95e5a548-j30p
  Normal   Pulled     66s                kubelet            Successfully pulled image "mysql:latest" in 90.948188ms (90.959776ms including waiting)
  Warning  Failed     66s                kubelet            Error: failed to generate container "e5cc53da817a2e0fc2a4009dc1cf998067eb989d17a65cb773c1ee7a9d1b5573" spec: failed to generate spec: failed to mkdir "/mysql": mkdir /mysql: read-only file system
  Warning  Failed     65s                kubelet            Error: failed to generate container "8ce745792f1129fd1c6cd875b6b6aa07774cb77c494e57688283d11b8318312a" spec: failed to generate spec: failed to mkdir "/mysql": mkdir /mysql: read-only file system
  Normal   Pulled     65s                kubelet            Successfully pulled image "mysql:latest" in 87.664217ms (87.67945ms including waiting)
  Normal   Pulled     50s                kubelet            Successfully pulled image "mysql:latest" in 81.926661ms (81.940438ms including waiting)
  Warning  Failed     50s                kubelet            Error: failed to generate container "e8a31f500fa8206554f075347885cbb52aaab8b22189c86bda2ad6b2124c234c" spec: failed to generate spec: failed to mkdir "/mysql": mkdir /mysql: read-only file system
  Normal   Pulled     38s                kubelet            Successfully pulled image "mysql:latest" in 107.138057ms (107.152067ms including waiting)
  Warning  Failed     38s                kubelet            Error: failed to generate container "2909632d3dab8b18fefcc4ae69d917a659e479195aba954b8086dc3f44384373" spec: failed to generate spec: failed to mkdir "/mysql": mkdir /mysql: read-only file system
  Normal   Pulled     25s                kubelet            Successfully pulled image "mysql:latest" in 89.176185ms (89.191531ms including waiting)
  Warning  Failed     25s                kubelet            Error: failed to generate container "4c0f1a846042f7be0e259c4994370a34319d71a1a3876a3bdea153056f7be5f9" spec: failed to generate spec: failed to mkdir "/mysql": mkdir /mysql: read-only file system
  Normal   Pulling    12s (x6 over 66s)  kubelet            Pulling image "mysql:latest"
  Normal   Pulled     11s                kubelet            Successfully pulled image "mysql:latest" in 98.682854ms (98.695413ms including waiting)
  Warning  Failed     11s                kubelet            Error: failed to generate container "c86b3d9b466ae13240d073a2ecb21cf8eb0b259c92a202140543923ab1650366" spec: failed to generate spec: failed to mkdir "/mysql": mkdir /mysql: read-only file system

ํ•ด๊ฒฐ

์ปจํ…Œ์ด๋„ˆ ๋‚ด๋ถ€์— ํŒŒ์ผ ์‹œ์Šคํ…œ์˜ ๋””๋ ‰ํ„ฐ๋ฆฌ์— ์ ‘๊ทผ๊ถŒํ•œ์ด ์—†์—ˆ๊ธฐ ๋•Œ๋ฌธ
hostPath.path: /var/lib/mysql ๋กœ ๋ณ€๊ฒฝํ•˜๋‹ˆ ์„ฑ๊ณตํ•˜์˜€๋‹ค..

PV, PVC Terminating ํ•ด๊ฒฐ

์ค‘๊ฐ„์— PV๋ฅผ ์ˆ˜์ •ํ•˜๋ ค๊ณ  ํ•˜๋Š”๋ฐ ์ข…๋ฃŒ๊ฐ€ ์•ˆ๋˜๊ณ  ๊ณ„์† ๋ฉˆ์ถฐ์žˆ์–ด์„œ ํ™•์ธํ•ด๋ณด๋‹ˆ PV,PVC๊ฐ€ terminating ์ƒํƒœ์—์„œ ๋™์ž‘์„ ํ•˜์ง€ ์•Š๊ณ  ์žˆ์—ˆ๋‹ค.

kubectl patch pv <pv_name> -p '{"metadata": {"finalizers": null}}'
kubectl delete pv <pv_name> --grace-period=0 --force

kubectl patch pvc <pvc_name> -p '{"metadata": {"finalizers": null}}'
kubectl delete pvc <pvc_name> --grace-period=0 --force

์›์ธ๊ด€๋ จ -> https://velog.io/@hyunshoon/kubernetes-pv-pvc-%EC%82%AD%EC%A0%9C-%EC%95%88%EB%90%A0-%EB%95%8C-Finalizer
๊ณต์‹๋ฌธ์„œ: https://kubernetes.io/ko/docs/concepts/overview/working-with-objects/finalizers/


๐ŸƒWAS ์ด๋ฏธ์ง€ ํŒŒ์ผ๊ณผ ์—ฐ๊ฒฐ

deployment.yaml (was)

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jpapractice-deployment
spec:
  replicas: 3  # Set the desired number of replicas
  selector:
    matchLabels:
      app: jpapractice
  template:
    metadata:
      labels:
        app: jpapractice
    spec:
      containers:
        - name: jpapractice
          image: adultkim/was-pvc-test:latest  # Your Spring Boot application image
          env:
            - name: active
              value: "prod"
            - name: SPRING_DATASOURCE_URL
              value: "jdbc:mysql://mysql-service:3306/pv1"
            - name: SPRING_DATASOURCE_USERNAME
              value: "admin"
            - name: SPRING_DATASOURCE_PASSWORD
              value: "1234"
          ports:
            - containerPort: 8081  # Port your Spring Boot application is running on

๐ŸƒWAS ๋””ํ”Œ๋กœ์ด๋จผํŠธ ์‹คํ–‰ ์—๋Ÿฌ

DataSource ์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋‹ค.. ์•„๋งˆ MySQL์— ์—ฐ๊ฒฐ์ด ์ž˜ ์•ˆ๋œ ํƒ“์ธ๋“ฏํ•˜๋‹ค

  • ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํ™˜๊ฒฝ์— ๋„ˆ๋ฌด ์น˜์ค‘ํ•˜๋‹ค๋ณด๋‹ˆ, jarํŒŒ์ผ ์˜์กด์„ฑ์— ๋Œ€ํ•ด์„œ ๊นŒ๋งˆ๋“ํžˆ ์žŠ๊ณ  ์žˆ์—ˆ๋‹ค..

    ๋“œ๋ผ์ด๋ฒ„ ํด๋ž˜์Šค๋ฅผ ์ง€์ •ํ•ด์ฃผ์ง€ ์•Š์•˜์„ ๋ฟ๋”๋Ÿฌ build.gradle์— mysql์˜์กด์„ฑ์„ ์ถ”๊ฐ€ํ•˜์ง€๋„ ์•Š๊ณ  ์ด๋ฏธ์ง€ํŒŒ์ผ์„ ๋นŒ๋“œํ•ด์„œ ๋ฐฐํฌํ•œ๊ฒƒ...

์Šคํ”„๋ง๋ถ€ํŠธ ์ด๋ฏธ์ง€ ํŒŒ์ผ ๋นŒ๋“œ ์—๋Ÿฌ

C:\Users\d\Desktop\practice>docker build -t adulkim/was-pvc-test .                                      
[+] Building 57.0s (15/17)                                                                                                                                                                                               docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                                               0.0s
 => => transferring dockerfile: 920B                                                                                                                                                                                               0.0s
 => [internal] load .dockerignore                                                                                                                                                                                                  0.0s 
 => => transferring context: 2B                                                                                                                                                                                                    0.0s 
 => [internal] load metadata for docker.io/library/openjdk:11-jre-slim                                                                                                                                                             1.6s 
 => [internal] load metadata for docker.io/library/gradle:6.9.2-jdk11                                                                                                                                                              1.6s 
 => [auth] library/openjdk:pull token for registry-1.docker.io                                                                                                                                                                     0.0s
 => [auth] library/gradle:pull token for registry-1.docker.io                                                                                                                                                                      0.0s
 => [build 1/7] FROM docker.io/library/gradle:6.9.2-jdk11@sha256:2f1f4c08527ae56e8ebcc3a2a8e9d52ddde443ea8bf6ee8d6e83cab53e2308a6                                                                                                  0.0s
 => [internal] load build context                                                                                                                                                                                                  0.0s
 => => transferring context: 1.91kB                                                                                                                                                                                                0.0s
 => [stage-1 1/3] FROM docker.io/library/openjdk:11-jre-slim@sha256:93af7df2308c5141a751c4830e6b6c5717db102b3b31f012ea29d842dc4f2b02                                                                                               0.0s
 => CACHED [build 2/7] WORKDIR /app                                                                                                                                                                                                0.0s
 => CACHED [build 3/7] COPY gradle /app/gradle                                                                                                                                                                                     0.0s 
 => CACHED [build 4/7] COPY build.gradle settings.gradle gradlew /app/                                                                                                                                                             0.0s 
 => CACHED [build 5/7] COPY src /app/src                                                                                                                                                                                           0.0s 
 => [build 6/7] RUN chmod +x gradlew                                                                                                                                                                                               0.4s 
 => ERROR [build 7/7] RUN ./gradlew clean build                                                                                                                                                                                   54.9s 
------
 > [build 7/7] RUN ./gradlew clean build:
0.547 Downloading https://services.gradle.org/distributions/gradle-8.2.1-bin.zip
1.072 ............10%............20%............30%.............40%............50%............60%............70%.............80%............90%............100%
13.07
13.07 Welcome to Gradle 8.2.1!
13.07
13.07 Here are the highlights of this release:
13.07  - Kotlin DSL: new reference documentation, assignment syntax by default
13.07  - Kotlin DSL is now the default with Gradle init
13.07  - Improved suggestions to resolve errors in console output
13.07  - Reduced sync memory consumption
13.07
13.07 For more details see https://docs.gradle.org/8.2.1/release-notes.html
13.07
13.16 Starting a Gradle Daemon (subsequent builds will be faster)
31.26 > Task :clean UP-TO-DATE
41.46
41.46 > Task :compileJava
41.46 Note: /app/src/main/java/com/jpa/practice/addition/security/WebSecurityConfig.java uses or overrides a deprecated API.
41.46 Note: Recompile with -Xlint:deprecation for details.
44.86
44.86 > Task :processResources
44.86 > Task :classes
46.35 > Task :bootJarMainClassName
46.65 > Task :bootJar
46.65 > Task :dockerfileZip NO-SOURCE
46.65 > Task :jar SKIPPED
46.66 > Task :assemble
49.65 > Task :compileTestJava
49.65 > Task :processTestResources NO-SOURCE
49.66 > Task :testClasses
54.35
54.35 > Task :test
54.35
54.35 PracticeApplicationTests > contextLoads() FAILED
54.35     java.lang.IllegalStateException at DefaultCacheAwareContextLoaderDelegate.java:98
54.36         Caused by: org.springframework.beans.factory.BeanCreationException at AbstractAutowireCapableBeanFactory.java:1804
54.36             Caused by: org.hibernate.service.spi.ServiceException at AbstractServiceRegistryImpl.java:284
54.36                 Caused by: org.hibernate.HibernateException at DialectFactoryImpl.java:100
54.45
54.45 1 test completed, 1 failed
54.45
54.45 > Task :test FAILED
54.46
54.46 FAILURE: Build failed with an exception.
54.46
54.46 * What went wrong:
54.46 Execution failed for task ':test'.
54.46 > There were failing tests. See the report at: file:///app/build/reports/tests/test/index.html
54.46
54.46 * Try:
54.46 > Run with --scan to get full insights.
54.46
54.46 Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
54.46
54.46 You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
54.46
54.46 For more on this, please refer to https://docs.gradle.org/8.2.1/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
54.46
54.46 BUILD FAILED in 53s
54.46 7 actionable tasks: 6 executed, 1 up-to-date
------
Dockerfile:24
--------------------
  22 |     RUN chmod +x gradlew
  23 |
  24 | >>> RUN ./gradlew clean build
  25 |
  26 |
--------------------
ERROR: failed to solve: process "/bin/sh -c ./gradlew clean build" did not complete successfully: exit code: 1

ํ…Œ์ŠคํŠธ์—์„œ ์—๋Ÿฌ๊ฐ€ ๋‚˜์„œ ํ…Œ์ŠคํŠธ๋ฅผ ์ œ์™ธํ•˜๊ณ  gradlw build๋ฅผ ํ•˜๋‹ˆ ์„ฑ๊ณตํ•˜์˜€๋‹ค
./gradlew clean build -x check --parallel

FROM gradle:6.9.2-jdk11 AS BUILD

ENV APP_HOME=/app
WORKDIR $APP_HOME

COPY gradle $APP_HOME/gradle
COPY build.gradle settings.gradle gradlew $APP_HOME/
COPY src $APP_HOME/src

USER root
RUN chmod +x gradlew

RUN ./gradlew clean build -x check --parallel


#Final Stage
FROM openjdk:11-jre-slim
ENV APP_HOME=/app
ENV JAR_FILE=/app/build/libs/*.jar

WORKDIR $APP_HOME

COPY --from=BUILD ${JAR_FILE} /app.jar

ENTRYPOINT ["java", "-jar", "-Dspring.profiles.active=${active}", "-Duser.timezone=Asia/Seoul", "/app.jar"]

์—ฌ์ „ํžˆ was ์‹คํ–‰ ์‹คํŒจ DataSource Exception

DB ์Šคํ‚ค๋งˆ ์šฐ์„  ์ƒ์„ฑ

kubectl exec -it pod/mysql-deployment-7d66f4c884-vcpw6 bash
์‹คํ–‰๋˜์–ด ์žˆ๋Š” MySql ํŒŒ๋“œ์— ์ ‘์†ํ•ด์„œ pv1์ด๋ผ๋Š” DB๋„ ์ผ๋‹จ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ๋‹ค.

kubectl logs jpapractice-deployment-fd9464675-8r752

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::               (v2.7.15)

2023-10-15 00:54:56.390  INFO 1 --- [           main] com.jpa.practice.PracticeApplication     : Starting PracticeApplication using Java 11.0.16 on jpapractice-deployment-fd9464675-8r752 with PID 1 (/app.jar started by root in /app)
2023-10-15 00:54:56.394  INFO 1 --- [           main] com.jpa.practice.PracticeApplication     : The following 1 profile is active: "prod"
2023-10-15 00:54:57.794  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-10-15 00:54:57.818  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 10 ms. Found 0 JPA repository interfaces.
2023-10-15 00:54:59.116  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8081 (http)
2023-10-15 00:54:59.136  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-10-15 00:54:59.137  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.79]
2023-10-15 00:54:59.297  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-10-15 00:54:59.297  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2801 ms
2023-10-15 00:54:59.862 ERROR 1 --- [           main] com.zaxxer.hikari.HikariConfig           : Failed to load driver class com.mysql.cj.jdbc.Driver from HikariConfig class classloader org.springframework.boot.loader.LaunchedURLClassLoader@69663380
2023-10-15 00:54:59.867  WARN 1 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.RuntimeException: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
2023-10-15 00:54:59.872  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2023-10-15 00:54:59.913  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-10-15 00:54:59.957 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataSourceScriptDatabaseInitializer' defined in class path resource [org/springframework/boot/autoconfigure/sql/init/DataSourceInitializationConfiguration.class]: Unsatisfied dependency expressed through method 'dataSourceScriptDatabaseInitializer' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.RuntimeException: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:800) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:541) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1157) ~[spring-context-5.3.29.jar!/:5.3.29]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:911) ~[spring-context-5.3.29.jar!/:5.3.29]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.29.jar!/:5.3.29]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.15.jar!/:2.7.15]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-2.7.15.jar!/:2.7.15]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.15.jar!/:2.7.15]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.7.15.jar!/:2.7.15]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.7.15.jar!/:2.7.15]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.7.15.jar!/:2.7.15]
        at com.jpa.practice.PracticeApplication.main(PracticeApplication.java:10) ~[classes!/:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[app.jar:na]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) ~[app.jar:na]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[app.jar:na]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[app.jar:na]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.RuntimeException: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:276) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1391) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1311) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:887) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:791) ~[spring-beans-5.3.29.jar!/:5.3.29]
        ... 29 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.RuntimeException: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.29.jar!/:5.3.29]
        at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.29.jar!/:5.3.29]
        ... 43 common frames omitted
Caused by: java.lang.RuntimeException: Failed to load driver class com.mysql.cj.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
        at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:491) ~[HikariCP-4.0.3.jar!/:na]
        at org.springframework.boot.jdbc.DataSourceBuilder$MappedDataSourceProperty.set(DataSourceBuilder.java:463) ~[spring-boot-2.7.15.jar!/:2.7.15]
        at org.springframework.boot.jdbc.DataSourceBuilder$MappedDataSourceProperties.set(DataSourceBuilder.java:357) ~[spring-boot-2.7.15.jar!/:2.7.15]
        at org.springframework.boot.jdbc.DataSourceBuilder.build(DataSourceBuilder.java:183) ~[spring-boot-2.7.15.jar!/:2.7.15]
        at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration.createDataSource(DataSourceConfiguration.java:48) ~[spring-boot-autoconfigure-2.7.15.jar!/:2.7.15]
        at org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration$Hikari.dataSource(DataSourceConfiguration.java:90) ~[spring-boot-autoconfigure-2.7.15.jar!/:2.7.15]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Unknown Source) ~[na:na]
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.29.jar!/:5.3.29]
        ... 44 common frames omitted

driver-class-name: com.mysql.cj.jdbc.Driver ์„ ํ•ด๊ฒฐํ• ์ˆ˜ ์—†๋‹ค๊ณ  ์—๋Ÿฌ ๋กœ๊ทธ๊ฐ€ ์ฐํžˆ๋Š”๋ฐ ์˜์กด์„ฑ๋„ ์ด๋ฏธ ์ž˜ ์ถ”๊ฐ€ํ–ˆ๊ณ  ๋กœ์ปฌ์—์„œ๋Š” ์ž˜๋งŒ ์‹คํ–‰๋˜๋Š”๋ฐ ์™œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ ํ™˜๊ฒฝ์—์„œ๋Š” ์—๋Ÿฌ๊ฐ€ ์ž๊พธ๋‚˜๋Š”์ง€ ๋„๋ฌด์ง€ ์ดํ•ด๊ฐ€ ์•ˆ ๊ฐ”๋‹ค...

  • ์˜์กด์„ฑ ์ถ”๊ฐ€ ์‚ญ์ œ๋ฅผ ๊ณ„์† ๋ฐ˜๋ณตํ•˜๊ณ  ํ™˜๊ฒฝ๋ณ€์ˆ˜์— ๋ฌธ์ œ๊ฐ€ ์—†๋Š”์ง€ ๊ณ„์† ํ™•์ธํ•˜๋ฉด์„œ ๋„์ปค ๋นŒ๋“œ๋ฅผ ํ•˜๋˜ ์™€์ค‘์— ๊ณ„์†ํ•ด์„œ layer๊ฐ€ ์ถ”๊ฐ€ ์•ˆ๋˜๋‹ค๊ฐ€ ํ•œ์ˆœ๊ฐ„์— Pushed ๋ ˆ์ด์–ด๊ฐ€ ํ•˜๋‚˜ ๋” ๋ฐœ์ƒํ–ˆ๋‹ค.
  • ๊ทธ๋Ÿฌ๊ณ ๋‚˜์„œ ๋‹ค์‹œ deployment๋ฅผ ์‹คํ–‰ํ•ด๋ณด๋‹ˆ ๋ฌธ์ œ๊ฐ€ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค... ๋ญ๊ฐ€ ๋ฌธ์  ์ง€ ๋„๋ฌด์ง€ ์•Œ์ˆ˜๊ฐ€ ์—†๋„ค, ์•„๋งˆ๋„ mysql ์˜์กด์„ฑ์ด ๊ฐ™์ด ๋นŒ๋“œ๊ฐ€ ๋˜์ง€ ์•Š์•„์„œ driverclass ์‹๋ณ„์„ ํ•  ์ˆ˜ ์žˆ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ๋ฏธ์ง€ ํŒŒ์ผ์— ์ถ”๊ฐ€๋˜์ง€ ์•Š์•˜๋˜ ๊ฒƒ๊ฐ™๋‹ค..

๋ฌธ์ œ ํ•ด๊ฒฐ

ํ•ด๊ฒฐ ๊ณผ์ •

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2023-10-15 01:09:45.878 ERROR 22252 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, ${SPRING_DATASOURCE_URL}
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:638) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1157) ~[spring-context-5.3.29.jar:5.3.29]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:911) ~[spring-context-5.3.29.jar:5.3.29]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.29.jar:5.3.29]
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.15.jar:2.7.15]
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731) ~[spring-boot-2.7.15.jar:2.7.15]
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.15.jar:2.7.15]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307) ~[spring-boot-2.7.15.jar:2.7.15]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303) ~[spring-boot-2.7.15.jar:2.7.15]
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292) ~[spring-boot-2.7.15.jar:2.7.15]
	at com.jpa.practice.PracticeApplication.main(PracticeApplication.java:10) ~[classes/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, ${SPRING_DATASOURCE_URL}
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.3.29.jar:5.3.29]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-5.3.29.jar:5.3.29]
	... 19 common frames omitted
Caused by: java.lang.RuntimeException: Driver com.mysql.cj.jdbc.Driver claims to not accept jdbcUrl, ${SPRING_DATASOURCE_URL}
	at com.zaxxer.hikari.util.DriverDataSource.<init>(DriverDataSource.java:110) ~[HikariCP-4.0.3.jar:na]
	at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:331) ~[HikariCP-4.0.3.jar:na]
	at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:114) ~[HikariCP-4.0.3.jar:na]
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:108) ~[HikariCP-4.0.3.jar:na]
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112) ~[HikariCP-4.0.3.jar:na]
	at org.springframework.jdbc.datasource.DataSourceUtils.fetchConnection(DataSourceUtils.java:160) ~[spring-jdbc-5.3.29.jar:5.3.29]
	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:118) ~[spring-jdbc-5.3.29.jar:5.3.29]
	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:81) ~[spring-jdbc-5.3.29.jar:5.3.29]
	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:332) ~[spring-jdbc-5.3.29.jar:5.3.29]
	at org.springframework.boot.jdbc.EmbeddedDatabaseConnection.isEmbedded(EmbeddedDatabaseConnection.java:164) ~[spring-boot-2.7.15.jar:2.7.15]
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateDefaultDdlAutoProvider.getDefaultDdlAuto(HibernateDefaultDdlAutoProvider.java:42) ~[spring-boot-autoconfigure-2.7.15.jar:2.7.15]
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.lambda$getVendorProperties$1(HibernateJpaConfiguration.java:130) ~[spring-boot-autoconfigure-2.7.15.jar:2.7.15]
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateSettings.getDdlAuto(HibernateSettings.java:41) ~[spring-boot-autoconfigure-2.7.15.jar:2.7.15]
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineDdlAuto(HibernateProperties.java:143) ~[spring-boot-autoconfigure-2.7.15.jar:2.7.15]
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.getAdditionalProperties(HibernateProperties.java:103) ~[spring-boot-autoconfigure-2.7.15.jar:2.7.15]
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateProperties.determineHibernateProperties(HibernateProperties.java:95) ~[spring-boot-autoconfigure-2.7.15.jar:2.7.15]
	at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaConfiguration.getVendorProperties(HibernateJpaConfiguration.java:131) ~[spring-boot-autoconfigure-2.7.15.jar:2.7.15]
	at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.entityManagerFactory(JpaBaseConfiguration.java:132) ~[spring-boot-autoconfigure-2.7.15.jar:2.7.15]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.3.29.jar:5.3.29]
	... 20 common frames omitted

์ข…๋ฃŒ ์ฝ”๋“œ 1(์œผ)๋กœ ์™„๋ฃŒ๋œ ํ”„๋กœ์„ธ์Šค

url ์ด๋‚˜ mysql ์œ ์ €/ ๋น„๋ฐ€๋ฒˆํ˜ธ๊ฐ€ ์ž˜๋ชป๋˜์—ˆ์„ ๋•Œ๋Š” BeanCreationException ์œ„์™€ ๊ฐ™์ด ์˜ˆ์™ธ๊ฐ€ ๋‚˜์ง€๋งŒ,
๊ณ„์†ํ•ด์„œ org.springframework.beans.factory.UnsatisfiedDependencyException ์˜ค๋ฅ˜ ์ฆ‰, driver-class-name์— ๋Œ€ํ•œ ์˜์กด์„ฑ ์‹๋ณ„์ด ์•ˆ๋˜๊ณ  ์žˆ์—ˆ๋Š”๋ฐ ๋‚˜๋Š” DB์— ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๊ฐ€ ๋ฌธ์ œ์ธ์ค„ ์•Œ๊ณ  ํ—›๋œ ์‹œ๊ฐ„์„ ์“ฐ๊ณ  ์žˆ์—ˆ๋‹ค..

  • ๊ฒฐ๊ตญ์—๋Š” ์˜์กด์„ฑ์ด ์ฃผ์ž…๋œ ์ด๋ฏธ์ง€ํŒŒ์ผ์„ ์„ฑ๊ณต์ ์œผ๋กœ ๋นŒ๋“œํ•˜๊ณ  ํ•ด๋‹น springBoot ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ํ•œ ํŒŒ๋“œ์™€ MySQL์„ ์‹คํ–‰ํ•œ ์ปจํ…Œ์ด๋„ˆ์˜ ์„œ๋น„์Šค๋ฅผ ์—ฐ๊ฒฐํ•˜์—ฌ ์ •์ƒ์ ์œผ๋กœ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ์—ˆ๋‹ค..

๊ฒฐ๋ก 

MySQL ๋“œ๋ผ์ด๋ฒ„ ์†์„ฑ์„ ์‹๋ณ„ํ•˜๋Š” ์˜์กด์„ฑ์ด ์ฃผ์ž…๋˜์ง€ ์•Š์€์ฑ„๋กœ ์ด๋ฏธ์ง€๊ฐ€ ๋นŒ๋“œ๋œ ์ƒํƒœ์—์„œ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ํŒŒ๋“œ๋ฅผ ์‹คํ–‰ํ•˜๋ ค๊ณ  ํ–ˆ๊ธฐ ๋•Œ๋ฌธ


๐Ÿšค์›น ์„œ๋ฒ„(SpringBoot)+๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค(MySQL) ์ตœ์ข… ๋งค๋‹ˆํŒจ์ŠคํŠธ ํŒŒ์ผ

๐ŸƒSpringBoot ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ : ์ด์ „ ํฌ์ŠคํŒ…+

1. ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฏธ์ง€ ๋ฐฐํฌ [deployment.yml]

์Šคํ”„๋ง๋ถ€ํŠธ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋””ํ”Œ๋กœ์ด๋จผํŠธ๋ฅผ ํ†ตํ•ด ํŒŒ๋“œ์•ˆ์— ์ปจํ…Œ์ด๋„ˆ๋กœ ์‹คํ–‰ํ•˜๊ธฐ ์œ„ํ•œ ํŒŒ์ผ

apiVersion: apps/v1
kind: Deployment
metadata:
  name: jpapractice-deployment
spec:
  replicas: 3  
  selector:
    matchLabels:
      app: jpapractice
  template:
    metadata:
      labels:
        app: jpapractice
    spec:
      containers:
        - name: jpapractice
          image: adultkim/was-pvc-test:latest  
          imagePullPolicy: Always
          env:
            - name: active
              value: "prod"
            - name: SPRING_DATASOURCE_URL
              value: "jdbc:mysql://mysql-service:3306/pv1"
            - name: SPRING_DATASOURCE_USERNAME
              value: "root"
            - name: SPRING_DATASOURCE_PASSWORD
              value: "1234"
          ports:
            - containerPort: 8081 

2. ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ํด๋Ÿฌ์Šคํ„ฐ ์„œ๋น„์Šค ์—ฐ๊ฒฐ [service.yaml]

Ingress๋ฅผ ํ†ตํ•ด์„œ ์™ธ๋ถ€์—์„œ ํ•ด๋‹น ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์œผ๋กœ ์š”์ฒญํ•  ์ˆ˜ ์žˆ๋„๋ก ์ค€๋น„

apiVersion: v1
kind: Service
metadata:
  name: jpapractice-service
spec:
  selector:
    app: jpapractice
  ports:
    - protocol: TCP
      port: 80
      targetPort: 8081  

3. ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์„œ๋น„์Šค-์ธ๊ทธ๋ ˆ์Šค ์„ค์ • [ingress.yaml]

์™ธ๋ถ€์—์„œ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ GKE ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ๋ฅผ ํ†ตํ•ด์„œ ์„œ๋น„์Šค์— ํฌํŠธ ํฌ์›Œ๋”ฉ ํ•˜๊ธฐ ์œ„ํ•œ ์„ค์ •

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: jpapractice-ingress
spec:
  rules:
    - host: insung-jpadocker.store  # ์‹ค์ œ ๋„๋ฉ”์ธ ์„ค์ •
      http:
        paths:
          - pathType: Prefix
            path: "/"
            backend:
              service:
                name: jpapractice-service
                port: 80

๐ŸฌMySQL DB ์„œ๋น„์Šค

4. mysql ํผ์‹œ์Šคํ„ดํŠธ ๋ณผ๋ฅจ [mysql-pv.yaml]

apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv
spec:
  capacity:
    storage: 5Gi 
  volumeMode: Filesystem
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  storageClassName: manual
  hostPath:
    path: /var/lib/mysql

5. mysql ํผ์‹œ์Šคํ„ดํŠธ ๋ณผ๋ฅจ ํด๋ ˆ์ž„ [mysql-pvc.yaml]

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pvc
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi  
  storageClassName: manual

6. mysql ๋””ํ”Œ๋กœ์ด๋จผํŠธ [mysql-deploy.yaml]

MySQL ์ด๋ฏธ์ง€ํŒŒ์ผ์„ ํ†ตํ•ด์„œ DB ์ปจํ…Œ์ด๋„ˆ ๊ตฌ์ถ•

apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
        - name: mysql
          image: mysql:latest
          env:
            - name: MYSQL_ROOT_PASSWORD
              value: "1234"
          ports:
            - containerPort: 3306
          volumeMounts:
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql
      volumes:
        - name: mysql-persistent-storage
          persistentVolumeClaim:
            claimName: mysql-pvc

7. mysql ์„œ๋น„์Šค [mysql-service.yaml]

apiVersion: v1
kind: Service
metadata:
  name: mysql-service
spec:
  selector:
    app: mysql
  ports:
    - protocol: TCP
      port: 3306
      targetPort: 3306
  type: ClusterIP

ํ”ผ๋“œ๋ฐฑ

ํ™˜๊ฒฝ๋ณ€์ˆ˜ secret ์„ค์ •ํ• ๊ฒƒ
image:latest ๋ฒ„์ „๊ด€๋ฆฌ์ฃผ์˜
imagePullPolicy: Always ๊ฐœ๋ฐœํ™˜๊ฒฝ์—์„œ๋งŒ (์šด์˜ํ™˜๊ฒฝ์—์„  ๋†‰)

pv์˜ ๋น„์ฆˆ๋‹ˆ์Šค ์ธก๋ฉด์— ๋”ฐ๋ผ์„œ ์„ค์ •์„ ๋‹ค๋ฅด๊ฒŒ
retain : pvc ์‚ญ์ œ ์‹œ, pv ๋‚จ์•„์žˆ์Œ
-> mysql๊ฐ™์€ metadata

delete : pvc ์‚ญ์ œ์‹œ, pv๋„ ์‚ญ์ œ๋จ
-> log๊ฐ™์€ ์ •๋ณด๋“ค

profile
๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฟˆ์ธ 25์‚ด ๋Œ€ํ•™์ƒ์ž…๋‹ˆ๋‹ค.

0๊ฐœ์˜ ๋Œ“๊ธ€