Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
paderlol authored Aug 2, 2024
2 parents 1785edf + 3c73f20 commit 3198a6a
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 43 deletions.
1 change: 1 addition & 0 deletions .github/workflows/operator-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ jobs:
with:
context: operator
file: operator/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
4 changes: 3 additions & 1 deletion README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ mysql-gf2vd 1/1 Running 0 111m
```
## 执行数据库初始化语句

数据库初始化语句位置 <https://github.com/alibaba/nacos/blob/develop/distribution/conf/nacos-mysql.sql>
数据库初始化语句位置 <https://github.com/alibaba/nacos/blob/develop/distribution/conf/mysql-schema.sql>



Expand All @@ -155,6 +155,7 @@ mysql-gf2vd 1/1 Running 0 111m

```yaml
data:
mysql.host: "数据库地址"
mysql.db.name: "数据库名称"
mysql.port: "端口"
mysql.user: "用户名"
Expand Down Expand Up @@ -281,6 +282,7 @@ for i in 0 1 2; do echo nacos-$i; kubectl exec nacos-$i curl GET "http://localho
| mysql.port | N | 端口 |
| mysql.user | Y | 用户名 |
| mysql.password | Y | 密码 |
| SPRING_DATASOURCE_PLATFORM | Y | 数据库类型,默认embedded嵌入式数据库,参数只支持mysql或embedded |
| NACOS_REPLICAS | N | 确定执行Nacos启动节点数量,如果不适用动态扩容插件,就必须配置这个属性,否则使用扩容插件后不会生效 |
| NACOS_SERVER_PORT | N | Nacos 端口 为peer_finder插件提供端口 |
| NACOS_APPLICATION_PORT | N | Nacos 端口 |
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ chmod +x quick-startup.sh

## 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>
<https://github.com/alibaba/nacos/blob/develop/distribution/conf/mysql-schema.sql>


> In advanced use, the cluster is automatically scaled and data is persisted, but [PersistentVolumeClaims](https://kubernetes.io/docs/concepts/storage/persistent-volumes/#persistentvolumeclaims) must be deployed. In this example, NFS is used.
Expand Down Expand Up @@ -165,6 +165,7 @@ mysql-gf2vd 1/1 Running 0 111m

```yaml
data:
mysql.host: "db host"
mysql.db.name: "db name"
mysql.port: " db port"
mysql.user: " db username"
Expand Down Expand Up @@ -284,6 +285,7 @@ You can find that the new node has joined the cluster
| mysql.port | N | database port |
| mysql.user | Y | database username |
| mysql.password | Y | database password |
| SPRING_DATASOURCE_PLATFORM | Y | Database type,The default is embedded database,parameters only support mysql or embedded |
| NACOS_REPLICAS | Y | The number of clusters must be consistent with the value of the replicas attribute |
| NACOS_SERVER_PORT | N | Nacos port,default:8848 for Peer-finder plugin |
| NACOS_APPLICATION_PORT | N | Nacos port, default:8848 |
Expand Down
23 changes: 12 additions & 11 deletions deploy/nacos/nacos-no-pvc-ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ kind: ConfigMap
metadata:
name: nacos-cm
data:
mysql.host: "10.127.1.12"
mysql.host: "mysql"
mysql.db.name: "nacos_devtest"
mysql.port: "3306"
mysql.user: "nacos"
mysql.password: "passwd"
mysql.password: "nacos"
---
apiVersion: apps/v1
kind: StatefulSet
Expand All @@ -62,7 +62,7 @@ spec:
- nacos
topologyKey: "kubernetes.io/hostname"
containers:
- name: k8snacos
- name: nacos
imagePullPolicy: Always
image: nacos/nacos-server:latest
resources:
Expand Down Expand Up @@ -106,14 +106,14 @@ spec:
configMapKeyRef:
name: nacos-cm
key: mysql.password
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: MODE
value: "cluster"
- name: NACOS_SERVER_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: NACOS_SERVERS
value: "nacos-0.nacos-headless.default.svc.cluster.local:8848 nacos-1.nacos-headless.default.svc.cluster.local:8848 nacos-2.nacos-headless.default.svc.cluster.local:8848"
selector:
Expand All @@ -125,18 +125,19 @@ spec:

---
# ------------------- App Ingress ------------------- #
apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nacos-headless
namespace: default

spec:
rules:
- host: nacos-web.nacos-demo.com
http:
paths:
- path: /
- path: /nacos
pathType: Prefix
backend:
serviceName: nacos-headless
servicePort: server
service:
name: nacos-headless
port:
name: server
14 changes: 10 additions & 4 deletions deploy/nacos/nacos-pvc-ceph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ metadata:
name: nacos-headless
labels:
app: nacos
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
publishNotReadyAddresses: true
ports:
- port: 8848
name: server
Expand All @@ -31,6 +30,7 @@ kind: ConfigMap
metadata:
name: nacos-cm
data:
mysql.host: "mysql"
mysql.db.name: "nacos_devtest"
mysql.port: "3306"
mysql.user: "nacos"
Expand All @@ -41,6 +41,7 @@ kind: StatefulSet
metadata:
name: nacos
spec:
podManagementPolicy: Parallel
serviceName: nacos-headless
replicas: 3
template:
Expand Down Expand Up @@ -98,6 +99,11 @@ spec:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: MYSQL_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.host
- name: MYSQL_SERVICE_DB_NAME
valueFrom:
configMapKeyRef:
Expand All @@ -118,12 +124,12 @@ spec:
configMapKeyRef:
name: nacos-cm
key: mysql.password
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: NACOS_SERVER_PORT
value: "8848"
- name: NACOS_APPLICATION_PORT
value: "8848"
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: PREFER_HOST_MODE
value: "hostname"
volumeMounts:
Expand Down
16 changes: 12 additions & 4 deletions deploy/nacos/nacos-pvc-nfs.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# 请阅读Wiki文章
# https://github.com/nacos-group/nacos-k8s/wiki/%E4%BD%BF%E7%94%A8peerfinder%E6%89%A9%E5%AE%B9%E6%8F%92%E4%BB%B6
---
apiVersion: v1
kind: Service
metadata:
name: nacos-headless
labels:
app: nacos
annotations:
service.alpha.kubernetes.io/tolerate-unready-endpoints: "true"
spec:
publishNotReadyAddresses: true
ports:
- port: 8848
name: server
Expand All @@ -31,6 +32,7 @@ kind: ConfigMap
metadata:
name: nacos-cm
data:
mysql.host: "mysql"
mysql.db.name: "nacos_devtest"
mysql.port: "3306"
mysql.user: "nacos"
Expand All @@ -41,6 +43,7 @@ kind: StatefulSet
metadata:
name: nacos
spec:
podManagementPolicy: Parallel
serviceName: nacos-headless
replicas: 3
template:
Expand Down Expand Up @@ -98,6 +101,11 @@ spec:
fieldRef:
apiVersion: v1
fieldPath: metadata.namespace
- name: MYSQL_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.host
- name: MYSQL_SERVICE_DB_NAME
valueFrom:
configMapKeyRef:
Expand All @@ -118,14 +126,14 @@ spec:
configMapKeyRef:
name: nacos-cm
key: mysql.password
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: NACOS_SERVER_PORT
value: "8848"
- name: NACOS_APPLICATION_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
volumeMounts:
- name: data
mountPath: /home/nacos/plugins/peer-finder
Expand Down
12 changes: 9 additions & 3 deletions deploy/nacos/nacos-quick-start.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ kind: ConfigMap
metadata:
name: nacos-cm
data:
mysql.host: "mysql"
mysql.db.name: "nacos_devtest"
mysql.port: "3306"
mysql.user: "nacos"
Expand Down Expand Up @@ -60,7 +61,7 @@ spec:
- nacos
topologyKey: "kubernetes.io/hostname"
containers:
- name: k8snacos
- name: nacos
imagePullPolicy: Always
image: nacos/nacos-server:latest
resources:
Expand All @@ -79,6 +80,11 @@ spec:
env:
- name: NACOS_REPLICAS
value: "3"
- name: MYSQL_SERVICE_HOST
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.host
- name: MYSQL_SERVICE_DB_NAME
valueFrom:
configMapKeyRef:
Expand All @@ -99,14 +105,14 @@ spec:
configMapKeyRef:
name: nacos-cm
key: mysql.password
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: NACOS_SERVER_PORT
value: "8848"
- name: NACOS_APPLICATION_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
- name: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: NACOS_SERVERS
value: "nacos-0.nacos-headless.default.svc.cluster.local:8848 nacos-1.nacos-headless.default.svc.cluster.local:8848 nacos-2.nacos-headless.default.svc.cluster.local:8848"
selector:
Expand Down
3 changes: 3 additions & 0 deletions helm/templates/ingress.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ spec:
secretName: {{ .secretName }}
{{- end }}
{{- end }}
{{- if .Values.ingress.ingressClassName }}
ingressClassName: {{ .Values.ingress.ingressClassName }}
{{- end }}
{{- if eq .Values.ingress.apiVersion "networking.k8s.io/v1" }}
rules:
{{- range .Values.ingress.hosts }}
Expand Down
2 changes: 1 addition & 1 deletion helm/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ spec:
initContainers:
- name: peer-finder-plugin-install
image: {{.Values.nacos.plugin.image.repository}}:{{.Values.nacos.plugin.image.tag}}
imagePullPolicy: Always
imagePullPolicy: {{ .Values.nacos.plugin.image.pullPolicy }}
volumeMounts:
- mountPath: /home/nacos/plugins/peer-finder
name: data
Expand Down
11 changes: 8 additions & 3 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ nacos:
image:
repository: nacos/nacos-peer-finder-plugin
tag: 1.1
pullPolicy: IfNotPresent
replicaCount: 1
podManagementPolicy: Parallel
domainName: cluster.local
Expand Down Expand Up @@ -56,11 +57,15 @@ service:

ingress:
enabled: false
#apiVersion: networking.k8s.io/v1
apiVersion: extensions/v1beta1
# apiVersion: extensions/v1beta1
apiVersion: networking.k8s.io/v1
annotations: { }
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
# 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: [ ]
Expand Down
4 changes: 3 additions & 1 deletion operator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Build the manager binary

FROM golang:1.16 AS builder
ARG TARGETARCH

WORKDIR /workspace
# Copy the Go Modules manifests
Expand All @@ -18,7 +20,7 @@ COPY pkg/ pkg/
ADD https://raw.githubusercontent.com/alibaba/nacos/develop/distribution/conf/mysql-schema.sql config/sql/nacos-mysql.sql

# Build
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -v -o manager main.go
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on go build -a -v -o manager main.go

# Use distroless as minimal base image to package the manager binary
# Refer to https://github.com/GoogleContainerTools/distroless for more details
Expand Down
4 changes: 2 additions & 2 deletions operator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ ifeq (, $(shell which controller-gen))
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.2 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
Expand All @@ -107,7 +107,7 @@ ifeq (, $(shell which kustomize))
KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$KUSTOMIZE_GEN_TMP_DIR ;\
go mod init tmp ;\
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
go get sigs.k8s.io/kustomize/kustomize/[email protected] ;\
rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\
}
KUSTOMIZE=$(GOBIN)/kustomize
Expand Down
16 changes: 13 additions & 3 deletions operator/api/v1alpha1/nacos_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,25 @@ type NacosSpec struct {

// 自定义配置
// 部署模式
Type string `json:"type,omitempty"`
Database Database `json:"database,omitempty"`
Volume Storage `json:"volume,omitempty"`
Type string `json:"type,omitempty"`
FunctionMode string `json:"function_mode,omitempty"`
Database Database `json:"database,omitempty"`
Volume Storage `json:"volume,omitempty"`
// 配置文件
Config string `json:"config,omitempty"`
// 开启认证
Certification Certification `json:"certification,omitempty"`
// 通用k8s配置包装器
K8sWrapper K8sWrapper `json:"k8sWrapper,omitempty"`
}

type Certification struct {
Enabled bool `json:"enabled,omitempty"`
Token string `json:"token,omitempty"`
TokenExpireSeconds string `json:"token_expire_seconds,omitempty"`
CacheEnabled bool `json:"cache_enabled,omitempty"`
}

type K8sWrapper struct {
PodSpec PodSpecWrapper `json:"PodSpec,omitempty"`
}
Expand Down
Loading

0 comments on commit 3198a6a

Please sign in to comment.