-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
143 lines (128 loc) · 4.52 KB
/
Taskfile.yaml
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
# yamllint disable rule:line-length
---
version: '3'
output: prefixed
vars:
CLUSTER_NAME: eck-demo
ELASTIC_NS: elastic-system
KUBECTL_CONTEXT: kind-{{.CLUSTER_NAME}}
ELASTIC_SECRET_NAME: elasticsearch-logs-es-elastic-user
ELASTIC_IMAGE: docker.elastic.co/elasticsearch/elasticsearch:8.4.1
KIBANA_IMAGE: docker.elastic.co/kibana/kibana:8.4.1
ELASTIC_OPERATOR_IMAGE: docker.elastic.co/eck/eck-operator:2.4.0
FILEBEAT_IMAGE: docker.elastic.co/beats/filebeat:8.4.1
tasks:
default:
cmds:
- task: create-cluster
all:
cmds:
- task: test
check-requirements:
preconditions:
- sh: which kind
msg: Kind must be install
- sh: which kubectl
msg: Kubectl must be install
- sh: which helm
msg: Helm must be installed
- sh: which terraform
msg: Terraform must be installed
- sh: which ab
msg: Apache Bench must be install -> sudo apt-get install -y apache2-utils
set-context:
status:
- kubectl config current-context | grep {{.KUBECTL_CONTEXT}}
- kubectl config view --minify -o jsonpath='{..namespace}' | grep {{.ELASTIC_NS}}
- kubectl get pods
preconditions:
- sh: kubectl get pods -n {{.ELASTIC_NS}}
msg: Cannot connect to {{.CLUSTER_NS}} on namespace {{.ELASTIC_NS}}
cmds:
- kubectl config set-context {{.KUBECTL_CONTEXT}} --namespace={{.ELASTIC_NS}}
- kubectl config use-context {{.KUBECTL_CONTEXT}}
create-cluster:
deps:
- check-requirements
status:
- kind get clusters | grep {{.CLUSTER_NAME}}
cmds:
- kind create cluster -n {{.CLUSTER_NAME}} --config kind-config.yaml
- sudo sysctl -w vm.max_map_count=262144
- docker pull {{.ELASTIC_IMAGE}} && kind load docker-image -n {{.CLUSTER_NAME}} {{.ELASTIC_IMAGE}}
- docker pull {{.KIBANA_IMAGE}} && kind load docker-image -n {{.CLUSTER_NAME}} {{.KIBANA_IMAGE}}
- docker pull {{.ELASTIC_OPERATOR_IMAGE}} && kind load docker-image -n {{.CLUSTER_NAME}} {{.ELASTIC_OPERATOR_IMAGE}}
- docker pull {{.FILEBEAT_IMAGE}} && kind load docker-image -n {{.CLUSTER_NAME}} {{.FILEBEAT_IMAGE}}
- task: set-context
- helm repo add metrics-server https://kubernetes-sigs.github.io/metrics-server/
- helm repo update
- helm upgrade --install --set args={--kubelet-insecure-tls} metrics-server metrics-server/metrics-server --namespace kube-system
deploy-operator:
deps:
- create-cluster
status:
- "helm status eck-operator | grep 'STATUS: deployed'"
preconditions:
- sh: kubectl get pods
msg: Cannot connect to kubernetes cluster
cmds:
- helm repo add elastic https://helm.elastic.co
- helm upgrade -i eck-operator elastic/eck-operator -n {{.ELASTIC_NS}} --create-namespace
deploy:
deps:
- deploy-operator
status:
- 02-deploy-elastic-kibana/wait_elastic_ready.sh elasticsearch-logs 5
dir: demo
sources:
- ./kustomization.yaml
- ./02-deploy-elastic-kibana/**
- ./03-deploy-filebeat/**
cmds:
- kubectl apply -k .
- 02-deploy-elastic-kibana/wait_elastic_ready.sh elasticsearch-logs
port-forward:
status:
- curl localhost:9200
- curl https://localhost:5601
cmds:
- kubectl port-forward svc/elasticsearch-logs-es-http 9200:9200 > /dev/null 2>&1 &
- kubectl port-forward svc/kibana-logs-kb-http 5601:5601 > /dev/null 2>&1 &
index-config:
deps:
- deploy
dir: demo/05-terraform-configure-index
status:
- terraform plan | grep "No changes"
sources:
- ./**
env:
ELASTICSEARCH_PASSWORD:
sh: kubectl get secret {{.ELASTIC_SECRET_NAME}} -o jsonpath='{.data.elastic}' | base64 --decode
cmds:
- task: port-forward
- terraform init
- terraform apply --auto-approve
test:
deps:
- index-config
cmds:
- task: port-forward
- ab -n 1000000 -c 20 http://localhost:30000/
terraform-destroy:
dir: demo/05-terraform-configure-index
deps:
- index-config
vars:
ELASTICSEARCH_PASSWORD:
sh: kubectl get secret {{.ELASTIC_SECRET_NAME}} -o jsonpath='{.data.elastic}' | base64 --decode
cmds:
- task: port-forward
- ELASTICSEARCH_PASSWORD={{.ELASTICSEARCH_PASSWORD}} terraform destroy --auto-approve
clean:
dir: demo/05-terraform-configure-index
cmds:
- kind delete cluster -n {{.CLUSTER_NAME}}
- sudo sysctl -w vm.max_map_count=65530
- rm -Rf *.tfstate* .terraform .terraform.lock.hcl
ignore_error: true