Nacos(Namings and Configuration Management)是阿里巴巴开源的一个易于构建云原生应用的动态服务发现、配置管理和服务管理平台。
以下是Nacos的一些主要功能和特点:
更多内容 ?https://nacos.io/zh-cn/docs/architecture.html
数据库安装部署就不在这里写了:
# 下载初始化SQL文件
$ wget https://raw.Githubusercontent.com/alibaba/nacos/master/distribution/conf/mysql-schema.sql
# 进去容器
$ docker exec -it mysql bash
# 进入数据库
$ mysql -u root -pAdmin@1234
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.44 MySQL Community Server (GPL)
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql>
# 创建数据库
mysql> create database nacos;
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| nacos |
| performance_schema |
| sys |
+--------------------+
5 rows in set (0.00 sec)
# 初始化数据库
mysql> use nacos;
mysql> source mysql-schema.sql;
本案例以MySQL作为持久化存储部署:
# 新建一个命名空间
$ kubectl create ns dev
# 拉取安装配置
$ git clone https://github.com/nacos-group/nacos-k8s.git
$ cd nacos-k8s/deploy/nacos
修改配置:
# 修改数据库信息
$ nacos-no-pvc-ingress.yaml
...
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm
data:
mysql.host: "10.0.53.73"
mysql.db.name: "nacos"
mysql.port: "3306"
mysql.user: "root"
mysql.password: "Admin@1234"
- name: NACOS_AUTH_ENABLE
value: "true"
- name: nacos.core.auth.server.identity.key
value: "subM8MzvolJ+MWYVhgkOBC7EvkwOrYczDYOsAB/6KhA="
- name: nacos.core.auth.server.identity.value
value: "7YlBYjd2HU+9DJpPRV4zcvvEkBqO8SxNpfJRDNqPH30="
- name: nacos.core.auth.plugin.nacos.token.secret.key
value: "SecretKey012345678901234567890123456789012345678901234567890123456789"
- name: NACOS_SERVERS
value: "nacos-0.nacos-headless.dev.svc.cluster.local:8848 nacos-1.nacos-headless.dev.svc.cluster.local:8848 nacos-2.nacos-headless.dev.svc.cluster.local:8848"
...
注意:NACOS_SERVERS配置指定的命名空间一定要与Nacos部署的命名空间一致
执行创建:
$ kubectl Apply -f nacos-pvc-nfs.yaml -n dev
service/nacos-headless created
configmap/nacos-cm created
statefulset.apps/nacos created
查看Pod状态:
$ kubectl get pods -n dev
NAME READY STATUS RESTARTS AGE
nacos-0 1/1 Running 0 4m35s
nacos-1 1/1 Running 0 4m19s
nacos-2 1/1 Running 0 4m4s
本次通过最简单的forward端口转发进行暴露进行访问(也可以通过Ingress进行暴露访问):
$ kubectl port-forward -n dev nacos-0 8848:8848 --address 0.0.0.0
http://转发机器IP:8848 默认帐号/密码:nacos/nacos:
查看集群状态:
到此为止,Nacos集群就完成部署了!
SpringCloud微服务容器化部署:https://www.processon.com/view/link/656850b84b191f7e7e04d4f5