下载项目
git clone https://github.com/nacos-group/nacos-k8s.git
查看项目目录结构
.
|-- README-CN.md
|-- README-ceph.md
|-- README.md
|-- changelog
|-- deploy
| |-- ceph
| | |-- pvc.yaml
| | `-- sc.yaml
| |-- mysql
| | |-- mysql-ceph.yaml
| | |-- mysql-local.yaml
| | `-- mysql-nfs.yaml
| |-- nacos
| | |-- nacos-no-pvc-ingress.yaml
| | |-- nacos-pvc-ceph.yaml
| | |-- nacos-pvc-nfs.yaml
| | |-- nacos-pvc-nfs.yaml.bak
| | `-- nacos-quick-start.yaml
| `-- nfs
| |-- class.yaml
| |-- deployment.yaml
| `-- rbac.yaml
|-- helm
| |-- Chart.yaml
| |-- README.md
| |-- templates
| | |-- NOTES.txt
| | |-- _helpers.tpl
| | |-- configmap.yaml
| | |-- ingress.yaml
| | |-- service.yaml
| | `-- statefulset.yaml
| `-- values.yaml
|-- images
| |-- cluster1.png
| |-- cluster2.png
| |-- cluster3.png
| |-- get_cluster_after.gif
| |-- k8s.gif
| |-- nacos.png
| |-- quickstart.png
| |-- scale.gif
| `-- standalone.png
|-- openshift
| |-- nacos-template.yaml
| `-- readme.md
|-- operator
| |-- Dockerfile
| |-- LICENSE
| |-- Makefile
| |-- PROJECT
| |-- README-CN.md
| |-- README.md
| |-- api
| | `-- v1alpha1
| | |-- groupversion_info.go
| | |-- nacos_types.go
| | `-- zz_generated.deepcopy.go
| |-- chart
| | |-- nacos
| | | |-- Chart.yaml
| | | |-- templates
| | | | |-- NOTES.txt
| | | | |-- _helpers.tpl
| | | | |-- alert.yaml
| | | | |-- nacos.yaml
| | | | `-- servicemonitor.yaml
| | | |-- values-mysql.yaml
| | | `-- values.yaml
| | `-- nacos-operator
| | |-- Chart.yaml
| | |-- crds
| | | `-- crd.yaml
| | |-- nacos-operator-all.yaml
| | |-- templates
| | | |-- NOTES.txt
| | | |-- _helpers.tpl
| | | |-- deployment.yaml
| | | |-- service.yaml
| | | |-- serviceaccount.yaml
| | | `-- tests
| | | `-- test-connection.yaml
| | `-- values.yaml
| |-- config
| | |-- certmanager
| | | |-- certificate.yaml
| | | |-- kustomization.yaml
| | | `-- kustomizeconfig.yaml
| | |-- crd
| | | |-- bases
| | | | `-- nacos.io_nacos.yaml
| | | |-- kustomization.yaml
| | | |-- kustomizeconfig.yaml
| | | `-- patches
| | | |-- cainjection_in_nacos.yaml
| | | `-- webhook_in_nacos.yaml
| | |-- default
| | | |-- kustomization.yaml
| | | |-- manager_auth_proxy_patch.yaml
| | | |-- manager_webhook_patch.yaml
| | | `-- webhookcainjection_patch.yaml
| | |-- manager
| | | |-- kustomization.yaml
| | | `-- manager.yaml
| | |-- prometheus
| | | |-- kustomization.yaml
| | | `-- monitor.yaml
| | |-- rbac
| | | |-- auth_proxy_client_clusterrole.yaml
| | | |-- auth_proxy_role.yaml
| | | |-- auth_proxy_role_binding.yaml
| | | |-- auth_proxy_service.yaml
| | | |-- kustomization.yaml
| | | |-- leader_election_role.yaml
| | | |-- leader_election_role_binding.yaml
| | | |-- nacos_editor_role.yaml
| | | |-- nacos_viewer_role.yaml
| | | |-- role.yaml
| | | `-- role_binding.yaml
| | |-- samples
| | | |-- kustomization.yaml
| | | |-- nacos.yaml
| | | |-- nacos_cluster.yaml
| | | |-- nacos_cluster_mysql.yaml
| | | |-- nacos_config.yaml
| | | |-- nacos_mysql.yaml
| | | |-- nacos_mysql_wrapper.yaml
| | | `-- nacos_volume.yaml
| | |-- scorecard
| | | |-- bases
| | | | `-- config.yaml
| | | |-- kustomization.yaml
| | | `-- patches
| | | |-- basic.config.yaml
| | | `-- olm.config.yaml
| | |-- sql
| | | `-- nacos-mysql.sql
| | `-- webhook
| | |-- kustomization.yaml
| | |-- kustomizeconfig.yaml
| | `-- service.yaml
| |-- controllers
| | |-- nacos_controller.go
| | `-- suite_test.go
| |-- go.mod
| |-- go.sum
| |-- hack
| | `-- boilerplate.go.txt
| |-- main.go
| |-- pkg
| | |-- errors
| | | |-- errors.go
| | | `-- type.go
| | |-- service
| | | |-- k8s
| | | | |-- configmap.go
| | | | |-- job.go
| | | | |-- k8s.go
| | | | |-- service.go
| | | | `-- statefulset.go
| | | |-- nacos
| | | | `-- cluster.go
| | | `-- operator
| | | |-- Check.go
| | | |-- Heal.go
| | | |-- Kind.go
| | | |-- Status.go
| | | `-- operaror.go
| | `-- util
| | |-- contains
| | | `-- contains.go
| | `-- merge
| | |-- api
| | | |-- deployment.go
| | | |-- pod.go
| | | `-- statefulset.go
| | |-- merge.go
| | |-- merge_deployment.go
| | |-- merge_ephemeral_container.go
| | |-- merge_podtemplate_spec.go
| | `-- merge_statefulset.go
| `-- test
| |-- e2e
| | `-- util
| | |-- deployment.go
| | |-- namespace.go
| | |-- pod.go
| | `-- util.go
| `-- func
| `-- main.go
|-- plugin
| |-- Dockerfile
| |-- install.sh
| `-- peer
| |-- on-change.sh
| |-- on-start.sh
| |-- peer-finder
| `-- plugin.sh
`-- quick-startup.sh
我们本次需要部署的文件在此目录下
/nacos-k8s/deploy/nacos
查看配置文件进行调整
cat nacos-pvc-nfs.yaml
# 请阅读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
spec:
publishNotReadyAddresses: true
ports:
- port: 8848
name: server
targetPort: 8848
# 我使用的nacos版本较低,所以需要禁用下面的对口,可以根据使用的版本进行调整,如果是2.0以上可以开启
# - port: 9848
# name: client-rpc
# targetPort: 9848
# - port: 9849
# name: raft-rpc
# targetPort: 9849
## 兼容1.4.x版本的选举端口
# - port: 7848
# name: old-raft-rpc
# targetPort: 7848
clusterIP: None
selector:
app: nacos
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm
data:
# 这里根据外部的数据库信息进行修改
mysql.host: "192.168.1.100"
mysql.db.name: "nacos_config"
mysql.port: "3306"
mysql.user: "nacos"
mysql.password: "nacos"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nacos
spec:
podManagementPolicy: Parallel
serviceName: nacos-headless
replicas: 3
template:
metadata:
labels:
app: nacos
annotations:
pod.alpha.kubernetes.io/initialized: "true"
spec:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- nacos
topologyKey: "kubernetes.io/hostname"
# serviceAccountName: nfs-client-provisioner
initContainers:
- name: peer-finder-plugin-install
image: nacos/nacos-peer-finder-plugin:1.1
imagePullPolicy: Always
volumeMounts:
- mountPath: /home/nacos/plugins/peer-finder
name: data
subPath: peer-finder
containers:
- name: nacos
imagePullPolicy: Always
image: nacos/nacos-server:1.3.2
resources:
requests:
memory: "2Gi"
cpu: "500m"
ports:
- containerPort: 8848
name: client-port
# 这里根据nacos版本进行调整
# - containerPort: 9848
# name: client-rpc
# - containerPort: 9849
# name: raft-rpc
# - containerPort: 7848
# name: old-raft-rpc
env:
- name: NACOS_REPLICAS
value: "3"
- name: SERVICE_NAME
value: "nacos-headless"
- name: DOMAIN_NAME
value: "cluster.local"
- name: POD_NAMESPACE
valueFrom:
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:
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: SPRING_DATASOURCE_PLATFORM
value: "mysql"
- name: NACOS_SERVER_PORT
value: "8848"
- name: NACOS_APPLICATION_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
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
volumeClaimTemplates:
- metadata:
name: data
annotations:
# volume.beta.kubernetes.io/storage-class: "csi-disk"
everest.io/disk-volume-type: SAS
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 20Gi
storageClassName: csi-disk
selector:
matchLabels:
app: nacos
部署发k8s集群
kubectl apply -f nacos-pvc-nfs.yaml
参考文档
https://nacos.io/zh-cn/docs/use-nacos-with-kubernetes.html
网友评论