K8S--部署Nacos

原文网址:K8S--部署Nacos-CSDN博客

简介

本文介绍K8S部署Nacos的方法。Nacos版本是:2.2.3。

部署方案

本文为了简单,使用此部署方式:使用本地pv+configmap,以embedded模式部署单机nacos。以nodePort方式暴露端口。

正式环境可以这样部署:使用nfs,以mysql方式部署集群nacos,以ingress方式暴露端口。

官网网址

Kubernetes Nacos | Nacos

https://github.com/nacos-group/nacos-k8s/blob/master/deploy/nacos/nacos-pvc-nfs.yaml

部署结果

我的工作目录:/work/devops/k8s/app/nacos

1.创建命名空间

创建namespace.yaml文件

内容如下:

# 创建命名空间
apiVersion: v1
kind: Namespace
metadata:
  name: middle
  labels:
    name: middle

创建命名空间

kubectl apply -f namespace.yaml

结果 

 

2.用ConfigMap创建配置

这里只能用ConfigMap,因为PV不能挂载单个文件,只能挂载目录。ConfigMap可以单独挂载配置文件。(想要挂载单个文件可以用hostPath方式)。

1.修改配置

先从github上下载nacos压缩包,地址:这里

修改配置文件(nacos-server-2.2.3\nacos\conf\application.properties),修改点如下:

备注:除了第一个要改为true之外,下边的几个都是随便写(最后一个配置必须大于32个字符,不然会报错)。 

修改后的配置文件如下:

#
# Copyright 1999-2021 Alibaba Group Holding Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

#*************** Spring Boot Related Configurations ***************#
### Default web context path:
server.servlet.contextPath=/nacos
### Include message field
server.error.include-message=ALWAYS
### Default web server port:
server.port=8848

#*************** Network Related Configurations ***************#
### If prefer hostname over ip for Nacos server addresses in cluster.conf:
# nacos.inetutils.prefer-hostname-over-ip=false

### Specify local server's IP:
# nacos.inetutils.ip-address=


#*************** Config Module Related Configurations ***************#
### If use MySQL as datasource:
### Deprecated configuration property, it is recommended to use `spring.sql.init.platform` replaced.
# spring.datasource.platform=mysql
# spring.sql.init.platform=mysql

### Count of DB:
# db.num=1

### Connect URL of DB:
# db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
# db.user.0=nacos
# db.password.0=nacos

### Connection pool configuration: hikariCP
db.pool.config.connectionTimeout=30000
db.pool.config.validationTimeout=10000
db.pool.config.maximumPoolSize=20
db.pool.config.minimumIdle=2

#*************** Naming Module Related Configurations ***************#

### If enable data warmup. If set to false, the server would accept request without local data preparation:
# nacos.naming.data.warmup=true

### If enable the instance auto expiration, kind like of health check of instance:
# nacos.naming.expireInstance=true

### Add in 2.0.0
### The interval to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.interval=60000

### The expired time to clean empty service, unit: milliseconds.
# nacos.naming.clean.empty-service.expired-time=60000

### The interval to clean expired metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.interval=5000

### The expired time to clean metadata, unit: milliseconds.
# nacos.naming.clean.expired-metadata.expired-time=60000

### The delay time before push task to execute from service changed, unit: milliseconds.
# nacos.naming.push.pushTaskDelay=500

### The timeout for push task execute, unit: milliseconds.
# nacos.naming.push.pushTaskTimeout=5000

### The delay time for retrying failed push task, unit: milliseconds.
# nacos.naming.push.pushTaskRetryDelay=1000

### Since 2.0.3
### The expired time for inactive client, unit: milliseconds.
# nacos.naming.client.expired.time=180000

#*************** CMDB Module Related Configurations ***************#
### The interval to dump external CMDB in seconds:
# nacos.cmdb.dumpTaskInterval=3600

### The interval of polling data change event in seconds:
# nacos.cmdb.eventTaskInterval=10

### The interval of loading labels in seconds:
# nacos.cmdb.labelTaskInterval=300

### If turn on data loading task:
# nacos.cmdb.loadDataAtStart=false


#*************** Metrics Related Configurations ***************#
### Metrics for prometheus
#management.endpoints.web.exposure.include=*

### Metrics for elastic search
management.metrics.export.elastic.enabled=false
#management.metrics.export.elastic.host=http://localhost:9200

### Metrics for influx
management.metrics.export.influx.enabled=false
#management.metrics.export.influx.db=springboot
#management.metrics.export.influx.uri=http://localhost:8086
#management.metrics.export.influx.auto-create-db=true
#management.metrics.export.influx.consistency=one
#management.metrics.export.influx.compressed=true

#*************** Access Log Related Configurations ***************#
### If turn on the access log:
server.tomcat.accesslog.enabled=true

### The access log pattern:
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i

### The directory of access log:
server.tomcat.basedir=file:.

#*************** Access Control Related Configurations ***************#
### If enable spring security, this option is deprecated in 1.2.0:
#spring.security.enabled=false

### The ignore urls of auth
nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**

### The auth system to use, currently only 'nacos' and 'ldap' is supported:
nacos.core.auth.system.type=nacos

### If turn on auth system:
#nacos.core.auth.enabled=false
nacos.core.auth.enabled=true

### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=true

### Since 1.4.1, Turn on/off white auth for user-agent: nacos-server, only for upgrade from old version.
nacos.core.auth.enable.userAgentAuthWhite=false

### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
#nacos.core.auth.server.identity.key=
#nacos.core.auth.server.identity.value=
nacos.core.auth.server.identity.key=exampleKey
nacos.core.auth.server.identity.value=exampleValue

### worked when nacos.core.auth.system.type=nacos
### The token expiration in seconds:
nacos.core.auth.plugin.nacos.token.cache.enable=false
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
### The default token (Base64 String):
#nacos.core.auth.plugin.nacos.token.secret.key=
nacos.core.auth.plugin.nacos.token.secret.key=Ho9pJlDFurhga1847fhj3jtlsvc18jguehfjgkhh17365jdf8

### worked when nacos.core.auth.system.type=ldap,{0} is Placeholder,replace login username
#nacos.core.auth.ldap.url=ldap://localhost:389
#nacos.core.auth.ldap.basedc=dc=example,dc=org
#nacos.core.auth.ldap.userDn=cn=admin,${nacos.core.auth.ldap.basedc}
#nacos.core.auth.ldap.password=admin
#nacos.core.auth.ldap.userdn=cn={0},dc=example,dc=org
#nacos.core.auth.ldap.filter.prefix=uid
#nacos.core.auth.ldap.case.sensitive=true


#*************** Istio Related Configurations ***************#
### If turn on the MCP server:
nacos.istio.mcp.server.enabled=false

#*************** Core Related Configurations ***************#

### set the WorkerID manually
# nacos.core.snowflake.worker-id=

### Member-MetaData
# nacos.core.member.meta.site=
# nacos.core.member.meta.adweight=
# nacos.core.member.meta.weight=

### MemberLookup
### Addressing pattern category, If set, the priority is highest
# nacos.core.member.lookup.type=[file,address-server]
## Set the cluster list with a configuration file or command-line argument
# nacos.member.list=192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809
## for AddressServerMemberLookup
# Maximum number of retries to query the address server upon initialization
# nacos.core.address-server.retry=5
## Server domain name address of [address-server] mode
# address.server.domain=jmenv.tbsite.net
## Server port of [address-server] mode
# address.server.port=8080
## Request address of [address-server] mode
# address.server.url=/nacos/serverlist

#*************** JRaft Related Configurations ***************#

### Sets the Raft cluster election timeout, default value is 5 second
# nacos.core.protocol.raft.data.election_timeout_ms=5000
### Sets the amount of time the Raft snapshot will execute periodically, default is 30 minute
# nacos.core.protocol.raft.data.snapshot_interval_secs=30
### raft internal worker threads
# nacos.core.protocol.raft.data.core_thread_num=8
### Number of threads required for raft business request processing
# nacos.core.protocol.raft.data.cli_service_thread_num=4
### raft linear read strategy. Safe linear reads are used by default, that is, the Leader tenure is confirmed by heartbeat
# nacos.core.protocol.raft.data.read_index_type=ReadOnlySafe
### rpc request timeout, default 5 seconds
# nacos.core.protocol.raft.data.rpc_request_timeout_ms=5000

#*************** Distro Related Configurations ***************#

### Distro data sync delay time, when sync task delayed, task will be merged for same data key. Default 1 second.
# nacos.core.protocol.distro.data.sync.delayMs=1000

### Distro data sync timeout for one sync data, default 3 seconds.
# nacos.core.protocol.distro.data.sync.timeoutMs=3000

### Distro data sync retry delay time when sync data failed or timeout, same behavior with delayMs, default 3 seconds.
# nacos.core.protocol.distro.data.sync.retryDelayMs=3000

### Distro data verify interval time, verify synced data whether expired for a interval. Default 5 seconds.
# nacos.core.protocol.distro.data.verify.intervalMs=5000

### Distro data verify timeout for one verify, default 3 seconds.
# nacos.core.protocol.distro.data.verify.timeoutMs=3000

### Distro data load retry delay when load snapshot data failed, default 30 seconds.
# nacos.core.protocol.distro.data.load.retryDelayMs=30000

### enable to support prometheus service discovery
#nacos.prometheus.metrics.enabled=true

### Since 2.3
#*************** Grpc Configurations ***************#

## sdk grpc(between nacos server and client) configuration
## Sets the maximum message size allowed to be received on the server.
#nacos.remote.server.grpc.sdk.max-inbound-message-size=10485760

## Sets the time(milliseconds) without read activity before sending a keepalive ping. The typical default is two hours.
#nacos.remote.server.grpc.sdk.keep-alive-time=7200000

## Sets a time(milliseconds) waiting for read activity after sending a keepalive ping. Defaults to 20 seconds.
#nacos.remote.server.grpc.sdk.keep-alive-timeout=20000


## Sets a time(milliseconds) that specify the most aggressive keep-alive time clients are permitted to configure. The typical default is 5 minutes
#nacos.remote.server.grpc.sdk.permit-keep-alive-time=300000

## cluster grpc(inside the nacos server) configuration
#nacos.remote.server.grpc.cluster.max-inbound-message-size=10485760

## Sets the time(milliseconds) without read activity before sending a keepalive ping. The typical default is two hours.
#nacos.remote.server.grpc.cluster.keep-alive-time=7200000

## Sets a time(milliseconds) waiting for read activity after sending a keepalive ping. Defaults to 20 seconds.
#nacos.remote.server.grpc.cluster.keep-alive-timeout=20000

## Sets a time(milliseconds) that specify the most aggressive keep-alive time clients are permitted to configure. The typical default is 5 minutes
#nacos.remote.server.grpc.cluster.permit-keep-alive-time=300000

2.生成ConfigMap

将上一步的文件放到此路径:/work/devops/k8s/app/nacos/conf/application.properties

kubectl create configmap nacos-configmap --namespace=middle --from-file=conf/application.properties

结果:

configmap/nacos-configmap created

命令查看结果

kubectl get configmap -n middle

结果

dashboard查看结果 

3.创建K8S配置

创建k8s.yaml文件,内容如下:

#用PV创建存储空间
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: pv-volume-nacos
  namespace: middle
  labels:
    type: local
    pv-name: pv-volume-nacos
spec:
  storageClassName: manual-nacos
  capacity:
    storage: 1Gi
  accessModes:
    - ReadWriteOnce
  hostPath:
    path: "/work/devops/k8s/app/nacos/pv"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: pv-claim-nacos
  namespace: middle
spec:
  storageClassName: manual-nacos
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 1Gi
  selector:
    matchLabels:
      pv-name: pv-volume-nacos

#创建Nacos容器
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nacos-standalone
  namespace: middle
spec:
  replicas: 1  #单机模式下若副本大于1,注册时会分配到不同副本上。web查看时,只能看到一个副本的注册服务。刷新web网页可切换副本
  selector:
    matchLabels:
      app: nacos-standalone
  template:
    metadata:
      labels:
        app: nacos-standalone
      annotations:
        pod.alpha.kubernetes.io/initialized: "true"
    spec:
      tolerations:       #设置能在master上部署
      - key: node-role.kubernetes.io/master
        operator: Exists
      initContainers:
        - name: peer-finder-plugin-install
          image: nacos/nacos-peer-finder-plugin:1.1
          imagePullPolicy: Always
          volumeMounts:
            - mountPath: /home/nacos/plugins/peer-finder
              name: volume
              subPath: peer-finder
      containers:
        - name: nacos
          image: nacos/nacos-server:v2.3.0
          imagePullPolicy: IfNotPresent
          env:
            - name: TZ
              value: Asia/Shanghai
            - name: MODE
              value: standalone
            - name: EMBEDDED_STORAGE
              value: embedded
          volumeMounts:
            - name: volume
              mountPath: /home/nacos/plugins/peer-finder
              subPath: peer-finder
            - name: volume
              mountPath: /home/nacos/data
              subPath: data
            - name: volume
              mountPath: /home/nacos/logs
              subPath: logs
            - name: config-map
              mountPath: /home/nacos/conf/application.properties
              subPath: application.properties
          ports:
            - containerPort: 8848
              name: client
            - containerPort: 9848
              name: client-rpc
            - containerPort: 9849
              name: raft-rpc
            - containerPort: 7848
              name: old-raft-rpc

      volumes:
      - name: volume
        persistentVolumeClaim:
          claimName: pv-claim-nacos
      - name: config-map
        configMap:
          name: nacos-configmap
      affinity:
        podAntiAffinity:
          requiredDuringSchedulingIgnoredDuringExecution:
            - labelSelector:
                matchExpressions:
                  - key: "app"
                    operator: In
                    values:
                      - nacos-standalone
              topologyKey: "kubernetes.io/hostname"

---
apiVersion: v1
kind: Service
metadata:
  namespace: middle
  name: nacos-service
  labels:
    app: nacos-service
spec:
  type: NodePort
  ports:
    - port: 8848
      name: server-regist
      targetPort: 8848
      nodePort: 30006
    - port: 9848  # 必须开放出去,否则开发和互联网环境无法访问,这是rpc 服务调用,程序默认 端口 偏移 1000 
      name: server-grpc
      targetPort: 9848
      nodePort: 30007 
    - port: 9849  # 必须开放出去,否则开发和互联网环境无法访问,这是rpc 服务调用,程序默认 端口 偏移 1000 
      name: server-grpc-sync
      targetPort: 9849
      nodePort: 30008
  selector:
    app: nacos-standalone

4.启动Nacos

kubectl apply -f k8s.yaml 

结果

persistentvolume/pv-volume-nacos created
persistentvolumeclaim/pv-claim-nacos created
deployment.apps/nacos-standalone created
service/nacos-service created

用命令查看结果

kubectl get all -n middle

结果

用dashboard查看结果

 

 

5.访问Nacos页面 

访问:http://192.168.5.193:30006/nacos

结果:

输入默认的账号密码(nacos/nacos),登录进去:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:/a/329977.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

如何禁用WordPress站点的管理员电子邮件验证或修改检查频率?

今天boke112百科登录某个WordPress站点时,又出现“管理员邮件确认”的提示,要求确认此站点的管理员电子邮箱地址是否仍然正确。具体如下图所示: 如果点击“稍后提醒我”,那么管理员邮件验证页面就会在3天后重新显示。 说实话&…

关于linux 救援模式出现xfs 文件系统挂载报 bad supperblock

关于linux 救援模式出现xfs 文件系统挂载报 bad supperblock 一种情况说明 挂载ISO文件进入救援模式,无法挂载XFS文件系统,xfs_repair也是报未知的超级块 使用 xfs_info 可以取到 xfs文件系统分区信息 xfs_db -c “sb 0” -c “p” $your_xfs_dev 也能…

Flutter 综述

Flutter 综述 1 介绍1.1 概述1.2 重要节点1.3 移动开发中三种跨平台框架技术对比1.4 flutter 技术栈1.5 IDE1.6 Dart 语言1.7 应用1.8 框架 2 Flutter的主要组成部分3 资料书籍 《Flutter实战第二版》Dart 语言官网Flutter中文开发者社区flutter 官网 4 搭建Flutter开发环境参考…

小程序 常用组件

文章目录 常见组件viewtextimageswipernavigatorrich-textnodes属性 buttoniconfromradiocheckbox 常见组件 重点讲解⼩程序中常⽤的布局组件 view,text,rich–text,button,image,navigator,icon,swiper,radio,checkbox。 等 view 代替 原来的 div 标签 <view hover-clas…

医院网络安全建设:三网整体设计和云数据中心架构设计

医院网络安全问题涉及到医院日常管理多个方面&#xff0c;一旦医院信息管理系统在正常运行过程中受到外部恶意攻击&#xff0c;或者出现意外中断等情况&#xff0c;都会造成海量医疗数据信息的丢失。由于医院信息管理系统中存储了大量患者个人信息和治疗方案信息等&#xff0c;…

Python 一行命令部署http、ftp服务

Python 一行命令部署http服务 文章目录 Python 一行命令部署http服务具体操作命令如下浏览器返回下载Python 一行命令部署FTP服务 具体操作命令如下 这个比nginx相对来说更加简单&#xff0c;可以用于部署特殊场景时如银行等部署时&#xff0c;各种权限控制&#xff0c;内网之间…

Base64编码原理解析

文章目录 一、Base64Base64编码的原理如下&#xff1a;以字符串"hello world"为例&#xff0c;它的ASCII码为&#xff08;下面&#x1f447;是ASCII码对照表&#xff09;&#xff1a;将这些ASCII码转换为二进制&#xff08;对照上表&#xff09;&#xff1a;将上述二…

TCP 拥塞控制对数据延迟的影响

哈喽大家好&#xff0c;我是咸鱼 今天分享一篇文章&#xff0c;是关于 TCP 拥塞控制对数据延迟产生的影响的。作者在服务延迟变高之后进行抓包分析&#xff0c;结果发现时间花在了 TCP 本身的机制上面&#xff1a;客户端并不是将请求一股脑发送给服务端&#xff0c;而是只发送…

uni-app的组件(二)

多项选择器checkbox-group 多项选择器&#xff0c;内部由多个 checkbox 组成。 <checkbox-group><checkbox checked color"red" value"1"></checkbox> 篮球<!-- disabled:是否禁用 --><checkbox disabled color"rgba(0,0…

设计模式-创建者模式

1.单例模式 单例模式&#xff08;Singleton Pattern&#xff09;是 Java 中最简单的设计模式之一&#xff0c;此模式保证某个类在运行期间&#xff0c;只有一个实例对外提供服务&#xff0c;而这个类被称为单例类。 使用单例模式要做的两件事 1. 保证一个类只有一个实例 2.…

ruoyi-cloud—若依微服务打包部署

1. 前端端口修改 2. 后端端口修改 &#xff08;1&#xff09;修改ruoyi-gateway服务中的bootstrap.yml的port端口 &#xff08;2&#xff09;修改ruoyi-ui中的vue.confing.js的target中的端口 3. 后端部署 (1) 在本地电脑上代码界面上打包后端 在ruoyi项目的bin目录下执行pa…

最新内置30+远程接口,全新API接口管理系统PHP源码,附带系统搭建教程

搭建教程 内置30远程接口doc文件夹可参考自行编辑api文件夹里附赠qrcode接口源码 此程序基于ThinkPHP5.1 PHP版本需7.0-7.3之间。 Nginx请设置如下TP伪静态 Apache无需配置 运行目录默认即可 将程序上传至网站根目录,访问域名/install进行安装操作

如何卸载旧版docker

环境&#xff1a; Docker1.13 centos7.6 问题描述&#xff1a; 如何卸载旧版docker 解决方案&#xff1a; 1.停止Docker服务。使用以下命令停止Docker服务&#xff1a; sudo service docker stop2.卸载Docker软件包。根据您的Linux发行版&#xff0c;使用适当的包管理器来…

GRU门控循环单元神经网络的MATLAB实现(含源代码)

在深度学习领域&#xff0c;循环神经网络&#xff08;RNN&#xff09;因其在处理序列数据方面的卓越能力而受到广泛关注。GRU&#xff08;门控循环单元&#xff09;作为RNN的一种变体&#xff0c;以其在捕捉时间序列长距离依赖关系方面的高效性而备受推崇。在本文中&#xff0c…

【Redis】Redis如何做内存优化?

​ &#x1f34e;个人博客&#xff1a;个人主页 &#x1f3c6;个人专栏&#xff1a;Redis ⛳️ 功不唐捐&#xff0c;玉汝于成 ​ 目录 前言 正文 使用数据结构&#xff1a; 压缩对象&#xff1a; 过期策略&#xff1a; 分片&#xff1a; 使用持久化方式&#xff1a…

【React】组件性能优化、高阶组件

文章目录 React性能优化SCUReact更新机制keys的优化render函数被调用shouldComponentUpdatePureComponentshallowEqual方法高阶组件memo 获取DOM方式refs如何使用refref的类型 受控和非受控组件认识受控组件非受控组件 React的高阶组件认识高阶函数高阶组件的定义应用一 – pro…

高校学生选课系统源码开发方案

一、项目背景与目标 &#xff08;一&#xff09;项目背景 随着高校教育的发展&#xff0c;学生选课系统成为了高校管理中不可或缺的一部分。传统的手工选课方式存在着效率低下、易出错等问题&#xff0c;因此需要开发一款高效、便捷的高校学生选课系统。 &#xff08;二&…

【机器学习】机器学习四大类第01课

一、机器学习四大类 有监督学习 (Supervised Learning) 有监督学习是通过已知的输入-输出对&#xff08;即标记过的训练数据&#xff09;来学习函数关系的过程。在训练阶段&#xff0c;模型会根据这些示例调整参数以尽可能准确地预测新的、未见过的数据点的输出。 实例&#x…

使用 vsCode创建GO项目

最近回顾了一下go的使用&#xff1a;具体操作看下面的参考连接&#xff0c;下面只描述一些踩过的坑&#xff1a; 1. go安装配置 安装go->配置go环境变量 推荐官网下载&#xff0c;速度很快&#xff1b; 这里需要配置五个参数&#xff1a;GOPATH/GOROOT/Path、GO111MODULE/…

护眼台灯有AAA级吗?国家AA级护眼灯推荐

在当今这个时代&#xff0c;人们对于知识的需求越来越大。因此&#xff0c;很多的孩子在学业上也是非常的繁忙的&#xff0c;晚上做作业也成为了很多学生的“家常便饭”了&#xff0c;台灯已然成为了很多孩子在夜晚学习的“伙伴”。 然而&#xff0c;很多的家长对于孩子在台灯…