Skip to content

Commit

Permalink
Add Blockscout API deployment (#5710)
Browse files Browse the repository at this point in the history
Adds a new deployment for the Blockscout read-only API component.
It is connected to the DB read replica and forwards traffic to both RPC and graphql endpoints to the new component.

Co-authored-by: Javier Cortejoso <javier.cortejoso@gmail.com>
  • Loading branch information
carterqw2 and jcortejoso committed Nov 11, 2020
1 parent 9456881 commit 5f4a62b
Show file tree
Hide file tree
Showing 11 changed files with 192 additions and 2 deletions.
8 changes: 7 additions & 1 deletion packages/helm-charts/blockscout/templates/_helpers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
- name: cloudsql-proxy
image: gcr.io/cloudsql-docker/gce-proxy:1.11
command: ["/cloud_sql_proxy",
"-instances={{ .Values.blockscout.db.connection_name }}=tcp:5432",
"-instances={{ .Values.blockscout.db.connection_name }}{{ .DbSuffix | default "" }}=tcp:5432",
"-credential_file=/secrets/cloudsql/credentials.json"]
resources:
requests:
memory: 500Mi
cpu: 200m
securityContext:
runAsUser: 2 # non-root user
allowPrivilegeEscalation: false
Expand Down Expand Up @@ -52,6 +56,8 @@ volumes:
value: "5432"
- name: WOBSERVER_ENABLED
value: "false"
- name: HEALTHY_BLOCKS_PERIOD
value: {{ .Values.blockscout.healthy_blocks_period | quote }}
- name: MIX_ENV
value: prod
- name: LOGO
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ .Release.Name }}-api
labels:
app: blockscout
chart: blockscout
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
component: blockscout-api-autoscaler
spec:
minReplicas: {{ .Values.blockscout.api.autoscaling.minReplicas }}
maxReplicas: {{ .Values.blockscout.api.autoscaling.maxReplicas }}
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Release.Name }}-api
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.blockscout.api.autoscaling.target.cpu }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Release.Name }}-api
labels:
app: blockscout
chart: blockscout
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
component: blockscout-api
spec:
replicas: 1
selector:
matchLabels:
app: blockscout
release: {{ .Release.Name }}
component: blockscout-api
template:
metadata:
labels:
app: blockscout
release: {{ .Release.Name }}
component: blockscout-api
spec:
containers:
- name: blockscout-api
image: {{ .Values.blockscout.image.repository }}:api-{{ .Values.blockscout.image.tag }}
imagePullPolicy: {{ .Values.imagePullPolicy }}
command:
- /bin/sh
- -c
args:
- |
exec mix cmd --app block_scout_web mix phx.server | sed 's/^iex(1)> //'
ports:
- name: http
containerPort: 4000
resources:
requests:
memory: 500Mi
cpu: 500m
env:
- name: DISABLE_WEBAPP
value: "true"
- name: DISABLE_WRITE_API
value: "true"
- name: DISABLE_INDEXER
value: "true"
- name: POOL_SIZE
value: {{ .Values.blockscout.api.pool_size | quote }}
{{ include "celo.blockscout-env-vars" . | indent 8 }}
{{$data := dict "Values" .Values "DbSuffix" "-replica"}}
{{ include "celo.blockscout-db-sidecar" $data | indent 6 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{- if .Capabilities.APIVersions.Has "networking.k8s.io/v1beta1" }}
apiVersion: networking.k8s.io/v1beta1
{{ else }}
apiVersion: extensions/v1beta1
{{ end -}}
kind: Ingress
metadata:
name: {{ .Release.Name }}-api-ingress
labels:
app: blockscout
chart: blockscout
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
component: blockscout-api-ingress
annotations:
kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/configuration-snippet: |
location ~ /admin/.* {
deny all;
}
spec:
tls:
- hosts:
- {{ .Release.Name }}-api.{{ .Values.domain.name }}.org
secretName: {{ .Release.Name }}-api-tls
rules:
- host: {{ .Release.Name }}-api.{{ .Values.domain.name }}.org
http:
paths:
- path: /
backend:
serviceName: {{ .Release.Name }}-api
servicePort: 4000
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
apiVersion: v1
kind: Service
metadata:
name: {{ .Release.Name }}-api
labels:
app: blockscout
chart: blockscout
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
component: blockscout-api
spec:
selector:
app: blockscout
release: {{ .Release.Name }}
component: blockscout-api
clusterIP: None
ports:
- name: http
port: 4000
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ spec:
env:
- name: DISABLE_WEBAPP
value: "true"
- name: POOL_SIZE
value: {{ .Values.blockscout.indexer.pool_size | quote }}
{{ include "celo.blockscout-env-vars" . | indent 8 }}
{{ include "celo.blockscout-db-sidecar" . | indent 6 }}
{{- with .Values.nodeSelector }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spec:
name: tmp-pod
readOnly: true
- name: metadata-crawler
image: {{ .Values.blockscout.metadata_crawler.image.repository }}:{{ .Values.blockscout.metadata_crawler.repository.tag }}
image: {{ .Values.blockscout.metadata_crawler.image.repository }}:{{ .Values.blockscout.metadata_crawler.image.tag }}
imagePullPolicy: IfNotPresent
command:
- /bin/sh
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ .Release.Name }}-web
labels:
app: blockscout
chart: blockscout
release: {{ .Release.Name }}
heritage: {{ .Release.Service }}
component: blockscout-web-autoscaler
spec:
minReplicas: {{ .Values.blockscout.web.autoscaling.minReplicas }}
maxReplicas: {{ .Values.blockscout.web.autoscaling.maxReplicas }}
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ .Release.Name }}-web
metrics:
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.blockscout.web.autoscaling.target.cpu }}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ spec:
value: "4000"
- name: DISABLE_INDEXER
value: "true"
- name: POOL_SIZE
value: {{ .Values.blockscout.web.pool_size | quote }}
{{ include "celo.blockscout-env-vars" . | indent 8 }}
{{ include "celo.blockscout-db-sidecar" . | indent 6 }}
{{- with .Values.nodeSelector }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ metadata:
heritage: {{ .Release.Service }}
component: blockscout-web-ingress
annotations:
nginx.ingress.kubernetes.io/use-regex: "true"
kubernetes.io/tls-acme: "true"
kubernetes.io/ingress.class: nginx
nginx.ingress.kubernetes.io/configuration-snippet: |
Expand All @@ -31,6 +32,14 @@ spec:
- host: {{ .Release.Name }}.{{ .Values.domain.name }}.org
http:
paths:
- path: /api/v1/(decompiled_smart_contract|verified_smart_contracts)
backend:
serviceName: {{ .Release.Name }}-web
servicePort: 4000
- path: /(graphql|graphiql|api)
backend:
serviceName: {{ .Release.Name }}-api
servicePort: 4000
- path: /
backend:
serviceName: {{ .Release.Name }}-web
Expand Down
17 changes: 17 additions & 0 deletions packages/helm-charts/blockscout/values.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
imagePullPolicy: IfNotPresent
blockscout:
indexer:
pool_size: 30
api:
autoscaling:
maxReplicas: 10
minReplicas: 2
target:
cpu: 70
pool_size: 40
web:
autoscaling:
maxReplicas: 5
minReplicas: 2
target:
cpu: 70
pool_size: 10
image:
repository: gcr.io/celo-testnet/blockscout
tag: v2.0.4-beta-celo
healthy_blocks_period: 60
db:
# ip: must be provided at runtime # IP address of the postgres DB
# connection_name: must be provided at runtime # name of the cloud sql connection
Expand Down

0 comments on commit 5f4a62b

Please sign in to comment.