-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdeploy.sh
executable file
·179 lines (154 loc) · 4.88 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
# --------------------------- color config ---------------------------
GREEN='\033[0;32m'
LB='\033[1;34m' # light blue
YE='\033[1;33m' # yellow
NC='\033[0m' # No Color
# --------------------------------------------------------------------
# ------------------------ dependency check --------------------------
check=`kubectl get storageclasses.storage.k8s.io | grep -q "(default)"`
if [ -z "$check" ]
then
echo -e "[${LB}Info${NC}] storage class available"
else
echo -e "[${YE}Warn${NC}] no storage class found, try to deploy localstorage provisioner"
kubectl apply -f k8s/storage-class.yaml
fi
# --------------------------------------------------------------------
# -------------------------- deployment menu -------------------------
logForwarder=1
read -p "Which log forwarder do you want to use
1: Fluentbit
2: Fluentd
(default:1) promt with [ENTER]:" inputLogForwarder
logForwarder="${inputLogForwarder:-$logForwarder}"
diskSpace=2
read -p "How many gigabyte diskspace do you want per node?(default:2) promt with [ENTER]:" inputDiskSpace
diskSpace="${inputDiskSpace:-$diskSpace}"
echo -e "[${LB}Info${NC}] elastic pvc requires ${diskSpace}Gi diskspace"
# --------------------------------------------------------------------
# -------------------------- deployment start ------------------------
echo -e "[${LB}Info${NC}] Install custom resource definitions and the operator with its RBAC rules"
kubectl apply -f https://download.elastic.co/downloads/eck/1.2.1/all-in-one.yaml
kubectl config set-context --current --namespace=elastic-system
echo -e "[${LB}Info${NC}] deploy elasticsearch"
cat <<EOF | kubectl apply -f -
apiVersion: elasticsearch.k8s.elastic.co/v1
kind: Elasticsearch
metadata:
name: quickstart
spec:
version: 7.9.0
http:
tls:
selfSignedCertificate:
disabled: true
nodeSets:
- name: default
count: 1
config:
node.master: true
node.data: true
node.ingest: true
node.store.allow_mmap: false
volumeClaimTemplates:
- metadata:
name: elasticsearch-data
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: ${diskSpace}Gi
EOF
echo -e "[${LB}Info${NC}] deploy kibana"
cat <<EOF | kubectl apply -f -
apiVersion: kibana.k8s.elastic.co/v1
kind: Kibana
metadata:
name: quickstart
spec:
http:
tls:
selfSignedCertificate:
disabled: true
version: 7.9.0
count: 1
elasticsearchRef:
name: quickstart
EOF
if [ $logForwarder -eq 1 ]; then
echo -e "[${LB}Info${NC}] deploy fluentd"
kubectl apply -f fluentbit/fluent-bit-configmap.yaml
kubectl apply -f fluentbit/fluent-bit-service-account.yaml
kubectl apply -f fluentbit/fluent-bit-role.yaml
# rolebinding is tied to the namespace "elastic-system"
kubectl apply -f fluentbit/fluent-bit-role-binding.yaml
kubectl apply -f fluentbit/fluent-bit-ds.yaml
kubectl rollout status daemonset.apps/fluent-bit
elif [ $logForwarder -eq 2 ]; then
echo -e "[${LB}Info${NC}] deploy fluentd"
kubectl apply -f fluentd/fluentd-cm.yaml
kubectl apply -f fluentd/fluentd-daemonset.yaml
kubectl rollout status daemonset.apps/fluentd
fi
# --------------------------------------------------------------------
# ---------------------- credentials and access ----------------------
elasticpw=`kubectl get secret quickstart-es-elastic-user -o go-template='{{.data.elastic | base64decode}}'`
echo -e "[${LB}Info${NC}] here are your kibana credentials. User is ${LB}elastic${NC}, Password ${LB}${elasticpw}${NC}"
echo -e "[${LB}Info${NC}] waiting for deployment of kibana and elasticsearch (takes a cuple of minutes)"
kubectl rollout status deployment/quickstart-kb
kubectl port-forward service/quickstart-kb-http 5601
# --------------------------------------------------------------------
# --------------------- elastic retension config----------------------
echo -e 'Define log retentionlifetimes with the ilm function
Use the buildin dev console for execution
PUT _ilm/policy/baremetal-ilm
{
"policy": {
"phases": {
"hot": {
"min_age": "0ms",
"actions": {
"rollover": {
"max_age": "7d",
"max_size": "4gb"
},
"set_priority": {
"priority": 100
}
}
},
"delete": {
"min_age": "1d",
"actions": {
"delete": {
"delete_searchable_snapshot": true
}
}
}
}
}
}
PUT _index_template/baremetal-template
{
"index_patterns": ["baremetal-*"],
"template": {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1,
"index.lifecycle.name": "baremetal-ilm",
"index.lifecycle.rollover_alias": "baremetal-rollover"
}
}
}
PUT baremetal*/_settings
{
"index": {
"lifecycle": {
"name": "baremetal-ilm"
}
}
}
'
# --------------------------------------------------------------------