spring boot app cannot connect mysql database between kubernetes pods/services in minikube

I got a web server in spring boot tries to connect to mysql database, both of which is running in minikube local machine. The application and database configuration should be alright, because it is working in local machine with localhost url.

The pod is able to reach the database pod with curl in shell, but the jdbc is not able to find database.

the jdbc error message:
Caused by: com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure
# curl -v $DB_HOST
*   Trying 10.109.201.118:3306...
* Connected to mysql-svc (10.109.201.118) port 3306 (#0)
> GET / HTTP/1.1
> Host: mysql-svc:3306
> User-Agent: curl/7.81.0
> Accept: */*
> 
* Received HTTP/0.9 when not allowed
* Closing connection 0
curl: (1) Received HTTP/0.9 when not allowed
application.yaml
---
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://${DB_HOST}/${DB_NAME}?useSSL=false
    username: ${DB_USERNAME}
    password: ${DB_PASSWORD}
    hikari:
      initialization-fail-timeout: 0
  jpa:
    database-platform: org.hibernate.dialect.MySQLDialect
    generate-ddl: true
    show-sql: true
    hibernate:
      ddl-auto: update
db-deploy.yaml
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: mysql-pv-volume # name of PV essential for identifying the storage data
  labels:
    app: mysql
    type: local
spec:
  storageClassName: manual
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce   #This specifies the mode of the claim that we are trying to create.
  hostPath:
    path: "/var/lib/mysql"

---
# Define a 'Persistent Volume Claim'(PVC) for Mysql Storage, dynamically provisioned by cluster
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: mysql-pv-claim # name of PVC essential for identifying the storage data
  labels:
    app: mysql
    tier: database
spec:
  storageClassName: manual
  accessModes:
    - ReadWriteOnce   #This specifies the mode of the claim that we are trying to create.
  resources:
    requests:
      storage: 5Gi    #This will tell kubernetes about the amount of space we are trying to claim.
---
# Configure 'Deployment' of mysql server
apiVersion: apps/v1
kind: Deployment
metadata:
  name: mysql-deploy
  labels:
    app: mysql
    tier: database
spec:
  selector: # mysql Pod Should contain same labels
    matchLabels:
      app: mysql
      tier: database
  strategy:
    type: Recreate
  template:
    metadata:
      labels: # Must match 'Service' and 'Deployment' selectors
        app: mysql
        tier: database
    spec:
      containers:
        - image: mysql:8.4 # image from docker-hub
#          args:
#            - "--ignore-db-dir=lost+found" # Workaround for https://github.com/docker-library/mysql/issues/186
          name: mysql
          env:
            - name: MYSQL_ROOT_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: password

          ports:
            - containerPort: 3306
              name: mysql
          volumeMounts:        # Mounting volume obtained from Persistent Volume Claim
            - name: mysql-persistent-storage
              mountPath: /var/lib/mysql #This is the path in the container on which the mounting will take place.
      volumes:
        - name: mysql-persistent-storage # Obtaining 'volume' from PVC
          persistentVolumeClaim:
            claimName: mysql-pv-claim
---
# Define a 'Service' To Expose mysql to Other Services
apiVersion: v1
kind: Service
metadata:
  name: mysql-svc  # DNS name
  labels: # mysql Pod Should contain same labels
    app: mysql
    tier: database
spec:
  ports:
    - protocol: TCP
      port: 3306
      targetPort: 3306
  selector:
    app: mysql
    tier: database
  clusterIP: None  # We Use DNS, Thus ClusterIP is not relevant
#  type: NodePort
#  type: ExternalName
#  externalName: my.database.host
app-deploy.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: onlineshopping-deploy
  labels:
    app: onlineshopping
spec:
  selector:
    matchLabels:
      app: onlineshopping
  replicas: 3
  template:
    metadata:
      labels:
        app: onlineshopping
    spec:
      containers:
        - name: onlineshopping-container
          image: tank73/onlineshopping:h1.0  # amazon/onlineshopping:1.0
          ports:
            - containerPort: 9000
          env:   # Setting Enviornmental Variables
            - name: DB_HOST   # Setting Database host address from configMap
              value : mysql-svc:3306
#              value : my.database.host:3306
            - name: DB_NAME  # Setting Database name from configMap
              value : onlineshopping
            - name: DB_USERNAME  # Setting Database username from Secret
              value : root
            - name: DB_PASSWORD # Setting Database password from Secret
              valueFrom:
                secretKeyRef:
                  name: mysql-secret
                  key: password

---
apiVersion: v1 # Kubernetes API version
kind: Service # Kubernetes resource kind we are creating
metadata: # Metadata of the resource kind we are creating
  name: onlineshopping-svc
spec:
  selector:
    app: onlineshopping
  ports:
    - protocol: TCP
      port: 9000 # The port that the service is running on in the cluster
      targetPort: 9000 # The port exposed by the service
  type: LoadBalancer # type of the service.

This is the link of my repository, you are welcome to take a look at my code and provide any suggestions.
https://github.com/Alex-Lin5/Amazon-Spring-Application

6

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật