K8S单机版nacos
作者:互联网
1.创建命名空间
[root@k8s-matser01 ~]# kubectl create ns nacos
2.编辑mysql的yaml文件
[root@k8s-matser01 ~]# 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
hostPath:
path: /data/mysql
type: DirectoryOrCreate
---
apiVersion: v1
kind: Service
metadata:
name: mysql
namespace: nacos
labels:
name: mysql
spec:
ports:
- port: 3306
targetPort: 3306
selector:
name: mysql
3.编辑nacos的yaml文件
[root@k8s-matser01 ~]# cat nacos.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
selector:
matchLabels:
app: nacos
template:
metadata:
labels:
app: nacos
spec:
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: 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: TZ
value: Asia/Shanghai
- name: MODE
value: standalone
4.启动服务
[root@k8s-matser01 ~]# kubectl get pod -n nacos
NAME READY STATUS RESTARTS AGE
mysql-p69fz 1/1 Running 0 58m
nacos-0 1/1 Running 0 16s
[root@k8s-matser01 ~]# kubectl get svc -n nacos
NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE
mysql ClusterIP 10.107.79.243 <none> 3306/TCP 57m
nacos NodePort 10.97.138.81 <none> 8848:30018/TCP,7848:30019/TCP 36s
nacos-headless ClusterIP None <none> 8848/TCP,7848/TCP 36s
标签:单机版,name,nacos,value,8848,mysql,K8S,port 来源: https://www.cnblogs.com/Applogize/p/15398591.html