forked from FanJunling/jenkins-sample
-
Notifications
You must be signed in to change notification settings - Fork 698
/
k8s-deploy.sh
58 lines (51 loc) · 1.22 KB
/
k8s-deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
#生成部署k8s的 yaml 模板文件
echo "生成部署k8s的 yaml 模板文件"
cat > app_rollback_${2}.yaml <<EOF
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
namespace: production
name: $project_name
labels:
app: $project_name
spec:
replicas: $podNum
selector:
matchLabels:
app: $project_name
strategy:
rollingUpdate: ##由于replicas为3,则整个升级,pod个数在2-4个之间
maxSurge: 1 #滚动升级时会先启动1个pod
maxUnavailable: 1 #滚动升级时允许的最大Unavailable的pod个数
template:
metadata:
labels:
app: $project_name
spec:
containers:
- name: $project_name
#发布时拉取最新版本的镜像
image: xianchao/jenkins-demo:<BUILD_TAG>
imagePullPolicy: IfNotPresent
---
apiVersion: v1
kind: Service
metadata:
namespace: production
name: ${project_name}
labels:
app: ${project_name}
spec:
ports:
- port: 18888
targetPort: 18888
nodePort: 31890
protocol: TCP
type: NodePort
selector:
app: ${project_name}
EOF
echo "生成部署k8s的 yaml 模板 完毕"
echo "==================================================================="
echo " "