一、下载
# github地址:
https://github.com/nacos-group/nacos-k8s
https://github.com/nacos-group/nacos-k8s/blob/master/operator/README-CN.md
# mkdir nacos-cluster
# cd nacos-cluster/
# git clone https://github.com/nacos-group/nacos-k8s.git
# pwd
/opt/k8s/nacos-cluster/nacos-cluster/nacos-k8s/helm
# kubectl create ns nacos
## 修改values文件
# cat values.yaml
# Default values for nacos.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
global:
# mode: standalone
mode: cluster
############################nacos###########################
namespace: nacos
nacos:
image:
repository: 192.168.2.51/caclico/nacos
tag: v2.2.3
pullPolicy: IfNotPresent
plugin:
enable: true
image:
repository: 192.168.2.51/caclico/nacos-peer-finder-plugin
tag: 1.1
pullPolicy: IfNotPresent
replicaCount: 3
podManagementPolicy: Parallel
domainName: cluster.local
preferhostmode: hostname
serverPort: 8848
health:
enabled: false
storage:
# type: embedded
type: mysql
db:
host: mysql.mysql.svc.cluster.local
name: nacos_config
port: 3306
username: nacos
password: SnbZB61kcbzCy5
param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&allowPublicKeyRetrieval=true&autoReconnect=true&useSSL=false
persistence:
enabled: true
data:
accessModes:
- ReadWriteOnce
storageClassName: nfs-storage
resources:
requests:
storage: 10Gi
service:
#type: ClusterIP
type: NodePort
port: 8848
nodePort: 30000
ingress:
enabled: false
# apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
annotations: { }
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
# For Kubernetes >= 1.18 you should specify the ingress-controller via the field ingressClassName
# See https://kubernetes.io/blog/2020/04/02/improvements-to-the-ingress-api-in-kubernetes-1.18/#specifying-the-class-of-an-ingress
# ingressClassName: nginx
ingressClassName: "nginx"
hosts:
- host: nacos.example.com
#paths: [ ]
tls: [ ]
# - secretName: chart-example-tls
# hosts:
# - chart-example.local
resources:
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
requests:
cpu: 500m
memory: 2Gi
annotations: { }
nodeSelector: { }
tolerations: [ ]
affinity: { }
## 在statefulset.yaml中添加下面四个变量
# vi templates/statefulset.yaml
- name: NACOS_AUTH_ENABLE
value: "true"
- name: NACOS_AUTH_TOKEN
value: "WlhFZ0xsWmhiSFZsY3k1dVlXTnZjeTV6ZEc5eVlXZGxMblI1Y0dVPQ=="
- name: NACOS_AUTH_IDENTITY_KEY
value: "nacos"
- name: NACOS_AUTH_IDENTITY_VALUE
value: "nacos"
## 运行
# helm install nacos . -f values.yaml
二、修改values.yaml文件:
注意:
此处镜像为都是手动下载好传入私有仓库的。
三、修改templates/statefulset.yaml
注意:
此处是开启的登录验证。
NACOS_AUTH_TOKEN: #设置一个大于32位的字符串作为Token密钥,并进行Base64编码。工具可用:Base64 编码/解码 - 锤子在线工具
NACOS_AUTH_IDENTITY_KEY: # 账户
NACOS_AUTH_IDENTITY_VALUE: #密码
四、检查:
五、参考
https://nacos.io/blog/faq/nacos-user-question-history13480/
https://nacos.io/docs/latest/manual/admin/system-configurations/
#base64在线编码
https://www.toolhelper.cn/EncodeDecode/Base64