k8s部署nacos集群(外接mysql数据库)
nacos集群部署
·
1.首先部署mysql
version: "3"
services:
mysql:
restart: always
container_name: mysql
image: 'nacos/nacos-mysql:5.7' #使用的镜像
restart: always
volumes:
- ${PWD}/mysql/mysql:/var/lib/mysql #挂载目录,持久化存储
- /etc/localtime:/etc/localtime:ro
ports:
- '3306:3306'
environment:
TZ: Asia/Shanghai
MYSQL_ROOT_PASSWORD: ****** #设置root用户的密码
user: root
2.创建nacos名称空间
kubectl create ns nacos
#cat nacos.yaml
---
kind: StatefulSet
apiVersion: apps/v1
metadata:
name: nacos
namespace: nacos
labels:
k8s.kuboard.cn/name: nacos
spec:
replicas: 3
selector:
matchLabels:
app: nacos
template:
metadata:
creationTimestamp: null
labels:
app: nacos
annotations:
pod.alpha.kubernetes.io/initialized: 'true'
spec:
containers:
- name: k8snacos
image: 'nacos/nacos-server:1.4.2'
ports:
- name: client
containerPort: 8848
protocol: TCP
- name: client-rpc
containerPort: 9848
protocol: TCP
- name: raft-rpc
containerPort: 9849
protocol: TCP
- name: old-raft-rpc
containerPort: 7848
protocol: TCP
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:
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: MODE
value: cluster
- name: NACOS_SERVER_PORT
value: '8848'
- name: PREFER_HOST_MODE
value: hostname
- name: MYSQL_SERVICE_DB_PARAM
value: >-
characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false
- name: NACOS_SERVERS
value: >-
nacos-0.nacos-headless.nacos.svc.cluster.local:8848
nacos-1.nacos-headless.nacos.svc.cluster.local:8848
nacos-2.nacos-headless.nacos.svc.cluster.local:8848
resources:
limits:
memory: 1Gi
requests:
cpu: 500m
memory: 512Mi
terminationMessagePath: /dev/termination-log
terminationMessagePolicy: File
imagePullPolicy: IfNotPresent
restartPolicy: Always
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
securityContext: {}
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- nacos
topologyKey: kubernetes.io/hostname
schedulerName: default-scheduler
serviceName: nacos-headless
podManagementPolicy: OrderedReady
updateStrategy:
type: RollingUpdate
rollingUpdate:
partition: 0
revisionHistoryLimit: 10
---
kind: Service
apiVersion: v1
metadata:
name: nacos-headless
namespace: nacos
labels:
app: nacos-headless
spec:
ports:
- name: server
protocol: TCP
port: 8848
targetPort: 8848
- name: client-rpc
protocol: TCP
port: 9848
targetPort: 9848
- name: raft-rpc
protocol: TCP
port: 9849
targetPort: 9849
- name: old-raft-rpc
protocol: TCP
port: 7848
targetPort: 7848
selector:
app: nacos
clusterIP: None
clusterIPs:
- None
type: ClusterIP
sessionAffinity: None
---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
name: nacos
namespace: nacos
labels:
k8s.kuboard.cn/name: nacos
spec:
ingressClassName: nginx
rules:
- host: nacos-dev.sisensing.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: nacos-headless
port:
number: 8848
---
kind: ConfigMap
apiVersion: v1
metadata:
name: nacos-cm
namespace: nacos
data:
mysql.db.name: nacos_devtest
mysql.host: 192.168.100.117
mysql.password: ******
mysql.port: '3306'
mysql.user: nacos
直接访问即可
更多推荐
已为社区贡献2条内容
所有评论(0)