K8S--部署Nacos

这篇具有很好参考价值的文章主要介绍了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

部署结果

K8S--部署Nacos,K8S,k8s,云原生

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

K8S--部署Nacos,K8S,k8s,云原生

1.创建命名空间

创建namespace.yaml文件

内容如下:

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

创建命名空间

kubectl apply -f namespace.yaml

结果 

 K8S--部署Nacos,K8S,k8s,云原生

2.用ConfigMap创建配置

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

1.修改配置

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

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

K8S--部署Nacos,K8S,k8s,云原生

备注:除了第一个要改为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

结果

K8S--部署Nacos,K8S,k8s,云原生

dashboard查看结果 

K8S--部署Nacos,K8S,k8s,云原生

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

结果

K8S--部署Nacos,K8S,k8s,云原生

用dashboard查看结果

 K8S--部署Nacos,K8S,k8s,云原生

K8S--部署Nacos,K8S,k8s,云原生

5.访问Nacos页面 

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

结果:

K8S--部署Nacos,K8S,k8s,云原生

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

K8S--部署Nacos,K8S,k8s,云原生文章来源地址https://www.toymoban.com/news/detail-809289.html

到了这里,关于K8S--部署Nacos的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 通过k8s搭建部署服务(nacos为例)

    前言:写这篇文章也算是自己对k8s的一种学习,加深一下k8s对服务部署的印象。 环境:使用的本地windows系统下的docker desktop工具,高版本的docker desktop自带了k8s服务所以就不需要特地去linux系统上装k8s了。docker desktop相当于在windows系统下配置了docker环境和k8s环境,可以直接在

    2024年02月14日
    浏览(31)
  • 基于Kubernetes(k8s)部署Dubbo+Nacos服务

    本文介绍基于 Kubernetes(k8s) 环境集成阿里云 私有镜像仓库 来部署一套 Dubbo + Nacos 的微服务系统,并使用 Kubernetes DNS 以及 port-forward 的方式来打通网络访问。 k8s环境搭建参考文章《基于minikube快速搭建kubernetes单节点环境》 中在阿里云镜像仓库构建的镜像来进行部署。 基于《基

    2024年02月02日
    浏览(32)
  • 二进制部署nacos、docker部署nacos、k8s部署nacos、helm部署nacos

    环境: centos7.9、k8s 1.22.15 、docker 20.10.9、nacos-server-2.2.2.tar.gz nacos是一个用于构建云原生应用的动态服务发现、配置管理和服务管理平台,简称服务配置注册管理中心。 本篇不讲多集群模式。本篇讲传统方式、docker方式、k8s方式部署nacos单机版和cluster版。 nacos的github官网:

    2024年02月04日
    浏览(65)
  • K8S单机部署-01.单机部署K8S

    转载请注明出处 K8S单机部署-00.旧版本卸载 K8S单机部署-01.单机部署K8S K8S单机部署-02.Kuboard面板部署 K8S单机部署-03.验证K8S的第一个Deployment K8S单机部署-04.NFS服务器搭建 K8S单机部署-05.静态持久化之PV、PVC(基于NFS) K8S单机部署-06.动态持久化StorageClass(基于NFS) K8S单机部署-07.调整

    2024年04月24日
    浏览(31)
  • k8s集群中集群方式安装nacos

    一个k8s集群,其中有三个master 节点,这三个节点的标签名称为etcd 三个master节点的ip 分别为:192.165.187.170 、192.165.187.171、192.165.187.172 一个mysql 数据库, 数据库的ip 为:192.165.187.180 用户名:root 密码:123456 在mysql 数据库中创建一个nacos名称的数据库,然后执行下面的建表语句

    2024年02月09日
    浏览(29)
  • Kubernetes(k8s)上搭建nacos集群

    你需要准备一个Kubernetes集群,如图我的集群已经准备完毕: nacos可以将配置文件存储到数据库当中,所以我们要先准备一个拥有nacos数据表结构的数据库,这样的数据库镜像我已经准备好了,当然你也可以自己制作这个镜像: 我之前写过一篇Kubernetes上安装数据库的文章:h

    2024年02月03日
    浏览(47)
  • k8s安装nacos(nacos镜像版本2.0.3)

    后期使用中,发现配置管理新增配置时提示\\\"nacos 发布失败。请检查参数是否正确。\\\"。同时控制台报了一个空指针异常,但是开发环境nacos2.1.0的版本正常,怀疑时版本的bug。镜像升级到nacos/nacos-server:v2.1.1后解决。因此,如果有按照本文档搭建环境的同学,请把下边镜像版本改

    2023年04月08日
    浏览(19)
  • K8s进阶之路-安装部署K8s

    参考:(部署过程参考的下面红色字体文档链接就可以,步骤很详细,重点部分在下面做了标注)  安装部署K8S集群文档: 使用kubeadm方式搭建K8S集群 · GitBook 本机: master:10.0.0.13 master            node1: 10.0.0.11 node1            node2: 10.0.0.12 node2 #systemctl stop firewalldsy

    2024年02月22日
    浏览(39)
  • k8s入门:裸机部署 k8s 集群

    系列文章 第一章:✨ k8s入门:裸机部署 k8s 集群 第二章:✨ k8s入门:部署应用到 k8s 集群 第三章:✨ k8s入门:service 简单使用 第四章:✨ k8s入门:StatefulSet 简单使用 第五章:✨ k8s入门:存储(storage) 第六章:✨ K8S 配置 storageclass 使用 nfs 动态申领本地磁盘空间 第七章:

    2023年04月20日
    浏览(38)
  • K8S搭建NACOS集群踩坑问题

    现象描述:通过K8S的statefulset启动,通过NodePort暴露不能在外网访问,只能在MASTER主节点访问。 yaml配置: 原因分析: 因为我们要将POD固定运行在NODE52这台节点上,所以加上了 nodeName: host-52,但是同时也加上了hostNetwork: true,导致POD已经启动,但是只能在主节点通过28855端口访

    2024年02月09日
    浏览(35)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包