Skip to content

Commit 13a2619

Browse files
committed
Adopted Elastic Stack version 8 and upgraded to 8.2.1 with quickstart demo for starting the ELK cluster in one shot
1 parent fb32369 commit 13a2619

File tree

10 files changed

+344
-75
lines changed

10 files changed

+344
-75
lines changed

bin/demo.sh

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/bin/bash
2+
3+
# Author: Bin Wu <[email protected]>
4+
5+
pwd=`pwd`
6+
cluster_name=elk-demo
7+
region=asia-east1
8+
# zone=asia-east1-a
9+
project_id=du-hast-mich
10+
default_pool=default-pool
11+
nodes_per_zone=5 # per zone
12+
machine_type=e2-standard-2
13+
release_channel=None # None -> static, e.g. rapid, regular, stable
14+
gke_version=1.23.6-gke.1500
15+
eck_version=2.2.0
16+
es_cluster_name=dingo-demo
17+
18+
__create_gke() {
19+
#--zone "${zone}" \
20+
#--node-locations "${region}-a,${region}-b,${region}-c"
21+
#--num-nodes "1" for regional/multi-zone cluster, this is the number in each zone
22+
gcloud beta container \
23+
--project "${project_id}" clusters create "$cluster_name" \
24+
--zone "${region}-a" \
25+
--node-locations "${region}-a" \
26+
--no-enable-basic-auth \
27+
--enable-dataplane-v2 \
28+
--release-channel "${release_channel}" \
29+
--cluster-version "${gke_version}" \
30+
--machine-type "$machine_type" \
31+
--image-type "COS_CONTAINERD" \
32+
--disk-type "pd-ssd" \
33+
--disk-size "20" \
34+
--metadata disable-legacy-endpoints=true \
35+
--scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" \
36+
--num-nodes "$nodes_per_zone" \
37+
--logging=SYSTEM,WORKLOAD \
38+
--monitoring=SYSTEM,WORKLOAD \
39+
--enable-ip-alias \
40+
--network "projects/${project_id}/global/networks/default" \
41+
--subnetwork "projects/${project_id}/regions/$region/subnetworks/default" \
42+
--default-max-pods-per-node "110" \
43+
--no-enable-master-authorized-networks \
44+
--addons HorizontalPodAutoscaling,HttpLoadBalancing \
45+
--no-enable-autoupgrade \
46+
--max-surge-upgrade 1 \
47+
--max-unavailable-upgrade 0 \
48+
--enable-autorepair
49+
50+
__init
51+
}
52+
53+
# setup the deployment enviroment for Elastic Stack
54+
__init() {
55+
# Set kubectl to target the created cluster
56+
gcloud container clusters get-credentials $cluster_name \
57+
--zone "${region}-a" \
58+
--project ${project_id}
59+
60+
# sysctl -w vm.max_map_count=262144 for every GKE node
61+
# Option 1
62+
# $pwd/bin/gke_sysctl_vmmaxmapcount.sh
63+
# Option 2
64+
kubectl apply -f $pwd/conf/node-daemon.yml
65+
66+
# Install ECK
67+
[ -f $pwd/conf/crds.yaml ] || \
68+
curl https://download.elastic.co/downloads/eck/$eck_version/crds.yaml --output $pwd/conf/crds.yaml
69+
kubectl create -f $pwd/conf/crds.yaml
70+
71+
[ -f $pwd/conf/operator.yaml ] || \
72+
curl https://download.elastic.co/downloads/eck/$eck_version/operator.yaml --output $pwd/conf/operator.yaml
73+
kubectl apply -f $pwd/conf/operator.yaml
74+
75+
# create storage class
76+
kubectl create -f $pwd/conf/storage.yml
77+
78+
## make it default
79+
80+
# 1. switch default class to false
81+
#kubectl patch storageclass standard \
82+
#-p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"false"}}}'
83+
84+
# 2. switch the default class to true for custom storage class
85+
#kubectl patch storageclass dingo-pdssd \
86+
#-p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
87+
}
88+
89+
__init_gcp_credentials() {
90+
# FIXME: you may want a minimum privilege service account here just for GCS
91+
[ -f $pwd/conf/gcs.client.default.credentials_file ] || \
92+
cp $GOOGLE_APPLICATION_CREDENTIALS $pwd/conf/gcs.client.default.credentials_file
93+
94+
# Optional: setup a GCP service account that can manipulate GCS for snapshots
95+
kubectl create secret generic gcs-credentials \
96+
--from-file=$pwd/conf/gcs.client.default.credentials_file
97+
}
98+
99+
__deploy_elastic() {
100+
__init_gcp_credentials
101+
102+
kubectl apply -f $pwd/templates/es.demo.yml
103+
kubectl apply -f $pwd/templates/kbn.demo.yml
104+
}
105+
106+
__deploy_demo() {
107+
__create_gke
108+
109+
__deploy_elastic
110+
}
111+
112+
__password() {
113+
# kubectl get secret ${es_cluster_name}-es-elastic-user -o=jsonpath='{.data.elastic}' | base64 --decode
114+
kubectl get secret ${es_cluster_name}-es-elastic-user -o go-template='{{.data.elastic | base64decode}}'
115+
}
116+
117+
__password_reset() {
118+
kubectl delete secret ${es_cluster_name}-es-elastic-user
119+
}
120+
121+
__status() {
122+
passwd=$(__password)
123+
lb_ip=`kubectl get services ${es_cluster_name}-es-http -o jsonpath='{.status.loadBalancer.ingress[0].ip}'`
124+
125+
#curl -u "elastic:$passwd" -k "https://$lb_ip:9200"
126+
127+
kbn_ip=`kubectl get service dingo-demo-kbn-kb-http -o jsonpath='{.status.loadBalancer.ingress[0].ip}'`
128+
kbn_port=5601
129+
kbn_url=https://${kbn_ip}:${kbn_port}
130+
131+
echo; echo "================================="
132+
echo "Access Kibana at: " ${kbn_url}
133+
echo "Username: " elastic
134+
echo "Password: " ${passwd}
135+
echo "================================="; echo
136+
}
137+
138+
__clean() {
139+
echo "Y" | gcloud container clusters delete $cluster_name \
140+
--zone "${region}-a"
141+
}
142+
143+
__main() {
144+
if [ $# -eq 0 ]
145+
then
146+
__deploy_demo
147+
__status
148+
else
149+
case $1 in
150+
password|pwd|pw|p)
151+
__password
152+
;;
153+
pwdreset|pwreset)
154+
__password_reset
155+
;;
156+
status|s)
157+
__status
158+
;;
159+
clean)
160+
__clean
161+
;;
162+
*)
163+
__deploy_demo
164+
__status
165+
;;
166+
esac
167+
fi
168+
}
169+
170+
__main $@

bin/es.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ __init_gcp_credentials() {
1414
# FIXME: you may want a minimum privilege service account here just for GCS
1515
[ -f $pwd/conf/gcs.client.default.credentials_file ] || \
1616
cp $GOOGLE_APPLICATION_CREDENTIALS $pwd/conf/gcs.client.default.credentials_file
17+
18+
# Optional: setup a GCP service account that can manipulate GCS for snapshots
19+
kubectl create secret generic gcs-credentials \
20+
--from-file=$pwd/conf/gcs.client.default.credentials_file
1721
}
1822

1923
__deploy() {

bin/gke.sh

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ pwd=`pwd`
66
cluster_name=elk
77
region=asia-east1
88
# zone=asia-east1-a
9-
project_id=google.com:bin-wus-learning-center
9+
project_id=du-hast-mich
1010
default_pool=default-pool
11-
nodes_per_zone=5 # per zone
11+
nodes_per_zone=6 # per zone
1212
machine_type=n2-standard-8
1313
release_channel=None # None -> static, e.g. rapid, regular, stable
14-
gke_version=1.23.5-gke.2400
14+
gke_version=1.23.6-gke.1500
1515
eck_version=2.2.0
1616
__usage() {
1717
echo "Usage: ./bin/gke.sh {create|(delete,del,d)|scale|fix}"
@@ -30,13 +30,14 @@ __create() {
3030
--release-channel "${release_channel}" \
3131
--cluster-version "${gke_version}" \
3232
--machine-type "$machine_type" \
33-
--image-type "COS" \
33+
--image-type "COS_CONTAINERD" \
3434
--disk-type "pd-ssd" \
35-
--disk-size "100" \
35+
--disk-size "32" \
3636
--metadata disable-legacy-endpoints=true \
3737
--scopes "https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" \
3838
--num-nodes "$nodes_per_zone" \
39-
--enable-stackdriver-kubernetes \
39+
--logging=SYSTEM,WORKLOAD \
40+
--monitoring=SYSTEM,WORKLOAD \
4041
--enable-ip-alias \
4142
--network "projects/${project_id}/global/networks/default" \
4243
--subnetwork "projects/${project_id}/regions/$region/subnetworks/default" \
@@ -85,10 +86,6 @@ __init() {
8586
# 2. switch the default class to true for custom storage class
8687
#kubectl patch storageclass dingo-pdssd \
8788
#-p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
88-
89-
# Optional: setup a GCP service account that can manipulate GCS for snapshots
90-
kubectl create secret generic gcs-credentials \
91-
--from-file=$pwd/conf/gcs.client.default.credentials_file
9289
}
9390

9491
__add_preemptible_pool() {

templates/apm.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: ApmServer
33
metadata:
44
name: dingo-apm
55
spec:
6-
version: 8.1.3
6+
version: 8.2.1
77
count: 1
88
elasticsearchRef:
99
name: dingo

templates/es.all_role.yml

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ kind: Elasticsearch
33
metadata:
44
name: dingo
55
spec:
6-
version: 8.1.3
6+
version: 8.2.1
77
#http:
88
#service:
99
#spec:
@@ -14,16 +14,13 @@ spec:
1414
- name: zone-a
1515
count: 2
1616
config:
17-
node.master: true
18-
node.data: true
19-
node.ingest: true
20-
node.ml: true
17+
node.roles: [ master, data, ingest, ml, remote_cluster_client, transform ]
2118
xpack.ml.enabled: true
2219
node.store.allow_mmap: true
2320
index.store.type: hybridfs
2421
cluster.routing.allocation.awareness.attributes: zone
2522
node.attr.zone: asia-east1-a
26-
cluster.remote.connect: true
23+
#node.remote_cluster_client: true
2724
xpack.security.authc.anonymous.roles: monitoring_user
2825
volumeClaimTemplates:
2926
- metadata:
@@ -104,16 +101,13 @@ spec:
104101
- name: zone-b
105102
count: 2
106103
config:
107-
node.master: true
108-
node.data: true
109-
node.ingest: true
110-
node.ml: true
104+
node.roles: [ master, data, ingest, ml, remote_cluster_client, transform ]
111105
xpack.ml.enabled: true
112106
node.store.allow_mmap: true
113107
index.store.type: hybridfs
114108
cluster.routing.allocation.awareness.attributes: zone
115109
node.attr.zone: asia-east1-b
116-
cluster.remote.connect: true
110+
#node.remote_cluster_client: true
117111
xpack.security.authc.anonymous.roles: monitoring_user
118112
volumeClaimTemplates:
119113
- metadata:

templates/es.demo.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
apiVersion: elasticsearch.k8s.elastic.co/v1
2+
kind: Elasticsearch
3+
metadata:
4+
name: dingo-demo
5+
spec:
6+
version: 8.2.1
7+
#http:
8+
#service:
9+
#spec:
10+
#type: LoadBalancer
11+
secureSettings:
12+
- secretName: gcs-credentials
13+
nodeSets:
14+
- name: zone-a
15+
count: 3
16+
config:
17+
node.roles: [ master, data, ingest, ml, remote_cluster_client, transform ]
18+
xpack.ml.enabled: true
19+
node.store.allow_mmap: true
20+
index.store.type: hybridfs
21+
cluster.routing.allocation.awareness.attributes: zone
22+
node.attr.zone: asia-east1-a
23+
#node.remote_cluster_client: true
24+
xpack.security.authc.anonymous.roles: monitoring_user
25+
volumeClaimTemplates:
26+
- metadata:
27+
name: elasticsearch-data
28+
spec:
29+
accessModes:
30+
- ReadWriteOnce
31+
resources:
32+
requests:
33+
storage: 256Gi
34+
storageClassName: dingo-pdssd-balanced
35+
podTemplate:
36+
metadata:
37+
labels:
38+
ingest: "on"
39+
coord: "on"
40+
spec:
41+
containers:
42+
- name: elasticsearch
43+
resources:
44+
requests:
45+
memory: 5Gi
46+
cpu: 1200m
47+
limits:
48+
memory: 5Gi
49+
cpu: 1200m
50+
env:
51+
- name: ES_JAVA_OPTS
52+
value: "-Xms3g -Xmx3g"
53+
- name: PRE_STOP_MAX_WAIT_SECONDS
54+
value: "20"
55+
- name: PRE_STOP_ADDITIONAL_WAIT_SECONDS
56+
value: "30"
57+
- name: READINESS_PROBE_TIMEOUT
58+
value: "10"
59+
readinessProbe:
60+
exec:
61+
command:
62+
- bash
63+
- -c
64+
- /mnt/elastic-internal/scripts/readiness-probe-script.sh
65+
failureThreshold: 3
66+
initialDelaySeconds: 10
67+
periodSeconds: 12
68+
successThreshold: 1
69+
timeoutSeconds: 12
70+
initContainers:
71+
#- name: sysctl
72+
#securityContext:
73+
#priviledged: true
74+
#command: ['sh', '-c', 'sysctl -w vm.max_map_count=262144']
75+
- name: install-plugins
76+
command:
77+
- sh
78+
- -c
79+
- |
80+
bin/elasticsearch-plugin install --batch repository-gcs
81+
#- name: install-ik
82+
# command:
83+
# - sh
84+
# - -c
85+
# - |
86+
# bin/elasticsearch-plugin install --batch https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v8.3.1/elasticsearch-analysis-ik-8.3.1.zip
87+
nodeSelector:
88+
cloud.google.com/gke-nodepool: default-pool
89+
affinity:
90+
podAntiAffinity:
91+
preferredDuringSchedulingIgnoredDuringExecution:
92+
- weight: 100
93+
podAffinityTerm:
94+
labelSelector:
95+
matchLabels:
96+
elasticsearch.k8s.elastic.co/cluster-name: dingo-demo
97+
topologyKey: kubernetes.io/hostname

0 commit comments

Comments
 (0)