Clean Code

This commit is contained in:
dsk-minchulahn
2023-12-19 13:03:29 +09:00
parent 947561ce1d
commit 0273450ff6
4237 changed files with 0 additions and 7447 deletions

View File

@@ -0,0 +1,193 @@
*기준 시간 : 2023.05.30 17:14:05
# dsk-iac
aws 환경 구축 시 사용하는 파일을 정리한다.
## directory 구조
1. __docs: 문서파일 저장.
2. architecture : aws 구성도
3. kops: aws kubernetes cluster 구성
4. packer: aws ami 생성
5. script: lambda 실행, key 배포 등 스크립트
6. terraform: terraform code
## 노드 목록 [26]
| name | ip | taints_key | instance_group | cpu | memory | zone | instance_type | os | k8s_ver | runtime_ver |
|---------------------|------------------|---------------------------------------|----------------------------|-----|--------|-----------------|---------------|--------------------|---------|--------------------|
| i-04abf3bdccadaf05c | 172.24.13.138/23 | - | k8s-prod-tmp | 8 | 32 | ap-northeast-2c | m5a.2xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-05a497c27d7f65d78 | 172.24.12.22/23 | control-plane | - | 2 | 4 | ap-northeast-2c | c5a.large | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0446ae551deac0b98 | 172.24.8.218/23 | control-plane | - | 2 | 4 | ap-northeast-2a | c5a.large | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0648e1521b484fde1 | 172.24.11.188/23 | control-plane | - | 2 | 4 | ap-northeast-2b | c5a.large | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-07aebcfff479c0332 | 172.24.12.210/23 | prod/data-druid | k8s-prod-data-druid-small | 4 | 16 | ap-northeast-2c | m6i.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0a36b91bce0b86b6f | 172.24.12.142/23 | prod/data-druid | k8s-prod-data-druid-c | 16 | 64 | ap-northeast-2c | m5a.4xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-07046cde77753a2d4 | 172.24.12.252/23 | prod/data-druid | k8s-prod-data-druid-c | 16 | 64 | ap-northeast-2c | m5a.4xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0c370e3211468e6e5 | 172.24.12.96/23 | prod/data-druid | k8s-prod-data-druid-middle | 8 | 32 | ap-northeast-2c | m5a.2xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0f2de40153ccd640e | 172.24.13.2/23 | prod/data-druid | k8s-prod-data-druid-middle | 8 | 32 | ap-northeast-2c | m5a.2xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0df4bd76188c35590 | 172.24.13.100/23 | prod/data-es | k8s-prod-data-es-c3 | 4 | 16 | ap-northeast-2c | m6i.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0fd0e6d60f02a7b14 | 172.24.13.29/23 | prod/data-es | k8s-prod-data-es-c2 | 4 | 16 | ap-northeast-2c | m5a.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-06e3ca9b0a909e7bd | 172.24.13.64/23 | prod/data-es | k8s-prod-data-es-c | 4 | 16 | ap-northeast-2c | m5a.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-092354f3890ecf207 | 172.24.13.215/23 | prod/data-kafka | k8s-prod-data-kafka-c2 | 4 | 16 | ap-northeast-2c | m5a.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0a6a549b5bf51efbc | 172.24.12.207/23 | prod/data-kafka | k8s-prod-data-kafka-c | 4 | 16 | ap-northeast-2c | m5a.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0097ed484d8513a71 | 172.24.12.66/23 | prod/data-kafka | k8s-prod-data-kafka-c3 | 4 | 16 | ap-northeast-2c | m5a.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0b38484102aa244e8 | 172.24.13.227/23 | prod/druid-middlemanager | k8s-prod-data-druid-large | 16 | 63 | ap-northeast-2c | m5.4xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-07fd9c87549c8ca0c | 172.24.12.112/23 | prod/druid-middlemanager | k8s-prod-data-druid-large | 16 | 64 | ap-northeast-2c | m5a.4xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-00fdae3a253e720bf | 172.24.12.227/23 | prod/process | k8s-prod-process-c | 4 | 16 | ap-northeast-2c | m5a.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0abc091cf1fc5084f | 172.24.12.23/23 | prod/process | k8s-prod-process-c4 | 4 | 16 | ap-northeast-2c | m5a.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-01da83c436c0fb834 | 172.24.13.47/23 | prod/process | k8s-prod-process-c2 | 4 | 16 | ap-northeast-2c | m6i.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-08cea9eddc5260b4d | 172.24.13.119/23 | prod/process | k8s-prod-process-c2 | 4 | 16 | ap-northeast-2c | m6i.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0d3e74b8884948aa3 | 172.24.13.32/23 | prod/process | k8s-prod-process-c | 4 | 16 | ap-northeast-2c | m5a.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0f5d94fbedf1127a7 | 172.24.12.78/23 | prod/rel-process | k8s-rel-process-c | 4 | 16 | ap-northeast-2c | m5zn.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-0746bcd96a3da0c7a | 172.24.13.226/23 | prod/rel-process | k8s-rel-process-c | 4 | 16 | ap-northeast-2c | m5zn.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-056794363777f0364 | 172.24.12.49/23 | prod/rel-process | k8s-rel-process-c | 4 | 16 | ap-northeast-2c | m5d.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
| i-001b5a37f8c2e6483 | 172.24.13.207/23 | prod/rel-process | k8s-rel-process-c | 4 | 16 | ap-northeast-2c | m5d.xlarge | Ubuntu 20.04.4 LTS | v1.25.2 | containerd://1.6.8 |
## 리소스 목록 [91]
| name | kind | count | reqeust_cpu | reqeust_mem | limit_cpu | limit_mem |
|------------------------------------------------------|--------------|-------|-------------|-------------|-----------|-----------|
| dsk-base-agent | DaemonSet | 26 | 50m | 128Mi | 100m | 250Mi |
| promtail | DaemonSet | 26 | <null> | <null> | <null> | <null> |
| dsk-log-agent | DaemonSet | 21 | 250m | 512Mi | 500m | 1G |
| prometheus-prometheus-node-exporter | DaemonSet | 26 | <null> | <null> | <null> | <null> |
| aws-cloud-controller-manager | DaemonSet | 3 | 200m | <null> | <null> | <null> |
| dsk-trace-agent | DaemonSet | 26 | <null> | <null> | <null> | <null> |
| calico-node | DaemonSet | 26 | 100m | <null> | <null> | <null> |
| kops-controller | DaemonSet | 3 | 50m | 50Mi | <null> | <null> |
| ebs-csi-node | DaemonSet | 26 | <null> | <null> | <null> | <null> |
| ingress-nginx-controller | DaemonSet | 7 | 100m | 90Mi | <null> | <null> |
| es-log-collector | DaemonSet | 4 | 10m | 20Mi | 50m | 50Mi |
| dsk-kubernetes-agent | Deployment | 1 | 100m | 512Mi | 1 | 1000Mi |
| dsk-otel | Deployment | 1 | 250m | 512M | 1 | 2048M |
| dsk-postgres-agents-pg-1 | Deployment | 1 | 100m | 512Mi | 1 | 1000Mi |
| dsk-vault-agent | Deployment | 1 | <null> | <null> | <null> | <null> |
| ebs-csi-controller | Deployment | 2 | <null> | <null> | <null> | <null> |
| prod-dsk-metric-base-flat-stream | Deployment | 4 | 500m | 500Mi | 1 | 1Gi |
| calico-kube-controllers | Deployment | 1 | <null> | <null> | <null> | <null> |
| cert-manager | Deployment | 1 | <null> | <null> | <null> | <null> |
| cert-manager-cainjector | Deployment | 1 | <null> | <null> | <null> | <null> |
| cert-manager-webhook | Deployment | 1 | <null> | <null> | <null> | <null> |
| coredns | Deployment | 2 | 100m | 70Mi | <null> | 170Mi |
| coredns-autoscaler | Deployment | 1 | 20m | 10Mi | <null> | <null> |
| dns-controller | Deployment | 1 | 50m | 50Mi | <null> | <null> |
| druid-broker | Deployment | 2 | <null> | 26Gi | <null> | 26Gi |
| druid-coordinator | Deployment | 1 | <null> | 1Gi | <null> | 8Gi |
| druid-router | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-log-api | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-loggate | Deployment | 4 | 100m | 500Mi | 200m | 1500Mi |
| prod-dsk-metric-base-agg-stream-1m | Deployment | 3 | 500m | 1Gi | 1 | 2Gi |
| prod-dsk-metric-base-agg-stream-5m | Deployment | 3 | 500m | 1Gi | 1 | 2Gi |
| prod-dsk-metric-custom-flat-stream | Deployment | 3 | <null> | <null> | <null> | <null> |
| prod-dsk-notification-api | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-tagging-connector-group1 | Deployment | 1 | 500m | 512Mi | 1 | 1Gi |
| prod-dsk-tagging-connector-group2 | Deployment | 1 | 500m | 512Mi | 1 | 1Gi |
| prod-dsk-tagging-connector-group3 | Deployment | 1 | 500m | 512Mi | 1 | 1Gi |
| prod-dsk-tagging-connector-group4 | Deployment | 1 | 500m | 512Mi | 1 | 1Gi |
| prod-dsk-tagging-connector-jaeger-process | Deployment | 1 | 500m | 512Mi | 1 | 1Gi |
| prod-dsk-tagging-connector-manifest | Deployment | 1 | 500m | 512Mi | 1 | 1Gi |
| prod-dsk-trace-stream | Deployment | 3 | <null> | <null> | <null> | <null> |
| prod-dsk-ui | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-usergate-api | Deployment | 1 | <null> | <null> | <null> | <null> |
| prometheus-kube-state-metrics | Deployment | 1 | 10m | 32Mi | 100m | 64Mi |
| prometheus-prometheus-pushgateway | Deployment | 1 | 100m | 30Mi | 200m | 50Mi |
| prometheus-server | Deployment | 1 | <null> | <null> | <null> | <null> |
| vault-agent-injector | Deployment | 1 | <null> | <null> | <null> | <null> |
| kafka-akhq | Deployment | 1 | <null> | <null> | <null> | <null> |
| kafka-kafka-ui | Deployment | 1 | <null> | <null> | <null> | <null> |
| metrics-server | Deployment | 1 | 100m | 200Mi | <null> | <null> |
| mongo-dsk-mongodb-sharded-mongos | Deployment | 1 | <null> | <null> | <null> | <null> |
| mongo-manifest-mongodb-sharded-mongos | Deployment | 1 | <null> | <null> | <null> | <null> |
| nfs-provisioner-prod-nfs-subdir-external-provisioner | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-agent-api | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-agentmanager-api | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-alert-api | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-apm-api | Deployment | 1 | 100m | 256Mi | 250m | 512Mi |
| prod-dsk-app-sender | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-backoffice | Deployment | 0 | <null> | <null> | <null> | <null> |
| prod-dsk-chart-api | Deployment | 1 | 500m | 512Mi | 1 | 1Gi |
| prod-dsk-dashboard-api | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-database-api | Deployment | 3 | 100m | 256Mi | 250m | 512Mi |
| prod-dsk-database-plan-stream | Deployment | 1 | <null> | <null> | <null> | <null> |
| prod-dsk-datagate-dsk-datagate-manifest | Deployment | 1 | 100m | 100M | 200m | 200M |
| prod-dsk-datagate-dsk-datagate-metric | Deployment | 5 | 250m | 250M | 500m | 500M |
| prod-dsk-datagate-dsk-datagate-plan | Deployment | 1 | 100m | 100M | 250m | 250M |
| prod-dsk-datagate-dsk-datagate-trace | Deployment | 2 | 100m | 250M | 200m | 500M |
| prod-dsk-infrastructure-api | Deployment | 1 | 100m | 256Mi | 250m | 512Mi |
| prod-dsk-kafka2storage-database-plan-stream | Deployment | 1 | 300m | 500Mi | 500m | 1G |
| prod-dsk-kafka2storage-database-stat-query | Deployment | 1 | 300m | 500Mi | 500m | 1G |
| prod-dsk-kafka2storage-manifest-original | Deployment | 1 | 300m | 500Mi | 500m | 1G |
| prod-dsk-kafka2storage-trace-span-stream | Deployment | 1 | 300m | 500Mi | 500m | 1G |
| prod-dsk-krakend | Deployment | 3 | 200m | 256Mi | 500m | 512Mi |
| elasticsearch-master | Stateful_Set | 3 | 2 | 12Gi | 2 | 12Gi |
| kafka | Stateful_Set | 3 | 2 | 6000Mi | 3 | 10000Mi |
| zookeeper | Stateful_Set | 2 | 100m | 512Mi | 200m | 1000Mi |
| druid-historical | Stateful_Set | 2 | <null> | 26Gi | <null> | 26Gi |
| keycloak | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
| druid-zookeeper | Stateful_Set | 3 | 250m | 256Mi | <null> | <null> |
| rabbitmq | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
| mongo-dsk-mongodb-sharded-configsvr | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
| prometheus-alertmanager | Stateful_Set | 1 | 10m | 32Mi | 100m | 128Mi |
| mongo-dsk-mongodb-sharded-shard0-data | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
| mongo-dsk-mongodb-sharded-shard1-data | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
| mongo-manifest-mongodb-sharded-configsvr | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
| redis-master | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
| mongo-manifest-mongodb-sharded-shard0-data | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
| mongo-manifest-mongodb-sharded-shard1-data | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
| druid-middle-manager | Stateful_Set | 2 | <null> | 1Gi | <null> | 60Gi |
| postgresql | Stateful_Set | 1 | 250m | 256Mi | <null> | <null> |
| druid-postgresql | Stateful_Set | 1 | 250m | 256Mi | <null> | <null> |
| vault | Stateful_Set | 1 | <null> | <null> | <null> | <null> |
## 서비스 목록 (NodePort) [33]
| name | namespace | type | node_port | age |
|-----------------------------------------|-------------------|----------|-----------|-------------------------|
| rabbitmq | dsk-middle | NodePort | 30038 | 5 mons 17 days 01:30:35 |
| kafka-broker | dsk-middle | NodePort | 30094 | 3 mons 8 days 23:00:58 |
| kafka-broker-global | dsk-middle | NodePort | 30095 | 3 mons 8 days 23:00:58 |
| keycloak | dsk-middle | NodePort | 30100 | 5 mons 15 days 01:32:43 |
| keycloak | dsk-middle | NodePort | 30101 | 5 mons 15 days 01:32:43 |
| mongo-manifest-mongodb-sharded | dsk-middle | NodePort | 30111 | 1 mon 16:25:57 |
| mongo-dsk-mongodb-sharded | dsk-middle | NodePort | 30112 | 1 mon 15:13:17 |
| redis-master | dsk-middle | NodePort | 30229 | 5 mons 17 days 01:30:22 |
| elasticsearch-master | dsk-middle | NodePort | 30433 | 27 days 03:11:32 |
| rabbitmq | dsk-middle | NodePort | 30523 | 5 mons 17 days 01:30:35 |
| rabbitmq | dsk-middle | NodePort | 30565 | 5 mons 17 days 01:30:35 |
| rabbitmq | dsk-middle | NodePort | 30655 | 5 mons 17 days 01:30:35 |
| rabbitmq | dsk-middle | NodePort | 32021 | 5 mons 17 days 01:30:35 |
| kafka-akhq | dsk-middle | NodePort | 32100 | 3 mons 8 days 23:00:58 |
| kafka-kafka-ui | dsk-middle | NodePort | 32101 | 3 mons 8 days 23:00:58 |
| elasticsearch-master | dsk-middle | NodePort | 32110 | 27 days 03:11:32 |
| prometheus-server | prometheus | NodePort | 32132 | 18 days 00:15:23 |
| prometheus-alertmanager | prometheus | NodePort | 32133 | 18 days 00:15:23 |
| prod-dsk-datagate-dsk-datagate-trace | dsk-datagate-prod | NodePort | 32300 | 4 mons 11 days 22:25:44 |
| prod-dsk-datagate-dsk-datagate-manifest | dsk-datagate-prod | NodePort | 32301 | 4 mons 23 days 23:41:29 |
| prod-dsk-datagate-dsk-datagate-metric | dsk-datagate-prod | NodePort | 32302 | 4 mons 23 days 23:41:29 |
| prod-dsk-datagate-dsk-datagate-plan | dsk-datagate-prod | NodePort | 32303 | 4 mons 23 days 23:41:29 |
| prod-dsk-loggate | dsk-datagate-prod | NodePort | 32304 | 4 mons 17 days 23:55:18 |
| prod-dsk-loggate | dsk-datagate-prod | NodePort | 32305 | 4 mons 17 days 23:55:18 |
| prod-dsk-backoffice | dsk-api-prod | NodePort | 32523 | 1 mon 24 days 05:37:14 |
| rabbitmq | dsk-middle | NodePort | 32987 | 5 mons 17 days 01:30:35 |
| postgresql | dsk-middle | NodePort | 32098 | 5 mons 17 days 01:30:58 |
| kafka-outside-0 | dsk-middle | NodePort | 32400 | 3 mons 8 days 23:00:58 |
| kafka-outside-1 | dsk-middle | NodePort | 32401 | 3 mons 8 days 23:00:58 |
| kafka-outside-2 | dsk-middle | NodePort | 32402 | 3 mons 8 days 23:00:58 |
| kafka-global-0 | dsk-middle | NodePort | 32500 | 3 mons 8 days 23:00:58 |
| kafka-global-1 | dsk-middle | NodePort | 32501 | 3 mons 8 days 23:00:58 |
| kafka-global-2 | dsk-middle | NodePort | 32502 | 3 mons 8 days 23:00:58 |
## 예약 인스턴스 사용 내역 [11]
| availability_zone | instance_type | ri_count | ec2_count | result |
|-------------------|---------------|----------|-----------|--------|
| ap-northeast-2a | c5a.large | 1 | 1 | 0 |
| ap-northeast-2a | t3.small | 2 | 1 | -1 |
| ap-northeast-2b | c5a.large | 1 | 1 | 0 |
| ap-northeast-2c | c5a.large | 1 | 1 | 0 |
| ap-northeast-2c | m5.4xlarge | 0 | 1 | 1 |
| ap-northeast-2c | m5a.2xlarge | 1 | 3 | 2 |
| ap-northeast-2c | m5a.4xlarge | 1 | 3 | 2 |
| ap-northeast-2c | m5a.xlarge | 7 | 8 | 1 |
| ap-northeast-2c | m6i.xlarge | 4 | 4 | 0 |
| ap-northeast-2c | t3.small | 1 | 1 | 0 |

View File

@@ -0,0 +1,11 @@
# dsk-iac
aws 환경 구축 시 사용하는 파일을 정리한다.
## directory 구조
1. __docs: 문서파일 저장.
2. architecture : aws 구성도
3. kops: aws kubernetes cluster 구성
4. packer: aws ami 생성
5. script: lambda 실행, key 배포 등 스크립트
6. terraform: terraform code

View File

@@ -0,0 +1,207 @@
#!/bin/bash
#------------------------------------------------------------------------------------------------------
__init (){
# pwd
# cd ${git_path}
# pwd
cd /home/jhjung/git/dsk-iac/scripts/steampipe_iac/
git pull
datetime=`date "+%Y.%m.%d %H:%M:%S"`
echo -e "*기준 시간 : ${datetime}\n" > ${file}
cat ${origin} >> ${file}
}
#------------------------------------------------------------------------------------------------------
__git_push (){
git add ${file}
git commit -m 'steampipe schedule'
git push
}
#------------------------------------------------------------------------------------------------------
__append (){
line_count=`cat ${exec_log} | grep -v -- -- | egrep -v '(name|ri_count)' | wc -l`
echo -e "\n${title} [${line_count}]\n" >> ${file}
cat ${exec_log} >> ${file}
}
#------------------------------------------------------------------------------------------------------
__query_exec (){
steampipe query "${1}" > ${exec_log}
__log_sed
}
#------------------------------------------------------------------------------------------------------
__log_sed (){
sed -i 's/+/|/g' ${exec_log}
sed -i "s/node-role.kubernetes.io\///g" ${exec_log}
sed -i '1d;$d' ${exec_log}
}
#------------------------------------------------------------------------------------------------------
node_query="""
SELECT
name,
annotations ->> 'projectcalico.org/IPv4Address' AS IP,
COALESCE(taints -> 0 ->> 'key', '-') AS Taints_key,
COALESCE(tags ->> 'kops.k8s.io/instancegroup', '-') AS Instance_group,
capacity ->> 'cpu' AS CPU,
CEIL((CAST(regexp_replace(capacity ->> 'memory', 'Ki', '') AS FLOAT) / 1024 / 1024)) AS Memory,
tags ->> 'topology.kubernetes.io/zone' AS Zone,
tags ->> 'beta.kubernetes.io/instance-type' AS Instance_type,
node_info ->> 'osImage' AS OS,
node_info ->> 'kubeletVersion' AS K8S_ver,
node_info ->> 'containerRuntimeVersion' AS Runtime_ver
FROM
kubernetes_node
ORDER BY
Taints_key
"""
resources_query="""
(SELECT
'sts' as kind,
name,
available_replicas as count,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'requests' ->> 'cpu' AS request_cpu,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'requests' ->> 'memory' AS request_mem,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'limits' ->> 'cpu' AS limit_cpu,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'limits' ->> 'memory' AS limit_mem,
jsonb_array_elements(template -> 'spec' -> 'containers') ->> 'name' AS c_name,
namespace
FROM
kubernetes_stateful_set
WHERE
name not like 'rel-%')
union
(SELECT
'deploy' as kind,
name,
available_replicas as count,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'requests' ->> 'cpu' AS request_cpu,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'requests' ->> 'memory' AS request_mem,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'limits' ->> 'cpu' AS limit_cpu,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'limits' ->> 'memory' AS limit_mem,
jsonb_array_elements(template -> 'spec' -> 'containers') ->> 'name' AS c_name,
namespace
FROM
kubernetes_deployment
WHERE
name not like 'rel-%')
union
(SELECT
'ds' as kind,
name,
number_available as count,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'requests' ->> 'cpu' AS request_cpu,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'requests' ->> 'memory' AS request_mem,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'limits' ->> 'cpu' AS limit_cpu,
jsonb_array_elements(template -> 'spec' -> 'containers') -> 'resources' -> 'limits' ->> 'memory' AS limit_mem,
jsonb_array_elements(template -> 'spec' -> 'containers') ->> 'name' AS c_name,
namespace
FROM
kubernetes_daemonset
WHERE
name not like 'rel-%')
order by kind
"""
service_query="""
SELECT
name,
namespace,
type,
lower(p ->> 'nodePort') as Node_Port,
age(current_timestamp, creation_timestamp)
FROM
kubernetes_service,
jsonb_array_elements(ports) as p
WHERE
type='NodePort'
ORDER BY
Node_Port
"""
#name not like '%rel-%'
aws_ri_query="""
SELECT
COALESCE(a.availability_zone, b.availability_zone, '-') AS availability_zone,
COALESCE(a.instance_type, b.instance_type, c.instance_type, '-') AS instance_type,
COALESCE(c.cpu, 0) AS cpu,
COALESCE(c.memory, 0) AS memory,
COALESCE(a.ri_count, 0) AS ri_count,
COALESCE(b.ec2_count, 0) AS ec2_count,
COALESCE(b.ec2_count, 0) - COALESCE(a.ri_count, 0) AS result
FROM
(SELECT
availability_zone,
instance_type,
SUM(instance_count) AS ri_count
FROM
aws_ec2_reserved_instance
WHERE
instance_state='active'
GROUP BY
availability_zone,
instance_type
) a
FULL OUTER JOIN
(SELECT
placement_availability_zone AS availability_zone,
instance_type,
COUNT(*) AS ec2_count
FROM
aws_ec2_instance
WHERE
instance_state='running' AND
instance_lifecycle!='spot'
GROUP BY
availability_zone,
instance_type
) b
ON
a.availability_zone = b.availability_zone AND
a.instance_type = b.instance_type
INNER JOIN
(SELECT
instance_type,
(CAST(memory_info ->> 'SizeInMiB' AS FLOAT) / 1024) AS memory,
(CAST(v_cpu_info ->> 'DefaultCores' AS FLOAT) * 2) AS cpu
FROM
aws_ec2_instance_type
WHERE
instance_type in (SELECT instance_type FROM aws_ec2_instance WHERE instance_state='running')
GROUP BY
instance_type, memory, cpu
) c
ON
COALESCE(a.instance_type, b.instance_type, '-') = c.instance_type
ORDER BY availability_zone
"""
#instance_type in (SELECT instance_type FROM aws_ec2_instance WHERE instance_state='running' AND instance_lifecycle!='spot')
#------------------------------------------------------------------------------------------------------
#git_path="/home/jhjung/git/dsk-iac"
origin="org_README.md"
exec_log="query.log"
file="../../README.md"
#------------------------------------------------------------------------------------------------------
__init
title="## 노드 목록"
__query_exec "${node_query}"
__append
title="## 리소스 목록"
__query_exec "${resources_query}"
__append
title="## 서비스 목록 (NodePort)"
__query_exec "${service_query}"
__append
title="## 예약 인스턴스 사용 내역"
__query_exec "${aws_ri_query}"
__append
#------------------------------------------------------------------------------------------------------
rm ${exec_log}
__git_push