Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
holmes
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
QA
holmes
Commits
5906dbaa
Commit
5906dbaa
authored
Jun 07, 2022
by
黎博
Browse files
Options
Browse Files
Download
Plain Diff
merge
parents
5f0c8005
9c7ad798
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
10 deletions
+20
-10
K8sController.java
src/main/java/cn/qg/holmes/controller/k8s/K8sController.java
+18
-8
TkeService.java
src/main/java/cn/qg/holmes/service/k8s/TkeService.java
+1
-1
Rabbitmq-Deployment.yml
src/main/resources/tke/template/Rabbitmq-Deployment.yml
+1
-1
No files found.
src/main/java/cn/qg/holmes/controller/k8s/K8sController.java
View file @
5906dbaa
...
@@ -9,6 +9,7 @@ import cn.qg.holmes.service.auth.TokenService;
...
@@ -9,6 +9,7 @@ import cn.qg.holmes.service.auth.TokenService;
import
cn.qg.holmes.service.k8s.*
;
import
cn.qg.holmes.service.k8s.*
;
import
cn.qg.holmes.utils.MongoUtils
;
import
cn.qg.holmes.utils.MongoUtils
;
import
cn.qg.holmes.utils.RedisUtils
;
import
cn.qg.holmes.utils.RedisUtils
;
import
cn.qg.holmes.utils.YamlUtils
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.tencentcloudapi.tcr.v20190924.models.RepoInfo
;
import
com.tencentcloudapi.tcr.v20190924.models.RepoInfo
;
...
@@ -121,7 +122,10 @@ public class K8sController {
...
@@ -121,7 +122,10 @@ public class K8sController {
tkeService
.
createIngressByYaml
(
serviceCreateVo
);
tkeService
.
createIngressByYaml
(
serviceCreateVo
);
}
}
// 新增Service
// 新增Service
tkeService
.
createServiceByYaml
(
serviceCreateVo
);
Service
service
=
tkeService
.
createServiceByYaml
(
serviceCreateVo
);
// 休眠3秒,防止创建服务的时候获取不到Service暴露的端口
Thread
.
sleep
(
3000
);
log
.
info
(
"/service/create创建Deployment前,Service状态:{}"
,
YamlUtils
.
JsonToYamlStr
(
JSON
.
toJSONString
(
service
)));
// 新增Deployment
// 新增Deployment
tkeService
.
createDeploymentByYaml
(
serviceCreateVo
);
tkeService
.
createDeploymentByYaml
(
serviceCreateVo
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
...
@@ -182,14 +186,17 @@ public class K8sController {
...
@@ -182,14 +186,17 @@ public class K8sController {
Service
service
=
tkeService
.
getServiceDetail
(
namespace
,
serviceName
);
Service
service
=
tkeService
.
getServiceDetail
(
namespace
,
serviceName
);
if
(
service
==
null
)
{
if
(
service
==
null
)
{
// 创建或替换Service
// 创建或替换Service
tkeService
.
createServiceByYaml
(
serviceCreateVo
);
service
=
tkeService
.
createServiceByYaml
(
serviceCreateVo
);
try
{
}
Thread
.
sleep
(
3000
);
}
catch
(
InterruptedException
e
)
{
// 休眠5秒,防止服务启动时获取不到Service暴露出来的端口
e
.
printStackTrace
();
try
{
}
Thread
.
sleep
(
5000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();
}
}
log
.
info
(
"/service/modify创建Deployment前,Service状态:{}"
,
YamlUtils
.
JsonToYamlStr
(
JSON
.
toJSONString
(
service
)));
// 创建或替换Deployment
// 创建或替换Deployment
tkeService
.
createDeploymentByYaml
(
serviceCreateVo
);
tkeService
.
createDeploymentByYaml
(
serviceCreateVo
);
// 创建或替换Ingress
// 创建或替换Ingress
...
@@ -503,7 +510,10 @@ public class K8sController {
...
@@ -503,7 +510,10 @@ public class K8sController {
@RequestParam
String
serviceType
,
@RequestParam
String
serviceType
,
@RequestParam
String
serviceName
,
@RequestParam
String
serviceName
,
@RequestParam
String
key
)
{
@RequestParam
String
key
)
{
List
<
ServicePort
>
servicePortList
=
tkeService
.
getServiceDetail
(
namespace
,
serviceName
).
getSpec
().
getPorts
();
log
.
info
(
"开始调取/k8s/dubbo/port接口,namespace:{}, serviceName: {}, key: {}"
,
namespace
,
serviceName
,
key
);
Service
service
=
tkeService
.
getServiceDetail
(
namespace
,
serviceName
);
log
.
info
(
"获取到的Service信息:{}"
,
JSON
.
toJSONString
(
service
));
List
<
ServicePort
>
servicePortList
=
service
.
getSpec
().
getPorts
();
Map
<
String
,
Object
>
serviceMap
=
new
HashMap
<>();
Map
<
String
,
Object
>
serviceMap
=
new
HashMap
<>();
List
<
Map
<
String
,
Object
>>
portMappingList
=
new
ArrayList
<>();
List
<
Map
<
String
,
Object
>>
portMappingList
=
new
ArrayList
<>();
if
(
servicePortList
.
size
()
>
0
)
{
if
(
servicePortList
.
size
()
>
0
)
{
...
...
src/main/java/cn/qg/holmes/service/k8s/TkeService.java
View file @
5906dbaa
...
@@ -672,7 +672,7 @@ public class TkeService {
...
@@ -672,7 +672,7 @@ public class TkeService {
if
(
serviceCreateVo
.
getDebug
()
==
1
)
{
if
(
serviceCreateVo
.
getDebug
()
==
1
)
{
service
.
getSpec
().
setType
(
"NodePort"
);
service
.
getSpec
().
setType
(
"NodePort"
);
}
}
log
.
info
(
"开始在{}环境创建{}服务的k8s Service: \n{}"
,
namespace
,
serviceName
,
serviceYaml
);
log
.
info
(
"开始在{}环境创建{}服务的k8s Service: \n{}"
,
namespace
,
serviceName
,
YamlUtils
.
JsonToYamlStr
(
JSON
.
toJSONString
(
service
))
);
return
kubernetesClient
.
services
().
inNamespace
(
namespace
).
createOrReplace
(
service
);
return
kubernetesClient
.
services
().
inNamespace
(
namespace
).
createOrReplace
(
service
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
log
.
info
(
"Service创建失败."
);
log
.
info
(
"Service创建失败."
);
...
...
src/main/resources/tke/template/Rabbitmq-Deployment.yml
View file @
5906dbaa
...
@@ -55,7 +55,7 @@ spec:
...
@@ -55,7 +55,7 @@ spec:
# 数据持久化
# 数据持久化
volumeMounts
:
volumeMounts
:
-
name
:
rabbitmq
-
name
:
rabbitmq
mountPath
:
"
/var/lib/rabbitmq"
mountPath
:
/var/lib/rabbitmq
volumes
:
volumes
:
-
name
:
rabbitmq
-
name
:
rabbitmq
persistentVolumeClaim
:
persistentVolumeClaim
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment