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}
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
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
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"๋ก ๋ณ๊ฒฝํจ
apiVersion: v1
kind: Service
metadata:
name: mysql-service
spec:
selector:
app: mysql
ports:
- protocol: TCP
port: 3306
targetPort: 3306
type: ClusterIP
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๋ฅผ ์์ ํ๋ ค๊ณ ํ๋๋ฐ ์ข ๋ฃ๊ฐ ์๋๊ณ ๊ณ์ ๋ฉ์ถฐ์์ด์ ํ์ธํด๋ณด๋ 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/
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
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"]
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์ ์ฐ๊ฒฐํ๊ธฐ ์ํ ํ๊ฒฝ ๋ณ์๊ฐ ๋ฌธ์ ์ธ์ค ์๊ณ ํ๋ ์๊ฐ์ ์ฐ๊ณ ์์๋ค..
MySQL ๋๋ผ์ด๋ฒ ์์ฑ์ ์๋ณํ๋ ์์กด์ฑ์ด ์ฃผ์ ๋์ง ์์์ฑ๋ก ์ด๋ฏธ์ง๊ฐ ๋น๋๋ ์ํ์์ ์ฟ ๋ฒ๋คํฐ์ค ํด๋ฌ์คํฐ์์ ํ๋๋ฅผ ์คํํ๋ ค๊ณ ํ๊ธฐ ๋๋ฌธ
์คํ๋ง๋ถํธ ์น ์ ํ๋ฆฌ์ผ์ด์ ์ด๋ฏธ์ง ํ์ผ์ ๋ํ๋ก์ด๋จผํธ๋ฅผ ํตํด ํ๋์์ ์ปจํ ์ด๋๋ก ์คํํ๊ธฐ ์ํ ํ์ผ
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
Ingress๋ฅผ ํตํด์ ์ธ๋ถ์์ ํด๋น ์น ์ ํ๋ฆฌ์ผ์ด์ ์ผ๋ก ์์ฒญํ ์ ์๋๋ก ์ค๋น
apiVersion: v1 kind: Service metadata: name: jpapractice-service spec: selector: app: jpapractice ports: - protocol: TCP port: 80 targetPort: 8081
์ธ๋ถ์์ ๋ค์ด์ค๋ ์์ฒญ์ 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
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
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: mysql-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 1Gi storageClassName: manual
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
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๊ฐ์ ์ ๋ณด๋ค