-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
134 lines (120 loc) · 2.95 KB
/
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /bin/bash
if [ $# -ne 4 ]
then
echo 'usage: ./deploy.sh $namespace $release $duration $interval'
exit 1
fi
namespace=$1
release=$2
duration=$3
interval=$4
if [ $duration -le $interval ]
then
echo "the duration value need larger than interval value"
exit 1
fi
if [ $duration -lt 60 ]
then
echo "the duration value cannot less than 60"
exit 1
fi
kubectl apply -f - <<EOF
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: milvus-gather-service-reader
namespace: ${namespace}
rules:
- apiGroups: [""] # "" indicates the core API group
resources: ["services","pods","deployments"]
verbs: ["get", "watch", "list"]
- apiGroups: ["apps"] # "" indicates the core API group
resources: ["replicasets","deployments"]
verbs: ["get", "watch", "list"]
- apiGroups: [""]
resources: ["pods/exec"]
verbs: ["create"]
---
EOF
if [ $? -ne 0 ]
then
echo "You don't have permission to create Role, please check your k8s user permissions."
exit 1
fi
kubectl apply -f - <<EOF
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: milvus-gather-service-reader
namespace: ${namespace}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: milvus-gather-service-reader
subjects:
- kind: ServiceAccount
name: default
namespace: ${namespace}
---
EOF
if [ $? -ne 0 ]
then
echo "You don't have permission to create RoleBinding, please check your k8s user permissions."
exit 1
fi
kubectl apply -f - <<EOF
apiVersion: v1
kind: ConfigMap
metadata:
name: milvus-gather-config
namespace: ${namespace}
data:
config.json: |
{
"namespace":"${namespace}",
"release":"${release}",
"duration": ${duration},
"interval": ${interval}
}
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: milvus-gather
labels:
app: milvus-gather
namespace: ${namespace}
spec:
replicas: 1
selector:
matchLabels:
app: milvus-gather
template:
metadata:
labels:
app: milvus-gather
spec:
containers:
- name: milvus-gather
image: kevin1991/milvus-gather:latest
volumeMounts:
- mountPath: /milvus/config
name: milvus-gather-config
volumes:
- configMap:
name: milvus-gather-config
name: milvus-gather-config
EOF
echo "start gather info......"
echo "wait $((duration + interval)) seconds"
sleep $((duration + interval))
echo "finish gather info......"
echo "cp data.tar.gz from pod to local"
pod=`kubectl get pod -n ${namespace}|grep milvus-gather|awk '{print $1}'`
kubectl exec pod/${pod} -n ${namespace} -- tar zcf data.tar.gz data
kubectl cp ${pod}:data.tar.gz data.tar.gz -n ${namespace}
echo "delete resource......"
kubectl delete deployment milvus-gather -n ${namespace}
kubectl delete configmap milvus-gather-config -n ${namespace}
kubectl delete rolebinding milvus-gather-service-reader -n ${namespace}
kubectl delete role milvus-gather-service-reader -n ${namespace}