This commit is contained in:
marsal wang
2023-07-26 10:07:34 +08:00
parent f884cb1020
commit 1e5a703cce
5384 changed files with 618283 additions and 4002 deletions

22
helm/nacos/.helmignore Normal file
View File

@ -0,0 +1,22 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/

9
helm/nacos/Chart.yaml Normal file
View File

@ -0,0 +1,9 @@
apiVersion: v1
appVersion: "1.0"
description: A Helm chart for Kubernetes
name: nacos
version: 0.1.5
maintainers:
- name: arrowfeng
- name: paderlol

137
helm/nacos/README.md Normal file
View File

@ -0,0 +1,137 @@
# Nacos Helm Chart
Nacos is committed to help you discover, configure, and manage your microservices. It provides a set of simple and useful features enabling you to realize dynamic service discovery, service configuration, service metadata and traffic management.
## Introduction
This project is based on the Helm Chart packaged by [nacos-k8s](https://github.com/nacos-group/nacos-k8s/).
## Prerequisites
- Kubernetes 1.10+
- Helm v3
- PV provisioner support in the underlying infrastructure
## Tips
If you use a custom database, please initialize the database script yourself first.
<https://github.com/alibaba/nacos/blob/develop/distribution/conf/nacos-mysql.sql>
## Installing the Chart
To install the chart with `release name`:
```shell
$ helm install `release name` ./nacos
```
The command deploys Nacos on the Kubernetes cluster in the default configuration. It will run without a mysql chart and persistent volume. The [configuration](#configuration) section lists the parameters that can be configured during installation.
### Service & Configuration Management
#### Service registration
```shell
curl -X POST 'http://$NODE_IP:$NODE_PORT/nacos/v1/ns/instance?serviceName=nacos.naming.serviceName&ip=20.18.7.10&port=8080'
```
#### Service discovery
```shell
curl -X GET 'http://$NODE_IP:$NODE_PORT/nacos/v1/ns/instance/list?serviceName=nacos.naming.serviceName'
```
#### Publish config
```shell
curl -X POST "http://$NODE_IP:$NODE_PORT/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test&content=helloWorld"
```
#### Get config
```shell
curl -X GET "http://$NODE_IP:$NODE_PORT/nacos/v1/cs/configs?dataId=nacos.cfg.dataId&group=test"
```
> **Tip**: List all releases using `helm list`
## Uninstalling the Chart
To uninstall/delete `release name`:
```shell
$ helm uninstall `release name`
```
The command removes all the Kubernetes components associated with the chart and deletes the release.
## Configuration
The following table lists the configurable parameters of the Skywalking chart and their default values.
| Parameter | Description | Default |
|---------------------------------------|--------------------------------------------------------------------|-------------------------------------|
| `global.mode` | Run Mode (~~quickstart,~~ standalone, cluster; ) | `standalone` |
| `resources` | The [resources] to allocate for nacos container | `{}` |
| `nodeSelector` | Nacos labels for pod assignment | `{}` |
| `affinity` | Nacos affinity policy | `{}` |
| `tolerations` | Nacos tolerations | `{}` |
| `resources.requests.cpu`|nacos requests cpu resource|`500m`|
| `resources.requests.memory`|nacos requests memory resource|`2G`|
| `nacos.replicaCount` | Number of desired nacos pods, the number should be 1 as run standalone mode| `1` |
| `nacos.image.repository` | Nacos container image name | `nacos/nacos-server` |
| `nacos.image.tag` | Nacos container image tag | `latest` |
| `nacos.image.pullPolicy` | Nacos container image pull policy | `IfNotPresent` |
| `nacos.plugin.enable` | Nacos cluster plugin that is auto scale | `true` |
| `nacos.plugin.image.repository` | Nacos cluster plugin image name | `nacos/nacos-peer-finder-plugin` |
| `nacos.plugin.image.tag` | Nacos cluster plugin image tag | `1.1` |
| `nacos.health.enabled` | Enable health check or not | `false` |
| `nacos.env.preferhostmode` | Enable Nacos cluster node domain name support | `hostname` |
| `nacos.env.serverPort` | Nacos port | `8848` |
| `nacos.storage.type` | Nacos data storage method `mysql` or `embedded`. The `embedded` supports either standalone or cluster mode | `embedded` |
| `nacos.storage.db.host` | mysql host | |
| `nacos.storage.db.name` | mysql database name | |
| `nacos.storage.db.port` | mysql port | 3306 |
| `nacos.storage.db.username` | username of database | |
| `nacos.storage.db.password` | password of database | |
| `nacos.storage.db.param` | Database url parameter | `characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false` |
| `persistence.enabled` | Enable the nacos data persistence or not | `false` |
| `persistence.data.accessModes` | Nacos data pvc access mode | `ReadWriteOnce` |
| `persistence.data.storageClassName` | Nacos data pvc storage class name | `manual` |
| `persistence.data.resources.requests.storage` | Nacos data pvc requests storage | `5G` |
| `service.type` | http service type | `NodePort` |
| `service.port` | http service port | `8848` |
| `service.nodePort` | http service nodeport | `30000` |
| `ingress.enabled` | Enable ingress or not | `false` |
| `ingress.annotations` | The annotations used in ingress | `{}` |
| `ingress.hosts` | The host of nacos service in ingress rule | `nacos.example.com` |
## Example
![img](../images/nacos.png)
#### standalone mode(with embedded)
```console
$ helm install `release name` ./ --set global.mode=standalone
```
![img](../images/quickstart.png)
#### standalone mode(with mysql)
```console
$ helm install `release name` ./ --set global.mode=standalone --set nacos.storage.db.host=host --set nacos.storage.
db.name=dbName --set nacos.storage.db.port=port --set nacos.storage.db.username=username --set nacos.storage.db.
password=password
```
![img](../images/standalone.png)
> **Tip**: if the logs of nacos pod throws exception, you may need to delete the pod. Because mysql pod is not ready, nacos pod has been started.
#### cluster mode(without pv)
```console
$ helm install `release name` ./ --set global.mode=cluster
```
![img](../images/cluster1.png)
```console
$ kubectl scale sts `release name`-nacos --replicas=3
```
![img](../images/cluster2.png)
* Use kubectl exec to get the cluster config of the Pods in the nacos StatefulSet after scale StatefulSets
![img](../images/cluster3.png)

Binary file not shown.

View File

@ -0,0 +1,25 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ . }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services nacos-cs)
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT/nacos
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "nacos.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "nacos.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "nacos.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl port-forward $POD_NAME 8080:80
{{- end }}
2. MODE:
standalone: you need to modify replicaCount in the values.yaml, .Values.replicaCount=1
cluster: kubectl scale sts {{ .Release.Namespace }}-nacos --replicas=3

View File

@ -0,0 +1,45 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "nacos.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "nacos.fullname" -}}
{{- if .Values.fullnameOverride -}}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- if contains $name .Release.Name -}}
{{- .Release.Name | trunc 63 | trimSuffix "-" -}}
{{- else -}}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "nacos.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
{{- end -}}
{{/*
Common labels
*/}}
{{- define "nacos.labels" -}}
app.kubernetes.io/name: {{ include "nacos.name" . }}
helm.sh/chart: {{ include "nacos.chart" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end -}}

View File

@ -0,0 +1,18 @@
{{- if eq .Values.nacos.storage.type "mysql"}}
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm
data:
{{- with .Values.nacos.storage.db }}
mysql.db.host: {{.host}}
mysql.db.name: {{ .name }}
mysql.port: "{{ .port | default 3306}}"
mysql.user: {{ .username }}
mysql.password: {{ .password }}
mysql.param: {{ .param | default "characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false" }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,149 @@
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: {{ include "nacos.fullname" . }}
annotations:
{{- toYaml .Values.annotations | indent 4 }}
spec:
{{- if eq .Values.global.mode "cluster" }}
serviceName: nacos-hs
{{- else }}
serviceName: nacos-cs
{{- end }}
replicas: {{ .Values.nacos.replicaCount }}
selector:
matchLabels:
app.kubernetes.io/name: {{ include "nacos.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
template:
metadata:
labels:
app.kubernetes.io/name: {{ include "nacos.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
spec:
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if and (eq .Values.global.mode "cluster") (.Values.nacos.plugin.enable) }}
initContainers:
- name: peer-finder-plugin-install
image: {{.Values.nacos.plugin.image.repository}}:{{.Values.nacos.plugin.image.tag}}
imagePullPolicy: Always
volumeMounts:
- mountPath: /home/nacos/plugins/peer-finder
name: data
subPath: peer-finder
{{- end }}
containers:
- name: {{ .Chart.Name }}
image: "{{ .Values.nacos.image.repository }}:{{ .Values.nacos.image.tag }}"
imagePullPolicy: {{ .Values.nacos.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.nacos.serverPort }}
protocol: TCP
- containerPort: {{ add .Values.nacos.serverPort 1000}}
name: client-rpc
- containerPort: {{ add .Values.nacos.serverPort 1001 }}
name: raft-rpc
- containerPort: 7848
name: old-raft-rpc
resources:
{{- toYaml .Values.resources | nindent 12 }}
env:
- name: NACOS_SERVER_PORT
value: {{ .Values.nacos.serverPort | quote }}
- name: NACOS_APPLICATION_PORT
value: {{ .Values.nacos.serverPort | quote }}
- name: PREFER_HOST_MODE
value: {{ .Values.nacos.preferhostmode | quote }}
{{- if eq .Values.global.mode "standalone" }}
- name: MODE
value: "standalone"
{{- else if eq .Values.global.mode "cluster" }}
- name: SERVICE_NAME
value: "nacos-hs"
- name: DOMAIN_NAME
value: {{ .Values.nacos.domainName | quote }}
- name: POD_NAMESPACE
valueFrom:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
{{- end }}
{{- if eq .Values.nacos.storage.type "mysql" }}
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: MYSQL_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.db.host
- name: MYSQL_SERVICE_DB_NAME
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.db.name
- 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: MYSQL_SERVICE_DB_PARAM
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.param
{{else}}
- name: EMBEDDED_STORAGE
value: embedded
{{end}}
livenessProbe:
tcpSocket:
port: {{ .Values.nacos.serverPort }}
readinessProbe:
tcpSocket:
port: {{ .Values.nacos.serverPort }}
volumeMounts:
- name: data
mountPath: /home/nacos/plugins/peer-finder
subPath: peer-finder
- name: data
mountPath: /home/nacos/data
subPath: data
- name: data
mountPath: /home/nacos/logs
subPath: logs
{{- if not .Values.persistence.enabled }}
volumes:
- name: data
emptyDir: { }
{{- end }}
{{- if .Values.persistence.enabled }}
volumeClaimTemplates:
- metadata:
name: data
spec:
{{- toYaml .Values.persistence.data | nindent 8 }}
{{- end }}

View File

@ -0,0 +1,36 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "nacos.fullname" . -}}
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{ include "nacos.labels" . | indent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
{{- if .Values.ingress.tls }}
tls:
{{- range .Values.ingress.tls }}
- hosts:
{{- range .hosts }}
- {{ . | quote }}
{{- end }}
secretName: {{ .secretName }}
{{- end }}
{{- end }}
rules:
{{- range .Values.ingress.hosts }}
- host: {{ .host | quote }}
http:
paths:
{{- range .paths }}
- path: {{ . }}
backend:
serviceName: nacos-cs
servicePort: http
{{- end }}
{{- end }}
{{- end }}

View File

@ -0,0 +1,62 @@
{{- if and (eq .Values.global.mode "cluster") }}
apiVersion: v1
kind: Service
metadata:
name: {{ include "nacos.fullname" . }}
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
clusterIP: None
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.nacos.serverPort }}
protocol: TCP
name: http
- port: {{ add .Values.service.port 1000}}
name: client-rpc
targetPort: {{add .Values.nacos.serverPort 1000}}
- port: {{add .Values.service.port 1001}}
name: raft-rpc
targetPort: {{add .Values.nacos.serverPort 1001}}
## 兼容1.4.x版本的选举端口
- port: 7848
name: old-raft-rpc
targetPort: 7848
protocol: TCP
selector:
app.kubernetes.io/name: {{ include "nacos.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
---
apiVersion: v1
kind: Service
metadata:
name: nacos-cs
labels:
{{- toYaml .Values.service.labels | nindent 4 }}
annotations:
{{- toYaml .Values.service.annotations | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{ .Values.nacos.serverPort }}
protocol: TCP
name: http
- port: {{ add .Values.service.port 1000}}
name: client-rpc
targetPort: {{add .Values.nacos.serverPort 1000}}
- port: {{add .Values.service.port 1001}}
name: raft-rpc
targetPort: {{add .Values.nacos.serverPort 1001}}
## 兼容1.4.x版本的选举端口
- port: 7848
name: old-raft-rpc
targetPort: 7848
protocol: TCP
{{- if eq .Values.service.type "NodePort" }}
nodePort: {{ .Values.service.nodePort }}
{{- end }}
selector:
app.kubernetes.io/name: {{ include "nacos.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}

89
helm/nacos/values.yaml Normal file
View File

@ -0,0 +1,89 @@
# Default values for nacos.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
global:
mode: standalone
# mode: cluster
############################nacos###########################
nacos:
image:
repository: nacos/nacos-server
tag: latest
pullPolicy: IfNotPresent
plugin:
enable: true
image:
repository: nacos/nacos-peer-finder-plugin
tag: 1.1
replicaCount: 1
domainName: cluster.local
preferhostmode: hostname
serverPort: 8848
health:
enabled: false
storage:
type: embedded
# type: mysql
# db:
# host: localhost
# name: nacos
# port: 3306
# username: usernmae
# password: password
# param: characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
persistence:
enabled: false
data:
accessModes:
- ReadWriteOnce
storageClassName: manual
resources:
requests:
storage: 5Gi
service:
#type: ClusterIP
type: NodePort
port: 8848
nodePort: 30000
ingress:
enabled: false
annotations: { }
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
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: { }