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: middlelabels: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-nacosnamespace: middlelabels:type: localpv-name: pv-volume-nacos
spec:storageClassName: manual-nacoscapacity:storage: 1GiaccessModes:- ReadWriteOncehostPath:path: "/work/devops/k8s/app/nacos/pv"
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:name: pv-claim-nacosnamespace: middle
spec:storageClassName: manual-nacosaccessModes:- ReadWriteOnceresources:requests:storage: 1Giselector:matchLabels:pv-name: pv-volume-nacos#创建Nacos容器
---
apiVersion: apps/v1
kind: Deployment
metadata:name: nacos-standalonenamespace: middle
spec:replicas: 1  #单机模式下若副本大于1,注册时会分配到不同副本上。web查看时,只能看到一个副本的注册服务。刷新web网页可切换副本selector:matchLabels:app: nacos-standalonetemplate:metadata:labels:app: nacos-standaloneannotations:pod.alpha.kubernetes.io/initialized: "true"spec:tolerations:       #设置能在master上部署- key: node-role.kubernetes.io/masteroperator: ExistsinitContainers:- name: peer-finder-plugin-installimage: nacos/nacos-peer-finder-plugin:1.1imagePullPolicy: AlwaysvolumeMounts:- mountPath: /home/nacos/plugins/peer-findername: volumesubPath: peer-findercontainers:- name: nacosimage: nacos/nacos-server:v2.3.0imagePullPolicy: IfNotPresentenv:- name: TZvalue: Asia/Shanghai- name: MODEvalue: standalone- name: EMBEDDED_STORAGEvalue: embeddedvolumeMounts:- name: volumemountPath: /home/nacos/plugins/peer-findersubPath: peer-finder- name: volumemountPath: /home/nacos/datasubPath: data- name: volumemountPath: /home/nacos/logssubPath: logs- name: config-mapmountPath: /home/nacos/conf/application.propertiessubPath: application.propertiesports:- containerPort: 8848name: client- containerPort: 9848name: client-rpc- containerPort: 9849name: raft-rpc- containerPort: 7848name: old-raft-rpcvolumes:- name: volumepersistentVolumeClaim:claimName: pv-claim-nacos- name: config-mapconfigMap:name: nacos-configmapaffinity:podAntiAffinity:requiredDuringSchedulingIgnoredDuringExecution:- labelSelector:matchExpressions:- key: "app"operator: Invalues:- nacos-standalonetopologyKey: "kubernetes.io/hostname"---
apiVersion: v1
kind: Service
metadata:namespace: middlename: nacos-servicelabels:app: nacos-service
spec:type: NodePortports:- port: 8848name: server-registtargetPort: 8848nodePort: 30006- port: 9848  # 必须开放出去,否则开发和互联网环境无法访问,这是rpc 服务调用,程序默认 端口 偏移 1000 name: server-grpctargetPort: 9848nodePort: 30007 - port: 9849  # 必须开放出去,否则开发和互联网环境无法访问,这是rpc 服务调用,程序默认 端口 偏移 1000 name: server-grpc-synctargetPort: 9849nodePort: 30008selector: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),登录进去:

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

vectorCast——Probe point 功能实现故障注入,局部变量打印,断点调试。

选择一个测试用例,选择coverage窗口进行查看。点击edit probe point,如图所示绿色的小圆圈。选代码中选择需要打断点的地方进行点击。黑色的小圆点都可以选。点击黑色小圆点,小圆点变绿,表示打断点成功。此时就可以根据自己的需求在打断点的位置编写一些C语言的命令语句。点…

线程同步--生产者消费者模型--单例模式线程池

文章目录 一.条件变量pthread线程库提供的条件变量操作 二.生产者消费者模型生产者消费者模型的高效性基于环形队列实现生产者消费者模型中的数据容器基于生产者消费者模型实现单例线程池 一.条件变量 条件变量是线程间共享的全局变量,线程间可以通过条件变量进行同步控制条件…

ffmpeg 常用命令行详解

概述 ffmpeg 是一个命令行音视频后期处理软件 1. 裁剪命令 参数说明 -i 文件,orgin.mp3 为待处理源文件-ss 裁剪时间,后跟裁剪开始时间,或者开始的秒数-t 裁剪时间output.mp3 为处理结果文件 ffmpeg -i organ.mp3 -ss 00:00:xx -t 120 o…

无刷电机学习-原理篇

一、无刷电机的优点 使用一项东西首先就要明白为什么要使用它,使用它有什么优点。与有刷电机相比无刷电机除了控制繁琐几乎全是优点。 1、应用范围广:家用电器(冰箱空调压缩机、洗衣机、水泵等)、汽车、航空航天、消费品工业自动…

4个值得使用的免费爬虫工具

在信息时代,数据的获取对于各行业都至关重要。而在数据采集的众多工具中,免费的爬虫软件成为许多用户的首选。本文将专心分享四款免费爬虫工具,突出介绍其中之一——147采集软件,为您揭示这些工具的优势和应用,助您在数…

【c语言】扫雷(上)

先开一个test.c文件用来游戏的逻辑测试,在分别开一个game.c文件和game.h头文件用来实现游戏的逻辑 主要步骤: 游戏规则: 输入1(0)开始(结束)游戏,输入一个坐标,如果该坐…

nodejs前端项目的CI/CD实现(二)jenkins的容器化部署

一、背景 docker安装jenkins,可能你会反问,这太简单了,有什么好讲的。 我最近就接手了一个打包项目,它是一个nodejs的前端项目,jenkins已在容器里部署且运行OK。 但是,前端组很追求新技术,不…

中小企业股权质押融资(下)

股权质押融资的主要风险 由于股权资产的特殊性,较固定资产抵押和质押、第三方担保等方式,股权质押融资风险易受企业经营状况等因素的影响,主要包括股权价值下跌的风险、股权质押的道德风险、股权处置风险以及现行法律不完善导致的法律风险。…

前端面试题汇总大全(含答案)-- 持续更新

​一、HTML 篇 1. 简述一下你对 HTML 语义化的理解? 用正确的标签做正确的事情。 html 语义化让页面的内容结构化,结构更清晰,便于对浏览器、搜索引擎解析;即使在没有样式 CSS 情况下也以一种文档格式显示,并且是容易…

学习Spring的第八天

先对自定义类使用MyComponet的注解,在设置这个MyComponet的的属性(一个 interface接口),然后,扫描(BaseClassScanUtils.java执行,这文件不重要)当前包下是否有这个注解的类,再用MyComponentBeanFactoryPostProcessor.java(后工厂…

AI智能绘图,触手可及的未来

AI智能绘图不仅仅是技术的体现,更是对人类情感的共鸣。它能够根据用户的描述或情感需求,自动生成与之相匹配的画作。它们或细腻如丝,或磅礴如海,或温婉如诗,或激昂如歌,而这正是AI智能绘图的魅力所在。 所…

bgp基础实验

最终实验效果: 全网可达:R1,R7路由表都有r1-r7环回,R1汇总0.0/22和1.0/24,R7另一环回172.16.2.1/32 用tracert命令来R1 ping R7环回,实现全网通 实现代码: 首先配置好接口ip和环回,然后: [r1] rip 1 version 2 network 1.0.0.0 network 12.0.0.0 network 192.168.1.0 …

顶顶通呼叫中心中间件如何实现自己呼叫自己并且放音:一步步配置(mod_cti基于FreeSWITCH)

介绍 顶顶通呼叫中心中间件如何实现自己呼叫自己并且放音:一步步配置 一、配置acl.conf 打开ccadmin-》点击配置文件并且打开acl.conf-》配置好了点击提交XML。 注意:acl.conf的服务器IP必须是内网IP 添加了之后在运维调试输入reloadacl 在运维调试执…

【NVIDIA】Jetson Orin Nano系列:安装 Qt6、firefox、jtop、flameshot

1、使用命令安装 sudo apt install qtcreator sudo apt install qt6-* sudo apt install libqt6* sudo apt install qml-qt6 sudo apt install qmlscene-qt6 sudo apt install assistant-qt6 sudo apt install designer-qt62、启动 qtcreator 3、常用工具安装 sudo apt in…

MyBatis 使用报错:org.xml.sax.SAXParseException 元素内容必须由格式正确的字符数据或标记组成

文章目录 前言问题分析解决方案方案一&#xff1a;使用 CDATA 区块&#xff0c;依然使用 “ > ” 或者 “ < ”方案二&#xff1a;使用转义字符 个人简介 前言 今天在使用 MyBatis 时出现报错&#xff1a; Caused by: org.xml.sax.SAXParseException: 元素内容必须由格式…

目标文献分析方法

如何正确选题&#xff1f; 不仅仅是题目&#xff0c;而是研究工作的起步选题步骤&#xff1f; 发现问题选择方向调查研究分析论证确定选题 中国知网 深度学习方向词 1检索&#xff1a;深度学习 医疗影像 1 发表时间要最新 2 显示50个&#xff0c;全选 3 导出文献格式Ref 4 导…

SpringCloud Aliba-Sentinel【中篇】-从入门到学废【5】

目录 1.流控规则 2. 熔断规则 3.热点规则 1.流控规则 1.资源名&#xff1a;唯一名称&#xff0c;默认请求路径 2.针对来源: Sentinel可以针对调用者进行限流,填写微服务名,默认default (不区分来源) 3.阈值类型/单机阈值&#xff1a; QPS&#xff08;每秒钟的请求数量&…

高光谱分类论文解读分享之HybridSN:基于 3-D–2-D CNN 的高光谱分类(经典回顾)

IEEE GRSL 2019&#xff1a;HybridSN&#xff1a;基于 3-D–2-D CNN 的高光谱分类 题目 HybridSN: Exploring 3-D–2-D CNN Feature Hierarchy for Hyperspectral Image Classification 作者 Swalpa Kumar Roy, Student Member, IEEE, Gopal Krishna, Shiv Ram Dubey , Mem…

探秘网络爬虫的基本原理与实例应用

1. 基本原理 网络爬虫是一种用于自动化获取互联网信息的程序&#xff0c;其基本原理包括URL获取、HTTP请求、HTML解析、数据提取和数据存储等步骤。 URL获取&#xff1a; 确定需要访问的目标网页&#xff0c;通过人工指定、站点地图或之前的抓取结果获取URL。 HTTP请求&#…

python有哪些解释器?

Python的解释器有&#xff1a; CPython&#xff1a;官方的Python解释器&#xff0c;使用C语言实现。Jython&#xff1a;运行在Java平台上的Python解释器&#xff0c;使用Java语言实现。IronPython&#xff1a;运行在.NET平台上的Python解释器&#xff0c;使用C#语言实现。PyPy…