-
Notifications
You must be signed in to change notification settings - Fork 183
/
install-metrics.sh
175 lines (159 loc) · 5.1 KB
/
install-metrics.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
#!/usr/bin/env bash
export CLUSTER=sumologic-demo
export PROFILE_NAME=sumologic
export NAMESPACE=sumologic
export AWS_REGION=us-east-2
export HELM_INSTALLATION_NAME=collection
export SG_NAME=sumologic-collection
export METRIC_PODS=10
## Set up Fargate Profile for Sumo Logic namespace
eksctl create fargateprofile \
--cluster "${CLUSTER}" \
--name "${PROFILE_NAME}" \
--namespace "${NAMESPACE}"
## Create EFS Volume
export EFS_ID="$(
aws efs describe-file-systems \
--region="${AWS_REGION}" | \
jq '.FileSystems[] |
select(.Tags[].Key == "Name" and .Tags[].Value == "SumologicCollectionVolumes") |
.FileSystemId' \
--raw-output)"
if [[ -z "${EFS_ID}" ]]; then
aws efs create-file-system \
--encrypted \
--performance-mode generalPurpose \
--throughput-mode bursting \
--tags Key=Name,Value=SumologicCollectionVolumes \
--region "${AWS_REGION}"
export EFS_ID="$(
aws efs describe-file-systems \
--region="${AWS_REGION}" | \
jq '.FileSystems[] |
select(.Tags[].Key == "Name" and .Tags[].Value == "SumologicCollectionVolumes") |
.FileSystemId' \
--raw-output)"
fi
## Create EFS access points for metric Pods
for (( counter=0; counter<METRIC_PODS; counter++ )); do
FSAP_ID="$(
aws efs describe-access-points \
--region "${AWS_REGION}" |
jq ".AccessPoints[] |
select(.RootDirectory.Path == \"/sumologic/file-storage-${HELM_INSTALLATION_NAME}-sumologic-otelcol-metrics-${counter}\") |
.AccessPointId" \
--raw-output)" || true
if [[ -z "${FSAP_ID}" ]]; then
aws efs create-access-point \
--file-system-id "${EFS_ID}" \
--posix-user Uid=1000,Gid=1000 \
--root-directory "Path=/${NAMESPACE}/file-storage-${HELM_INSTALLATION_NAME}-sumologic-otelcol-metrics-${counter},CreationInfo={OwnerUid=1000,OwnerGid=1000,Permissions=777}" \
--region "${AWS_REGION}"
fi
done
## Create a security group to be used with mount targets
export VPC_ID="$(
aws ec2 describe-vpcs \
--region "${AWS_REGION}" | \
jq ".Vpcs[] |
select(.Tags[]=={\"Key\": \"alpha.eksctl.io/cluster-name\", \"Value\": \"${CLUSTER}\"}) |
.VpcId" \
--raw-output)"
aws ec2 create-security-group \
--description "Sumo Logic Collection for Fargate" \
--group-name "${SG_NAME}" \
--vpc-id "${VPC_ID}" \
--region "${AWS_REGION}"
export SG_ID="$(
aws ec2 describe-security-groups \
--region "${AWS_REGION}" | \
jq ".SecurityGroups[] |
select(.GroupName == \"${SG_NAME}\") |
.GroupId" \
--raw-output)"
## Authorize ingress for security group
export CIDR_BLOCK="$(
aws ec2 describe-vpcs \
--region "${AWS_REGION}" | \
jq ".Vpcs[] |
select(.VpcId == \"${VPC_ID}\") |
.CidrBlock" \
--raw-output)"
aws ec2 authorize-security-group-ingress \
--group-id "${SG_ID}" \
--protocol tcp \
--port 2049 \
--region "${AWS_REGION}" \
--cidr "${CIDR_BLOCK}"
## Create mount targets for each pair of EFS access point and subnet
export SUBNETS="$(
aws ec2 describe-subnets \
--region "${AWS_REGION}" | \
jq ".Subnets[] |
select(.Tags[]=={\"Key\": \"alpha.eksctl.io/cluster-name\", \"Value\": \"${CLUSTER}\"}) |
.SubnetId" \
--raw-output)"
for subnet in ${SUBNETS}; do
aws efs create-mount-target \
--file-system-id "${EFS_ID}" \
--subnet-id "${subnet}" \
--security-group "${SG_ID}" \
--region "${AWS_REGION}"
done
## Create `sumo-metrics-pvc.yaml` with PVC per access point
echo "---
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: efs-sc
provisioner: efs.csi.aws.com
volumeBindingMode: Immediate" | tee sumo-metrics-pvc.yaml
for (( counter=0; counter<METRIC_PODS; counter++ )); do
FSAP_ID="$(
aws efs describe-access-points \
--region "${AWS_REGION}" | \
jq ".AccessPoints[] |
select(.RootDirectory.Path == \"/${NAMESPACE}/file-storage-${HELM_INSTALLATION_NAME}-sumologic-otelcol-metrics-${counter}\") |
.AccessPointId" \
--raw-output)" || true
echo "---
apiVersion: v1
kind: PersistentVolume
metadata:
name: file-storage-${HELM_INSTALLATION_NAME}-sumologic-otelcol-metrics-${counter}
labels:
app: ${HELM_INSTALLATION_NAME}-sumologic-otelcol-metrics
spec:
capacity:
storage: 10Gi
volumeMode: Filesystem
accessModes:
- ReadWriteMany
persistentVolumeReclaimPolicy: Retain
storageClassName: efs-sc
claimRef:
namespace: ${NAMESPACE}
name: file-storage-${HELM_INSTALLATION_NAME}-sumologic-otelcol-metrics-${counter}
csi:
driver: efs.csi.aws.com
volumeHandle: ${EFS_ID}::${FSAP_ID}
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: file-storage-${HELM_INSTALLATION_NAME}-sumologic-otelcol-metrics-${counter}
labels:
app: ${HELM_INSTALLATION_NAME}-sumologic-otelcol-metrics
namespace: ${NAMESPACE}
spec:
accessModes:
- ReadWriteMany
storageClassName: efs-sc
resources:
requests:
storage: 5Gi"
done | tee -a sumo-metrics-pvc.yaml
## Create namespace if it doesn't exist already
kubectl create namespace "${NAMESPACE}"
## Apply `sumo-metrics-pvc.yaml`
kubectl apply -f sumo-metrics-pvc.yaml -n "${NAMESPACE}"