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
1ea335f8
Commit
1ea335f8
authored
Apr 20, 2022
by
黎博
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化kafka deployment
parent
d56c915f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
10 additions
and
10 deletions
+10
-10
TkeService.java
src/main/java/cn/qg/holmes/service/k8s/TkeService.java
+6
-6
Kafka-Deployment.yml
src/main/resources/tke/template/Kafka-Deployment.yml
+3
-3
Kafka-Service.yml
src/main/resources/tke/template/Kafka-Service.yml
+1
-1
No files found.
src/main/java/cn/qg/holmes/service/k8s/TkeService.java
View file @
1ea335f8
...
...
@@ -545,7 +545,7 @@ public class TkeService {
// kafka还需替换下zookeeper地址和本身的Service port
if
(
StringUtils
.
equals
(
serviceName
,
"kafka"
))
{
Map
<
String
,
Object
>
zookeeperInfo
=
getPodAndServiceInfo
(
namespace
,
"base"
,
"zookeeper"
);
deploymentYaml
=
deploymentYaml
.
replaceAll
(
"\\{\\{ZOOKEEPER_HOST}"
,
zookeeperInfo
.
get
(
"lanIp"
).
toString
());
deploymentYaml
=
deploymentYaml
.
replaceAll
(
"\\{\\{ZOOKEEPER_HOST}
}
"
,
zookeeperInfo
.
get
(
"lanIp"
).
toString
());
deploymentYaml
=
deploymentYaml
.
replaceAll
(
"\\{\\{ZOOKEEPER_PORT}}"
,
zookeeperInfo
.
get
(
"port_2181"
).
toString
());
int
count
=
10
;
Service
kafkaService
;
...
...
@@ -553,7 +553,7 @@ public class TkeService {
try
{
kafkaService
=
getServiceDetail
(
namespace
,
"kafka-"
+
namespace
);
if
(
kafkaService
!=
null
)
{
deploymentYaml
.
replaceAll
(
"\\{\\{KAFKA_SERVICE_PORT}}"
,
String
.
valueOf
(
kafkaService
.
getSpec
().
getPorts
().
get
(
0
).
getNodePort
()));
deploymentYaml
=
deploymentYaml
.
replaceAll
(
"\\{\\{KAFKA_SERVICE_PORT}}"
,
String
.
valueOf
(
kafkaService
.
getSpec
().
getPorts
().
get
(
0
).
getNodePort
()));
break
;
}
Thread
.
currentThread
().
sleep
(
1000
);
...
...
@@ -606,7 +606,7 @@ public class TkeService {
deployment
.
getSpec
().
getTemplate
().
getSpec
().
getContainers
().
forEach
(
container
->
container
.
setReadinessProbe
(
readinessProbe
));
deployment
.
getSpec
().
getTemplate
().
getSpec
().
getContainers
().
forEach
(
container
->
container
.
setLivenessProbe
(
livelinessProbe
));
}
log
.
info
(
"开始在{}环境
,
创建{}的k8s Deployment: \n{}"
,
namespace
,
serviceName
,
YamlUtils
.
JsonToYamlStr
(
JSON
.
toJSONString
(
deployment
)));
log
.
info
(
"开始在{}环境创建{}的k8s Deployment: \n{}"
,
namespace
,
serviceName
,
YamlUtils
.
JsonToYamlStr
(
JSON
.
toJSONString
(
deployment
)));
return
kubernetesClient
.
apps
().
deployments
().
inNamespace
(
namespace
).
createOrReplace
(
deployment
);
}
catch
(
IOException
e
)
{
log
.
info
(
"创建Deployment失败!"
);
...
...
@@ -647,7 +647,7 @@ public class TkeService {
}
Yaml
yaml
=
new
Yaml
(
new
Constructor
(
Service
.
class
));
Service
service
=
yaml
.
load
(
serviceYaml
);
log
.
info
(
"开始在{}环境
,创建{}服务的,
k8s Service: \n{}"
,
namespace
,
serviceName
,
serviceYaml
);
log
.
info
(
"开始在{}环境
创建{}服务的
k8s Service: \n{}"
,
namespace
,
serviceName
,
serviceYaml
);
return
kubernetesClient
.
services
().
inNamespace
(
namespace
).
createOrReplace
(
service
);
}
catch
(
IOException
e
)
{
log
.
info
(
"Service创建失败."
);
...
...
@@ -672,7 +672,7 @@ public class TkeService {
String
pvcFilePath
=
"tke/template/"
+
StringUtils
.
capitalize
(
serviceName
)
+
"-Pvc.yml"
;
String
pvcYaml
=
FileUtils
.
readFileFromClassPathResource
(
pvcFilePath
);
pvcYaml
=
TkeUtils
.
replaceBasicYaml
(
pvcYaml
,
serviceCreateVo
);
log
.
info
(
"开始在{}环境
,
创建{}服务的k8s Pvc:\n{}"
,
namespace
,
serviceName
,
pvcYaml
);
log
.
info
(
"开始在{}环境创建{}服务的k8s Pvc:\n{}"
,
namespace
,
serviceName
,
pvcYaml
);
Yaml
yaml
=
new
Yaml
(
new
Constructor
(
PersistentVolumeClaim
.
class
));
PersistentVolumeClaim
persistentVolumeClaim
=
yaml
.
load
(
pvcYaml
);
return
kubernetesClient
.
persistentVolumeClaims
().
inNamespace
(
namespace
).
create
(
persistentVolumeClaim
);
...
...
@@ -692,7 +692,7 @@ public class TkeService {
try
{
String
ingressYaml
=
FileUtils
.
readFileFromClassPathResource
(
"tke/template/Ingress.yml"
);
ingressYaml
=
TkeUtils
.
replaceBusinessYaml
(
ingressYaml
,
serviceCreateVo
,
null
);
log
.
info
(
"开始在{}环境
,创建{}服务的
Ingress:\n{}"
,
serviceCreateVo
.
getNamespace
(),
serviceCreateVo
.
getServiceName
(),
ingressYaml
);
log
.
info
(
"开始在{}环境
创建{}服务的k8
Ingress:\n{}"
,
serviceCreateVo
.
getNamespace
(),
serviceCreateVo
.
getServiceName
(),
ingressYaml
);
Yaml
yaml
=
new
Yaml
(
new
Constructor
(
Ingress
.
class
));
Ingress
ingress
=
yaml
.
load
(
ingressYaml
);
IntOrString
servicePort
=
new
IntOrStringBuilder
().
withIntVal
(
80
).
build
();
...
...
src/main/resources/tke/template/Kafka-Deployment.yml
View file @
1ea335f8
...
...
@@ -23,9 +23,9 @@ spec:
imagePullPolicy
:
IfNotPresent
ports
:
-
containerPort
:
9092
livenessProbe
:
tcpSocket
:
port
:
9092
#
livenessProbe:
#
tcpSocket:
#
port: 9092
env
:
-
name
:
KAFKA_ZOOKEEPER_CONNECT
value
:
{{
ZOOKEEPER_HOST
}}
:{{ZOOKEEPER_PORT}}/kafka
...
...
src/main/resources/tke/template/Kafka-Service.yml
View file @
1ea335f8
...
...
@@ -11,7 +11,7 @@ spec:
ports
:
-
port
:
9092
name
:
kafka-9092-9092
targetPort
:
9092
# targetPort: "9092"
protocol
:
TCP
selector
:
qcloud-app
:
kafka
\ No newline at end of file
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