k8s部署nacos(基于现有的mysql)单节点/集群 模式
一、确定nacos需要使用的mysql信息,后面会用到二、nacos镜像版本2.0.3,nacos/nacos-server:2.0.3上yaml# cat nacos-StatefulSet.yaml---apiVersion: v1kind: Servicemetadata:name: nacoslabels:app: nacosspec:selector:app: nacosexternal
一、确定nacos需要使用的mysql信息,后面会用到
二、nacos镜像版本2.0.3,nacos/nacos-server:2.0.3
上yaml
# cat nacos-StatefulSet.yaml
---
apiVersion: v1
kind: Service
metadata:
name: nacos
labels:
app: nacos
spec:
selector:
app: nacos
externalTrafficPolicy: Cluster
ports:
- name: nacos-service-0
targetPort: 8848
nodePort: 30003
port: 8848
protocol: TCP
type: NodePort
---
apiVersion: v1
kind: Service
metadata:
name: nacos-headless
labels:
app: nacos-headless
spec:
type: ClusterIP
clusterIP: None
ports:
- port: 8848
name: server
targetPort: 8848
- port: 9848
name: client-rpc
targetPort: 9848
- port: 9849
name: raft-rpc
targetPort: 9849
- port: 7848
name: old-raft-rpc
targetPort: 7848
selector:
app: nacos
---
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm #这里下面会用到
data:
mysql.service.name: "10.8.16.11" #增加数据库地址变量,这里填写第二步创建的service名字.
mysql.db.name: "db_nacos" #数据库名字
mysql.port: "3306" #数据库端口
mysql.user: "root" #数据库用户名
mysql.password: "123456" #数据库密码
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nacos
spec:
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"
containers:
- name: k8snacos
imagePullPolicy: IfNotPresent
image: "nacos/nacos-server:2.0.3"
resources:
requests:
memory: "2Gi"
cpu: "500m"
ports:
- containerPort: 8848
name: client
- containerPort: 9848
name: client-rpc
- containerPort: 9849
name: raft-rpc
- containerPort: 7848
name: old-raft-rpc
env:
- name: NACOS_REPLICAS
value: "3"
- name: MYSQL_SERVICE_HOST #添加的数据库地址环境变量,无需修改.
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.service.name
- 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: NACOS_SERVER_PORT
value: "8848"
- name: NACOS_APPLICATION_PORT
value: "8848"
- name: PREFER_HOST_MODE
value: "hostname"
- 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" #这里中间的default,需要根据实际的命名空间修改,默认default命名空间
selector:
matchLabels:
app: nacos
kubectl apply -f nacos-StatefulSet.yaml
三、访问登录
http://hostIP:30003/nacos
用户密码:nacos/nacos
更多推荐
所有评论(0)