Commit 3847df41 authored by 智勇's avatar 智勇

base pvc

parent 972107c1
...@@ -50,7 +50,7 @@ const createService = async (ctx) => { ...@@ -50,7 +50,7 @@ const createService = async (ctx) => {
type, serviceName, namespace, image, system_name, domain, label, type, serviceName, namespace, image, system_name, domain, label,
} = ctx.request.body } = ctx.request.body
logger.info('创建服务', ctx.request.body) logger.info('创建服务', ctx.request.body)
if (serviceName === 'mysql') { if (label === 'base') {
await serviceCreate(namespace, serviceName, image, label) await serviceCreate(namespace, serviceName, image, label)
ctx.body = ctx.ok('创建成功') ctx.body = ctx.ok('创建成功')
return return
......
...@@ -21,6 +21,8 @@ const serviceCreate = async (namespace, serviceName, image) => { ...@@ -21,6 +21,8 @@ const serviceCreate = async (namespace, serviceName, image) => {
app: serviceName, app: serviceName,
image, image,
} }
const pvcName = `${serviceName}-${namespace}`
const yamlManifest = yamls[serviceName].replace(/{{([A-Za-z0-9_\.]+)}}/g, function () { const yamlManifest = yamls[serviceName].replace(/{{([A-Za-z0-9_\.]+)}}/g, function () {
if (_.get(data, arguments[1], null) === null) { if (_.get(data, arguments[1], null) === null) {
throw new Error(`缺少模板所需变量: ${arguments[1]}`) throw new Error(`缺少模板所需变量: ${arguments[1]}`)
...@@ -45,7 +47,7 @@ const serviceCreate = async (namespace, serviceName, image) => { ...@@ -45,7 +47,7 @@ const serviceCreate = async (namespace, serviceName, image) => {
case 'PersistentVolumeClaim': case 'PersistentVolumeClaim':
pvc = await client.api.v1.namespaces(namespace).persistentvolumeclaims.get() pvc = await client.api.v1.namespaces(namespace).persistentvolumeclaims.get()
pvc = pvc.body.items.filter(item => item.metadata.name === serviceName) pvc = pvc.body.items.filter(item => item.metadata.name === pvcName)
if (!pvc.length) { if (!pvc.length) {
await client.api.v1.namespaces(namespace).persistentvolumeclaims.post({ body: jsonObj }) await client.api.v1.namespaces(namespace).persistentvolumeclaims.post({ body: jsonObj })
} }
......
const fs = require('fs') const fs = require('fs')
const mysql = fs.readFileSync('yamls/mysql.yaml', 'utf8') const mysql = fs.readFileSync('yamls/mysql.pvc.yaml', 'utf8')
const redis = fs.readFileSync('yamls/redis.pvc.yaml', 'utf8')
const rabbitmq = fs.readFileSync('yamls/rabbitmq.pvc.yaml', 'utf8')
const zookeeper = fs.readFileSync('yamls/zookeeper.pvc.yaml', 'utf8')
module.exports = { module.exports = {
mysql, mysql,
redis,
rabbitmq,
zookeeper,
} }
kind: PersistentVolumeClaim kind: PersistentVolumeClaim
apiVersion: v1 apiVersion: v1
metadata: metadata:
name: {{app}} name: {{app}}-{{namespace}}
namespace: {{namespace}} namespace: {{namespace}}
spec: spec:
storageClassName: cbs storageClassName: cbs
...@@ -55,12 +55,12 @@ spec: ...@@ -55,12 +55,12 @@ spec:
- name: MYSQL_USER - name: MYSQL_USER
value: qa value: qa
volumeMounts: volumeMounts:
- mountPath: "/data/mysql" - mountPath: "/var/lib/mysql"
name: mysql name: {{app}}
volumes: volumes:
- name: mysql - name: {{app}}
persistentVolumeClaim: persistentVolumeClaim:
claimName: mysql claimName: {{app}}-{{namespace}}
imagePullSecrets: imagePullSecrets:
- name: qcloudregistrykey - name: qcloudregistrykey
- name: tencenthubkey - name: tencenthubkey
...@@ -81,9 +81,7 @@ spec: ...@@ -81,9 +81,7 @@ spec:
type: NodePort type: NodePort
ports: ports:
- name: '3306' - name: '3306'
nodePort: 0
port: 3306 port: 3306
protocol: TCP
targetPort: 3306 targetPort: 3306
selector: selector:
qcloud-app: {{app}} qcloud-app: {{app}}
kind: PersistentVolumeClaim kind: PersistentVolumeClaim
apiVersion: v1 apiVersion: v1
metadata: metadata:
name: pvc-rabbitmq-test1-db name: {{app}}-{{namespace}}
namespace: test1 namespace: {{namespace}}
spec: spec:
storageClassName: cbs storageClassName: cbs
accessModes: accessModes:
...@@ -13,32 +12,32 @@ spec: ...@@ -13,32 +12,32 @@ spec:
storage: 10Gi storage: 10Gi
--- ---
apiVersion: extensions/v1beta1
apiVersion: apps/v1beta1
kind: Deployment kind: Deployment
metadata: metadata:
labels: labels:
qcloud-app: rabbitmq type: base
name: rabbitmq qcloud-app: {{app}}
namespace: test1 name: {{app}}
namespace: {{namespace}}
spec: spec:
replicas: 1 replicas: 1
revisionHistoryLimit: 1 revisionHistoryLimit: 1
selector: selector:
matchLabels: matchLabels:
qcloud-app: rabbitmq qcloud-app: {{app}}
strategy: strategy:
type: Recreate type: Recreate
template: template:
metadata: metadata:
labels: labels:
qcloud-app: rabbitmq qcloud-app: {{app}}
spec: spec:
# hostname固定,容器重置后数据持久化才能正常
hostname: rabbitmq-test1
containers: containers:
- image: ccr.ccs.tencentyun.com/qa-base/rabbitmq:3.6 - image: ccr.ccs.tencentyun.com/{{image}}
imagePullPolicy: IfNotPresent imagePullPolicy: Always
name: rabbitmq name: {{app}}
resources: resources:
requests: requests:
memory: 100Mi memory: 100Mi
...@@ -46,19 +45,18 @@ spec: ...@@ -46,19 +45,18 @@ spec:
limits: limits:
memory: 500Mi memory: 500Mi
cpu: 500m cpu: 500m
env:
- name: RABBITMQ_DEFAULT_USER
value: qa
- name: RABBITMQ_DEFAULT_PASS
value: qatest
# 数据持久化
volumeMounts: volumeMounts:
- name: db - mountPath: "/var/lib/rabbitmq"
mountPath: "/var/lib/rabbitmq" name: {{app}}
env:
- name: RABBITMQ_DEFAULT_USER
value: qa
- name: RABBITMQ_DEFAULT_PASS
value: qatest
volumes: volumes:
- name: db - name: {{app}}
persistentVolumeClaim: persistentVolumeClaim:
claimName: pvc-rabbitmq-test1-db claimName: {{app}}-{{namespace}}
imagePullSecrets: imagePullSecrets:
- name: qcloudregistrykey - name: qcloudregistrykey
- name: tencenthubkey - name: tencenthubkey
...@@ -72,25 +70,17 @@ kind: Service ...@@ -72,25 +70,17 @@ kind: Service
metadata: metadata:
labels: labels:
type: base type: base
qcloud-app: rabbitmq qcloud-app: {{app}}
name: rabbitmq name: {{app}}
namespace: test1 namespace: {{namespace}}
spec: spec:
type: NodePort type: NodePort
# 保留客户端源 IP 地址, 方便调试连接
externalTrafficPolicy: Local
selector:
qcloud-app: rabbitmq
ports: ports:
- name: tcp-5672-5672 - name: tcp-5672-5672
nodePort: 0
port: 5672 port: 5672
protocol: TCP
targetPort: 5672 targetPort: 5672
- name: tcp-15672-15672 - name: tcp-15672-15672
nodePort: 0
port: 15672 port: 15672
protocol: TCP
targetPort: 15672 targetPort: 15672
selector:
qcloud-app: {{app}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{app}}-{{namespace}}
namespace: {{namespace}}
spec:
storageClassName: cbs
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
labels:
type: base
qcloud-app: {{app}}
name: {{app}}
namespace: {{namespace}}
spec:
replicas: 1
revisionHistoryLimit: 1
selector:
matchLabels:
qcloud-app: {{app}}
strategy:
type: Recreate
template:
metadata:
labels:
qcloud-app: {{app}}
spec:
containers:
- image: ccr.ccs.tencentyun.com/{{image}}
imagePullPolicy: Always
name: {{app}}
resources:
requests:
memory: 40Mi
cpu: 100m
limits:
memory: 500Mi
cpu: 500m
volumeMounts:
- mountPath: "/data"
name: {{app}}
volumes:
- name: {{app}}
persistentVolumeClaim:
claimName: {{app}}-{{namespace}}
imagePullSecrets:
- name: qcloudregistrykey
- name: tencenthubkey
restartPolicy: Always
terminationGracePeriodSeconds: 30
status: {}
---
apiVersion: v1
kind: Service
metadata:
labels:
type: base
qcloud-app: {{app}}
name: {{app}}
namespace: {{namespace}}
spec:
type: NodePort
ports:
- name: '6379'
port: 6379
targetPort: 6379
- name: '6380'
port: 6380
targetPort: 6380
- name: '6381'
port: 6381
targetPort: 6381
- name: '6382'
port: 6382
targetPort: 6382
- name: '6383'
port: 6383
targetPort: 6383
selector:
qcloud-app: {{app}}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{app}}-{{namespace}}
namespace: {{namespace}}
spec:
storageClassName: cbs
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 10Gi
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
labels:
type: base
qcloud-app: {{app}}
name: {{app}}
namespace: {{namespace}}
spec:
replicas: 1
revisionHistoryLimit: 1
selector:
matchLabels:
qcloud-app: {{app}}
strategy:
type: Recreate
template:
metadata:
labels:
qcloud-app: {{app}}
spec:
containers:
- image: ccr.ccs.tencentyun.com/{{image}}
imagePullPolicy: Always
name: {{app}}
resources:
requests:
memory: 100Mi
cpu: 100m
limits:
memory: 500Mi
cpu: 500m
volumeMounts:
- mountPath: "/var/lib/zookeeper"
name: {{app}}
env:
- name: ZOO_USER
value: zookeeper
# - name: ZOO_PORT
# value: 2181
volumes:
- name: {{app}}
persistentVolumeClaim:
claimName: {{app}}-{{namespace}}
imagePullSecrets:
- name: qcloudregistrykey
- name: tencenthubkey
restartPolicy: Always
terminationGracePeriodSeconds: 30
status: {}
---
apiVersion: v1
kind: Service
metadata:
labels:
type: base
qcloud-app: {{app}}
name: {{app}}
namespace: {{namespace}}
spec:
type: NodePort
ports:
- name: tcp-2181
port: 2181
targetPort: 2181
- name: tcp-9090
port: 9090
targetPort: 9090
selector:
qcloud-app: {{app}}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment