k8s部署单机版nacos
来源:
https://www.jianshu.com/p/4f69d1b369d1
mysql
安装mysql如下:
- 创建mysql.yml文件如下:
[root@DoM01 nacos]# cat mysql.yaml
apiVersion: v1
kind: ReplicationController
metadata:
name: mysql
namespace: nacos
labels:
name: mysql
spec:
replicas: 1
selector:
name: mysql
template:
metadata:
labels:
name: mysql
spec:
containers:
- name: mysql
image: nacos/nacos-mysql:5.7
ports:
- containerPort: 3306
volumeMounts:
- name: nacos-mysql
mountPath: /var/lib/mysql
env:
- name: MYSQL_ROOT_PASSWORD
value: "40010355"
- name: MYSQL_DATABASE
value: "nacos"
- name: MYSQL_USER
value: "nacos"
- name: MYSQL_PASSWORD
value: "40010300"
- name: TZ
value: Asia/Shanghai
volumes:
- name: nacos-mysql
persistentVolumeClaim:
claimName: nacos-mysql-pvc
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nacos-mysql-pvc
namespace: nacos
spec:
accessModes:
- ReadWriteMany
resources:
requests:
storage: 20Gi
storageClassName: nfs-client
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: nacos
labels:
name: mysql
spec:
ports:
- port: 3306
targetPort: 3306
selector:
name: mysql
- 启动
#kubectl create -f mysql.yml
- 查看结果
root@DoM01 nacos]# kubectl get pod -n nacos
NAME READY STATUS RESTARTS AGE
mysql-lckvh 1/1 Running 0 40h
[root@DoM01 nacos]# kubectl get service -n nacos
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mysql ClusterIP 10.1.189.109 <none> 3306/TCP 40h
nacos-standalone
- 创建nacos-stand.yaml文件如下
---
apiVersion: v1
kind: Service
metadata:
name: nacos
namespace: nacos
labels:
app: nacos
spec:
type: NodePort
ports:
- port: 8848
name: server
targetPort: 8848
nodePort: 30018
- port: 7848
name: rpc
targetPort: 7848
nodePort: 30019
selector:
app: nacos
---
apiVersion: v1
kind: Service
metadata:
name: nacos-headless
namespace: nacos
labels:
app: nacos
spec:
ports:
- port: 8848
name: server
targetPort: 8848
- port: 7848
name: rpc
targetPort: 7848
clusterIP: None
selector:
app: nacos
---
# 链接mysql数据库
apiVersion: v1
kind: ConfigMap
metadata:
name: nacos-cm
namespace: nacos
data:
mysql.db.name: "nacos"
mysql.port: "3306"
mysql.user: "nacos"
mysql.password: "40010355"
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nacos
namespace: nacos
spec:
serviceName: nacos-headless
replicas: 1
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: nacos
imagePullPolicy: Always
image: nacos/nacos-server:latest
resources:
requests:
memory: "2Gi"
cpu: "500m"
ports:
- containerPort: 8848
name: client-port
- containerPort: 7848
name: rpc
env:
- name: NACOS_REPLICAS
value: "1"
- name: MYSQL_SERVICE_DB_NAME
valueFrom:
configMapKeyRef:
name: nacos-cm
key: mysql.db.name
- name: MYSQL_SERVICE_PORT
valueFrom:
configMapKeyRef:
name