k8s下部署nacos集群
这里使用的是外部 mysql 数据库,所以没有使用官方提供的 mysql 和存储方案。
1、clone 项目
git clone https://github.com/nacos-group/nacos-k8s.git
2、修改 yaml 文件,这里要注意 NACOS_SERVERS 的格式
cat nacos-quick-start.yaml --- # 添加一个 namespace apiVersion: v1 kind: Namespace metadata: name: yunjing-test --- apiVersion: v1 kind: Service metadata: name: nacos-headless # namespace: yunjing-test labels: app: nacos-headless spec: ports: - port: 8848 name: server targetPort: 8848 nodePort: 30112 # 添加 nodePort 曝光控制台 selector: app: nacos type: NodePort --- apiVersion: v1 kind: ConfigMap metadata: name: nacos-cm # namespace: yunjing-test data: mysql.db.host: "192.168.2.181" # 添加外部 mysql 访问地址 mysql.db.name: "nacos" mysql.port: "30006" mysql.user: "root" mysql.password: "mysql@@0627" --- apiVersion: apps/v1 kind: StatefulSet metadata: name: nacos # namespace: yunjing-test spec: serviceName: nacos-headless replicas: 3 template: metadata: labels: app: nacos annotations: pod.alpha.kubernetes.io/initialized: "true" spec: affinity: podAntiAffinity: requiredDuringSchedulingIgnoredDuringExecution: - labelSelector: matchExpressions: - key: "app" operator: In values: - nacos-headless topologyKey: "kubernetes.io/hostname" containers: - name: k8snacos imagePullPolicy: Always image: nacos/nacos-server:latest resources: requests: memory: "2Gi" cpu: "500m" ports: - containerPort: 8848 name: client env: - name: NACOS_REPLICAS value: "3" - name: MYSQL_SERVICE_DB_NAME valueFrom: configMapKeyRef: name: nacos-cm key: mysql.db.name - name: MYSQL_SERVICE_HOST # 添加 mysql 访问地址的环境变量 valueFrom: configMapKeyRef: name: nacos-cm key: mysql.db.host - 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: PREFER_HOST_MODE value: "hostname" - name: NACOS_SERVERS value: "nacos-0.nacos-headless.default.svc.cluster.local:8848 nacos-1.nacos-headless.default.svc.cluster.local:8848 nacos-2.nacos-headless.default.svc.cluster.local:8848" # 修改 namespace 名称 selector: matchLabels: app: nacos
部署 nacos
kubectl apply -f nacos-quick-start.yaml
查看服务状态
kubectl get po -n test
部署完成效果图
作者:南辞、归
本博客所有文章仅用于学习、研究和交流目的,欢迎非商业性质转载。
博主的文章没有高度、深度和广度,只是凑字数。由于博主的水平不高,不足和错误之处在所难免,希望大家能够批评指出。
博主是利用读书、参考、引用、抄袭、复制和粘贴等多种方式打造成自己的文章,请原谅博主成为一个无耻的文档搬运工!