nacos单机部署
【摘要】 nacos单机测试环境部署,将数据写入mysql数据库
1.测试环境部署
- 创建数据库文件:https://github.com/alibaba/nacos/blob/master/distribution/conf/mysql-schema.sql
- 不使用
nacos/nacos-mysql:5.7
镜像的时候就需要使用上面的数据库初始化文件,因为这个镜像为我们初始化好了数据库
2.storage csi准备
- storage class name:nfs-csi
3.mysql
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
namespace: nacos
spec:
replicas: 1
selector:
name: mysql
template:
metadata:
labels:
name: mysql
spec:
containers:
- name: mysql
image: nacos/nacos-mysql:5.7
ports:
- containerPort: 3306
volumeMounts:
- name: nacos-mysql
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "nacos"
- name: MYSQL_DATABASE
value: "nacos_db"
- name: MYSQL_USER
value: "nacos"
- name: MYSQL_PASSWORD
value: "nacos"
- name: TZ
value: Asia/Shanghai
volumes:
- name: nacos-mysql
persistentVolumeClaim:
claimName: nacos-mysql-pvc
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nacos-mysql-pvc
namespace: nacos
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 10Gi
storageClassName: nfs-csi
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: nacos
spec:
ports:
- port: 3306
targetPort: 3306
selector:
name: mysql
4.configmap
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm
namespace: nacos
data:
mysql.db.name: "nacos_db"
mysql.port: "3306"
mysql.user: "nacos"
mysql.password: "nacos"
mysql.host: "mysql.nacos.svc.cluster.local"
5.nacos service
---
apiVersion: v1
kind: Service
metadata:
name: nacos
namespace: nacos
spec:
type: NodePort
ports:
- port: 8848
name: server
targetPort: 8848
nodePort: 30018
- port: 7848
name: rpc
targetPort: 7848
nodePort: 30019
selector:
app: nacos
---
apiVersion: v1
kind: Service
metadata:
name: nacos-headless
namespace: nacos
spec:
ports:
- port: 8848
name: server
targetPort: 8848
- port: 7848
name: rpc
targetPort: 7848
clusterIP: None
selector:
app: nacos
6.statefulset
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nacos
namespace: nacos
spec:
serviceName: nacos-headless
replicas: 1
template:
metadata:
labels:
app: nacos
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- nacos
topologyKey: "kubernetes.io/hostname"
containers:
- name: nacos
imagePullPolicy: Always
image: nacos/nacos-server:latest
#resources:
# requests:
# memory: "2Gi"
# cpu: "500m"
ports:
- containerPort: 8848
name: client-port
- containerPort: 7848
name: rpc
env:
- name: NACOS_REPLICAS
value: "1"
- 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
- name: NACOS_SERVER_PORT
value: "8848"
- name: NACOS_APPLICATION_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
- name: TZ
value: Asia/Shanghai
- name: MODE
value: standalone
- name: NACOS_SERVERS
value: "nacos-0.nacos.svc.cluster.local:8848"
- name: SPRING_DATASOURCE_PLATFORM
value: mysql
volumeMounts:
- name: datadir
mountPath: /home/nacos/data
- name: logdir
mountPath: /home/nacos/logs
volumeClaimTemplates:
- metadata:
name: datadir
annotations:
volume.beta.kubernetes.io/storage-class: "nfs-csi"
spec:
accessModes: [ "ReadWriteMany" ]
resources:
requests:
storage: 5Gi
- metadata:
name: logdir
annotations:
volume.beta.kubernetes.io/storage-class: "nfs-csi"
spec:
accessModes: [ "ReadWriteMany" ]
resources:
requests:
storage: 5Gi
selector:
matchLabels:
app: nacos
7.访问验证
# 在web界面创建一个配置,随后登录数据库验证数据是否写入数据库
$ kubectl exec -it -n nacos pods/mysql-4k6m6 -- /bin/bash
bash-4.2# mysql -uroot -pnacos
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| nacos_db |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
mysql> show tables;
+----------------------+
| Tables_in_nacos_db |
+----------------------+
| config_info |
| config_info_aggr |
| config_info_beta |
| config_info_tag |
| config_tags_relation |
| group_capacity |
| his_config_info |
| permissions |
| roles |
| tenant_capacity |
| tenant_info |
| users |
+----------------------+
12 rows in set (0.00 sec)
mysql> select * from config_info;
+----+---------+---------------+---------+----------------------------------+---------------------+---------------------+----------+----------------+----------+-----------+--------+-------+--------+------+----------+--------------------+
| id | data_id | group_id | content | md5 | gmt_create | gmt_modified | src_user | src_ip | app_name | tenant_id | c_desc | c_use | effect | type | c_schema | encrypted_data_key |
+----+---------+---------------+---------+----------------------------------+---------------------+---------------------+----------+----------------+----------+-----------+--------+-------+--------+------+----------+--------------------+
| 1 | test | DEFAULT_GROUP | 1 | c4ca4238a0b923820dcc509a6f75849b | 2024-04-26 10:42:19 | 2024-04-26 10:42:19 | NULL | 10.100.106.128 | | | NULL | NULL | NULL | text | NULL | |
+----+---------+---------------+---------+----------------------------------+---------------------+---------------------+----------+----------------+----------+-----------+--------+-------+--------+------+----------+--------------------+
1 row in set (0.00 sec)
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)