You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Kubernetes单实例MySQL Pod启动失败unknown option报错解决

Kubernetes 部署MySQL 8.0 报错问题排查

我遇到了一个暂时无法解决的报错,我正尝试部署一个非常简单的MySQL Deployment,配置如下:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: mysql
  name: mysql
spec:
  replicas: 1
  selector:
    matchLabels:
      app: mysql
  template:
    metadata:
      labels:
        app: mysql
    spec:
      containers:
      - image: mysql:8.0.25
        name: mysql
        ports:
        - containerPort: 3306
          name: mysql
        volumeMounts:
        - name: mysql
          mountPath: /var/lib/mysql
        env:
        - name: MYSQL_USER
          value: weazel
        - name: MYSQL_DATABASE
          value: weazel
        - name: MYSQL_PASSWORD
          value: weazel
        - name: MYSQL_ROOT_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql
              key: rootPassword
      volumes:
      - name: mysql
        persistentVolumeClaim:
          claimName: mysql

---

apiVersion: v1
kind: Service
metadata:
  name: mysql
spec:
  ports:
  - port: 3306
  selector:
    app: mysql
  clusterIP: None

Deployment成功创建后开始运行,Pod经过数分钟初始化后抛出如下错误:

2021-06-20 21:19:58+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
2021-06-20 21:19:59+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-06-20 21:19:59+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.25-1debian10 started.
2021-06-20 21:19:59+00:00 [Note] [Entrypoint]: Initializing database files
2021-06-20T21:19:59.461650Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.25) initializing of server in progress as process 43
2021-06-20T21:19:59.510070Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-06-20T21:21:15.206744Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-06-20T21:24:18.876746Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2021-06-20 21:28:29+00:00 [Note] [Entrypoint]: Database files initialized
2021-06-20 21:28:29+00:00 [Note] [Entrypoint]: Starting temporary server
2021-06-20T21:28:30.333051Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.25) starting as process 126
2021-06-20T21:28:30.538635Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-06-20T21:28:32.723573Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-06-20T21:28:33.273688Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock
2021-06-20T21:28:39.828471Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-06-20T21:28:39.828950Z 0 [System] [MY-013602] [Server] Channel mysql_main configured to support TLS. Encrypted connections are now supported for this channel.
2021-06-20T21:28:40.155589Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2021-06-20T21:28:40.215423Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.25'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.
2021-06-20 21:28:40+00:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2021-06-20 21:31:13+00:00 [Note] [Entrypoint]: Creating database weazel
mysql: [ERROR] unknown option '--"'.

报错后Pod会自动重启,但我无法再使用配置的凭据连接到数据库。我尝试在Docker容器中使用相同配置运行,一切运行符合预期。无论我怎么调整配置都会复现该错误,我猜测该问题可能和我使用的三主节点线下自建Kubernetes集群有关,恳请大家帮忙排查。

解决方案

Secret变量编码时末尾带有换行符,重新编码时去掉末尾的换行符后一切运行正常。

内容的提问来源于stack exchange,提问作者Iurie Muradu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.15 13:24:05