Skip to content

Commit

Permalink
rancher demo
Browse files Browse the repository at this point in the history
  • Loading branch information
minminmsn committed Sep 9, 2020
1 parent 2f13023 commit 0dd5136
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 0 deletions.
31 changes: 31 additions & 0 deletions rancher/demo/.rancher-pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
stages:
- name: compile
steps:
- runScriptConfig:
image: core-harbor.zhidaoauto.com/enterprise-dev/centos-jdk8-maven
- name: push
steps:
- publishImageConfig:
dockerfilePath: ./Dockerfile
buildContext: .
tag: core-harbor.minminmsn.com/public/${CICD_GIT_REPO_NAME}:${CICD_GIT_COMMIT}
pushRemote: true
registry: core-harbor.minminmsn.com
- name: deploy
steps:
- applyYamlConfig:
path: ./kubernetes.yaml

notification:
recipients:
- recipient: [email protected]
notifier: local:n-chlz9
condition:
- Success

timeout: 60
branch:
include:
- release/dev
- release/qa
- release/prod
8 changes: 8 additions & 0 deletions rancher/demo/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM core-harbor.minminmsn.com/public/centos-jdk8:v1.0.7
MAINTAINER minminmsn

ADD ./target/*.jar /opt/app.jar

EXPOSE 8080

CMD ["bash", "-c", "java $JAVA_OPTS -jar /opt/app.jar $APP_ARGS"]
16 changes: 16 additions & 0 deletions rancher/demo/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env sh

echo '-- build --'

mvn clean package spring-boot:repackage -DskipTests
mv target/*.jar target/app.jar

# setup namespace
PROFILE=`echo ${CICD_GIT_BRANCH} | awk '{sub(/release\//,""); print $0}'`
NS_POSTFIX=`echo ${CICD_GIT_BRANCH} | awk '{sub(/release\//,""); print $0}'`
NS=tech-${NS_POSTFIX}
NS=`echo ${NS} | awk '{sub(/-$/,""); print $0}'`
sed -i "s/{NS}/${NS}/g" kubernetes.yaml
sed -i "s/{PROFILE}/${PROFILE}/g" kubernetes.yaml

env
132 changes: 132 additions & 0 deletions rancher/demo/kubernetes.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
apiVersion: v1
kind: Service
metadata:
name: ${CICD_GIT_REPO_NAME}
labels:
app: ${CICD_GIT_REPO_NAME}
namespace: {NS}
spec:
type: NodePort
ports:
- port: 80
protocol: TCP
targetPort: 8080
selector:
app: ${CICD_GIT_REPO_NAME}

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: ${CICD_GIT_REPO_NAME}
labels:
app: ${CICD_GIT_REPO_NAME}
namespace: {NS}
spec:
replicas: 2
selector:
matchLabels:
app: ${CICD_GIT_REPO_NAME}
template:
metadata:
labels:
app: ${CICD_GIT_REPO_NAME}
spec:
containers:
- name: java
image: core-harbor.minminmsn.com/public/${CICD_GIT_REPO_NAME}:${CICD_GIT_COMMIT}
command:
- "bash"
- "-c"
- "java -Denv={PROFILE} -Dfile.encoding=utf-8 $JAVA_OPTS -jar /opt/app.jar $APP_ARGS"
ports:
- containerPort: 8080
imagePullPolicy: IfNotPresent
env:
- name: JAVA_OPTS
value: "
-javaagent:/opt/skywalking/skywalking-agent.jar
-Dskywalking.agent.namespace={PROFILE}
-Dskywalking.agent.service_name=${CICD_GIT_REPO_NAME}
-Dskywalking.collector.backend_service=192.168.88.61:11800
-Dskywalking.logging.file_name=${CICD_GIT_REPO_NAME}.log
-Dskywalking.logging.level=ERROR
-Dskywalking.agent.cool_down_threshold=3
-Dskywalking.agent.operation_name_threshold=10000
-Dplugin.toolit.use_qualified_name_as_operation_name=true
-Dskywalking.plugin.mysql.trace_sql_parameters=true
-server
-Xms1024m
-Xmx1024m
-Duser.timezone=GMT+8
-XX:+HeapDumpOnOutOfMemoryError
-XX:+DisableExplicitGC
-XX:+UseConcMarkSweepGC
-XX:+CMSParallelRemarkEnabled
-XX:+UseCMSInitiatingOccupancyOnly
-XX:CMSInitiatingOccupancyFraction=70
-XX:+PrintGCDetails
-XX:+PrintGCDateStamps
-XX:HeapDumpPath=/tmp/heapDump
-XX:ErrorFile=/tmp/logs/hs_err_pid%p.log
-Xloggc:/tmp/logs/gc.log"
readinessProbe:
initialDelaySeconds: 20
periodSeconds: 5
timeoutSeconds: 10
failureThreshold: 5
httpGet:
path: /demo/actuator/health
port: 8080
livenessProbe:
initialDelaySeconds: 60
periodSeconds: 5
timeoutSeconds: 5
failureThreshold: 3
httpGet:
path: /demo/actuator/health
port: 8080
volumeMounts:
- mountPath: /tmp
name: log-volume
lifecycle:
preStop:
exec:
command:
- "bash"
- "-c"
- "killjava app.jar"
resources:
requests:
cpu: "1"
memory: 1024Mi
limits:
cpu: "2"
memory: 2048Mi
- name: filebeat-log
image: elastic/filebeat:7.9.0
imagePullPolicy: IfNotPresent
volumeMounts:
- name: filebeat-config
subPath: filebeat.yml
mountPath: /usr/share/filebeat/filebeat.yml
- name: log-volume
mountPath: /tmp
- name: filebeat-big-data-kafka
image: elastic/filebeat:7.9.0
imagePullPolicy: IfNotPresent
volumeMounts:
- name: filebeat-big-data-config
subPath: filebeat.yml
mountPath: /usr/share/filebeat/filebeat.yml
- name: log-volume
mountPath: /tmp
volumes:
- name: log-volume
emptyDir: {}
- name: filebeat-config
configMap:
name: filebeat-config
- name: filebeat-big-data-config
configMap:
name: filebeat-big-data-config
23 changes: 23 additions & 0 deletions rancher/rancher集群流水线操作指南.md
Original file line number Diff line number Diff line change
@@ -1,38 +1,52 @@
**1.添加LDAP认证**

全局--安全--认证--编辑--启用OpenLDAP认证

设置仅允许授权的用户和组织,方便账号管理及安全使用

> ![](https://upload-images.jianshu.io/upload_images/7535971-6b4a4ed77c78c93e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

**2.添加通知**

Local--工具--通知

默认支持Slack、Mail、PagerDuty、Webhook、企业微信、钉钉、Microfoft Teams,这里选择邮件

> ![](https://upload-images.jianshu.io/upload_images/7535971-2741cc650d84097d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-846c1b773b9786c0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)




**3.添加日志**

Local--工具--日志

有Elasticsearch、Splunk、Kafka、Syslog、Fluentd,这里使用的是Elasticsearch

> ![](https://upload-images.jianshu.io/upload_images/7535971-c6936d64e3afcf53.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-4c493bd1157b3417.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)




**4.集成Gitlab**

Local--Defalt--工具--流水线

需要先在Gitlab对应项目账号中新建Application,然后在流水线中配置Gitlab应用,设置好id和secret后验证确认授权

> ![](https://upload-images.jianshu.io/upload_images/7535971-0034aa0b24ed5812.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-c9d0189bcdf86fe2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-5163c228931794c5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-00a80ee8e16d223b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


**5.配置镜像库凭证**

Local--Default--资源--密文--镜像库凭证列表--添加凭证

> ![](https://upload-images.jianshu.io/upload_images/7535971-44a6fe71d1ef52b2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-93f25e25f29484ce.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-5be1e241c8333a2e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Expand All @@ -41,7 +55,9 @@ Local--Default--资源--密文--镜像库凭证列表--添加凭证


**6.配置流水线**

Local--Default--资源--流水线--设置代码库--启用项目--编辑流水线

> ![](https://upload-images.jianshu.io/upload_images/7535971-eb9f3043016ef83a.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-ba1f46af4f7d774f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-2d2932e64a84c235.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
Expand All @@ -53,6 +69,7 @@ Local--Default--资源--流水线--设置代码库--启用项目--编辑流水

查看YAML如下


```
stages:
- name: Build
Expand Down Expand Up @@ -82,10 +99,16 @@ notification:
```

**7.运行流水线**

> ![](https://upload-images.jianshu.io/upload_images/7535971-cffe463751b55870.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/7535971-3b7aa0f8620e3d52.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)


部署成功可以发邮件

> ![](https://upload-images.jianshu.io/upload_images/7535971-b13b003f780e454d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

**8.最后架构图如下**

> ![](https://upload-images.jianshu.io/upload_images/7535971-230d6eb34f02d5bc.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

0 comments on commit 0dd5136

Please sign in to comment.