programing

Kubernetes의 Mariadb 통신 패킷을 읽는 동안 오류가 발생했습니다.

procenter 2023. 1. 13. 20:15
반응형

Kubernetes의 Mariadb 통신 패킷을 읽는 동안 오류가 발생했습니다.

k8s 클러스터에 mariadb 데이터베이스를 사용하여 애플리케이션을 도입하려고 합니다.사용하고 있는 전개는 다음과 같습니다.

apiVersion: v1
kind: Service
metadata:
  name: app-back
  labels:
    app: app-back
  namespace: dev
spec:
  type: ClusterIP
  ports:
    - port: 8080
      name: app-back
  selector:
    app: app-back
---
apiVersion: v1
kind: Service
metadata:
  name: app-db
  labels:
    app: app-db
  namespace: dev
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - port: 3306
      name: app-db
  selector:
    app: app-db
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: mysql
  labels:
    app: mysql
data:
  60-server.cnf: |
    [mysqld]
    bind-address = 0.0.0.0
    skip-name-resolve
    connect_timeout = 600
    net_read_timeout = 600
    net_write_timeout = 600
    max_allowed_packet = 256M
    default-time-zone = +00:00
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-db
  namespace: dev
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: app-db
  template:
    metadata:
      labels:
        app: app-db
    spec:
      containers:
        - name: app-db
          image: mariadb:10.5.8
          env:
            - name: MYSQL_DATABASE
              value: app
            - name: MYSQL_USER
              value: app
            - name: MYSQL_PASSWORD
              value: app
            - name: MYSQL_RANDOM_ROOT_PASSWORD
              value: "true"
          ports:
            - containerPort: 3306
              name: app-db
          resources:
            requests:
              memory: "200Mi"
              cpu: "100m"
            limits:
              memory: "400Mi"
              cpu: "200m"
          volumeMounts:
            - name: config-volume
              mountPath: /etc/mysql/conf.d
      volumes:
        - name: config-volume
          configMap:
            name: mysql
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: app-back
  namespace: dev
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: app-back
  template:
    metadata:
      labels:
        app: app-back
    spec:
      containers:
        - name: app-back
          image: private-repository/app/app-back:latest
          env:
            - name: spring.profiles.active
              value: dev
            - name: DB_HOST
              value: app-db
            - name: DB_PORT
              value: "3306"
            - name: DB_NAME
              value: app
            - name: DB_USER
              value: app
            - name: DB_PASSWORD
              value: app
          ports:
            - containerPort: 8080
              name: app-back
          resources:
            requests:
              memory: "200Mi"
              cpu: "100m"
            limits:
              memory: "200Mi"
              cpu: "400m"
      imagePullSecrets:
        - name: docker-private-credentials

이 작업을 실행하면 mariadb 컨테이너에 다음 경고가 기록됩니다.

2020-12-03  8:23:41 28 [Warning] Aborted connection 28 to db: 'app' user: 'app' host: 'xxx.xxx.xxx.xxx' (Got an error reading communication packets)
2020-12-03  8:23:41 25 [Warning] Aborted connection 25 to db: 'app' user: 'app' host: 'xxx.xxx.xxx.xxx' (Got an error reading communication packets)
2020-12-03  8:23:41 31 [Warning] Aborted connection 31 to db: 'app' user: 'app' host: 'xxx.xxx.xxx.xxx' (Got an error reading communication packets)
2020-12-03  8:23:41 29 [Warning] Aborted connection 29 to db: 'app' user: 'app' host: 'xxx.xxx.xxx.xxx' (Got an error reading communication packets)
...

내 앱이 데이터베이스에 연결하려고 하다가 멈춰버렸어.어플리케이션은 다음 도커파일을 사용한Sprinboot 어플리케이션 빌드입니다.

FROM maven:3-adoptopenjdk-8 AS builder
WORKDIR /usr/src/mymaven/
COPY . .
RUN mvn clean package -e -s settings.xml -DskipTests

FROM tomcat:9-jdk8-adoptopenjdk-hotspot
ENV spring.profiles.active=dev
ENV DB_HOST=localhost
ENV DB_PORT=3306
ENV DB_NAME=app
ENV DB_USER=app
ENV DB_PASSWORD=app

COPY --from=builder /usr/src/mymaven/target/app.war /usr/local/tomcat/webapps/

감 잡히는 게 없어요?

좋아, 해결책을 찾았어이것은 mariadb의 실수가 아니었다.이는 낮은 메모리가 있는 컨테이너 내에서 실행할 경우 연결이 끊어지는 Apache 때문입니다.메모리 제한을 1500Mi로 설정하면 문제가 해결.

언급URL : https://stackoverflow.com/questions/65122890/mariadb-on-kubernetes-got-an-error-reading-communication-packets

반응형