k8s如何使用RDS
作者:互联网
1把RDS的信息做成configmap
apiVersion: v1 kind: ConfigMap metadata: name: nacos-cm data: mysql.host: "阿里云 RDS 内网地址" mysql.db.name: "数据库名" mysql.port: "数据库端口" mysql.user: "数据库用户名" mysql.password: "数据库密码"
2在deployment里定义env并引用这些configmap
可提前把这些代码整理好,目的是为了把MYSQL_SERVICE_HOST,MYSQL_SERVICE_DB_NAME,MYSQL_SERVICE_PORT,MYSQL_SERVICE_USER,MYSQL_SERVICE_PASSWORD
这些变量给到后台,让后台使用这些变量连接数据库
env: - name: MYSQL_SERVICE_HOST valueFrom: configMapKeyRef: name: nacos-cm key: mysql.host - name: MYSQL_SERVICE_DB_NAME valueFrom: configMapKeyRef: name: nacos-cm key: mysql.db.name - name: MYSQL_SERVICE_PORT valueFrom: configMapKeyRef: name: nacos-cm key: mysql.port - name: MYSQL_SERVICE_USER valueFrom: configMapKeyRef: name: nacos-cm key: mysql.user - name: MYSQL_SERVICE_PASSWORD valueFrom: configMapKeyRef: name: nacos-cm key: mysql.password
3后台数据库连接示例代码:
url: jdbc:mysql://${MYSQL_SERVER:127.0.0.1}:${MYSQL_PORT:3306}/${MYSQL_DB_NAME:blogDB}?useUnicode=true&characterEncoding=utf-8&useSSL=false
标签:cm,name,RDS,MYSQL,nacos,如何,SERVICE,mysql,k8s 来源: https://www.cnblogs.com/tyjs09/p/16457957.html