在 K8S 上部署以 mysql 数据库作为后端存储的单机版 nacos

Nacos 被用于:

  • 服务发现
  • 微服务配置信息管理

部署 nacos 时,需要用到如下两个镜像,这两个镜像均来自于 nacos 官方发布到 docker hub 的镜像,

nacos/nacos-server:latest https://hub.docker.com/r/nacos/nacos-server
nacos/nacos-mysql:5.7  https://hub.docker.com/r/nacos/nacos-mysql

碰到个奇葩的问题

使用官方的nacos/nacos-server:2.0.1镜像,会报错,连接不上数据库:
org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

Caused by: java.sql.SQLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.

Caused by: com.mysql.cj.exceptions.CJCommunicationsException: Communications link failure

换成官方的nacos/nacos-server:latest镜像就可以连接上数据库,但是web页面访问后查看nacos版本竟然是2.0.1。

操作步骤

# 需要事先有存储卷
1.kubectl create -f Namespace.yaml
2.kubectl create -f nacos-mysql.yaml
3.kubectl create -f nacos-mysql-service.yaml
4.kubectl create -f ConfigMap.yaml
5.kubectl create -f StatefulSet.yaml
6.kubectl create -f nacos-service.yaml

yaml文件下载地址

https://files.cnblogs.com/files/sanduzxcvbnm/single_nacos.7z

posted @ 2021-06-15 17:26  哈喽哈喽111111  阅读(1117)  评论(0编辑  收藏  举报