Commit 3a197e04 authored by kewei.jia's avatar kewei.jia Committed by 智勇

添加QKE 功能支持

parent 4f2831c2
......@@ -20,7 +20,7 @@ const {
replicaSetDelete,
pvcDelete,
} = require('../kubeService/service')
const newClient = require('./../resource/getClient')
const getClient = require('./../resource/getClient')
const router = new Router()
module.exports = router
......@@ -174,12 +174,26 @@ router.get('/listEnvVars', async (ctx) => {
})
// for container
const clientNew = {}
router.get('/listEnvVarsNew', async (ctx) => {
const envVars = {}
const { namespace, client } = newClient(ctx)
let cluster;
let namespace;
const parmars = ctx.request.query.namespace || ''
if (parmars.search('@') === -1) {
cluster = 'qa'
namespace = ctx.request.query.namespace
} else {
namespace = parmars.split('@')[0];
cluster = parmars.split('@')[1]
}
if (!clientNew[cluster]) {
console.log('为空')
clientNew[cluster] = getClient(cluster)
}
const res = await Promise.all([
getPods(client, namespace),
getServices(client, namespace),
getPods(clientNew[cluster], namespace),
getServices(clientNew[cluster], namespace),
])
res[0].body.items.forEach(async (item) => {
......
......@@ -2,17 +2,7 @@ const path = require('path')
const Client = require('kubernetes-client').Client
const config = require('kubernetes-client').config
const newClient = function client(ctx) {
const parmars = ctx.request.query.namespace || ''
if (parmars.search('@') === -1) {
ctx.body = {
code: '0001',
msg: '参数传入不合法',
}
return false
}
const namespace = parmars.split('@')[0];
const cluster = parmars.split('@')[1]
module.exports = function getClient(cluster) {
let yaml = ''
switch (cluster) {
case 'qa':
......@@ -25,17 +15,12 @@ const newClient = function client(ctx) {
yaml = './../kubeService/kubeConfig-qke.yaml'
break
default:
ctx.body = {
code: '0001',
msg: '请选择集群的名字',
}
throw Error('未获取到Client')
}
const client = new Client({
return new Client({
config: config.fromKubeconfig(
path.resolve(__dirname, yaml),
),
version: '1.10',
})
return { namespace, client }
}
module.exports = newClient
......@@ -9,7 +9,7 @@ metadata:
spec:
type: NodePort
ports:
- port: 3306
- port: 3306
selector:
qcloud-app: {{serviceName}}
......@@ -21,12 +21,12 @@ metadata:
name: {{serviceName}}-{{namespace}}
namespace: {{namespace}}
spec:
storageClassName: cbs
storageClassName: cbs-3
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
storage: 20Gi
---
......@@ -53,42 +53,44 @@ spec:
type: base
spec:
containers:
- image: ccr.ccs.tencentyun.com/{{image}}
imagePullPolicy: Always
name: {{serviceName}}
resources:
requests:
cpu: {{resources.cpu.request}}m
memory: {{resources.memory.request}}Mi
limits:
cpu: {{resources.cpu.limit}}m
memory: {{resources.memory.limit}}Mi
env:
- name: MYSQL_DATABASE
value: db
- name: MYSQL_PASSWORD
value: qatest
- name: MYSQL_ROOT_PASSWORD
value: Quantgroup2017
- name: MYSQL_USER
value: qa
readinessProbe:
exec:
command: ["mysql", "-uqa", "-pqatest", "-e", "SELECT 1"]
initialDelaySeconds: 5
periodSeconds: 2
timeoutSeconds: 1
failureThreshold: 40
volumeMounts:
- mountPath: "/var/lib/mysql"
name: {{serviceName}}
- image: ccr.ccs.tencentyun.com/{{image}}
imagePullPolicy: Always
name: {{serviceName}}
resources:
requests:
cpu: {{resources.cpu.request}}m
memory: {{resources.memory.request}}Mi
limits:
cpu: {{resources.cpu.limit}}m
memory: {{resources.memory.limit}}Mi
env:
- name: MYSQL_DATABASE
value: db
- name: MYSQL_PASSWORD
value: qatest
- name: MYSQL_ROOT_PASSWORD
value: Quantgroup2017
- name: MYSQL_USER
value: qa
readinessProbe:
exec:
command: ["mysql", "-uqa", "-pqatest", "-e", "SELECT 1"]
initialDelaySeconds: 5
periodSeconds: 2
timeoutSeconds: 1
failureThreshold: 40
volumeMounts:
- mountPath: "/var/lib/mysql"
name: {{serviceName}}
# nodeSelector:
# zone: "3"
volumes:
- name: {{serviceName}}
persistentVolumeClaim:
claimName: {{serviceName}}-{{namespace}}
imagePullSecrets:
- name: qcloudregistrykey
- name: tencenthubkey
- name: qcloudregistrykey
- name: tencenthubkey
restartPolicy: Always
terminationGracePeriodSeconds: 30
status: {}
......@@ -35,6 +35,8 @@ spec:
qcloud-app: {{serviceName}}
type: base
spec:
nodeSelector:
zone: "3"
containers:
- image: ccr.ccs.tencentyun.com/{{image}}
imagePullPolicy: Always
......
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