diff --git a/.kubernetes/configmap.yaml b/.kubernetes/configmap.yaml new file mode 100644 index 00000000..2e073342 --- /dev/null +++ b/.kubernetes/configmap.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: lite-explorer +data: + config.json: |- + CONFIG_JSON diff --git a/.kubernetes/deploy.sh b/.kubernetes/deploy.sh new file mode 100755 index 00000000..c7a04b06 --- /dev/null +++ b/.kubernetes/deploy.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -e + +# Get config.json contents based on first program arg or default then escape special chars for sed replacements string then indent all lines with 4 spaces to align with output yaml +config_json=$(cat ${1:-"../config.default.json"} | sed 's:[\/&]:\\&:g;$!s/$/\\/' | sed 's/^/ /') + +# Replace the placeholder from input yaml file and write a new one +cat configmap.yaml | sed "s/ CONFIG_JSON/$config_json/" > configmap.generated.yaml + +kubectl apply -f configmap.generated.yaml +kubectl apply -f explorer-deployment.yaml +kubectl apply -f explorer-service.yaml + +# Clean up +rm configmap.generated.* diff --git a/.kubernetes/explorer-deployment.yaml b/.kubernetes/explorer-deployment.yaml new file mode 100644 index 00000000..7637ade1 --- /dev/null +++ b/.kubernetes/explorer-deployment.yaml @@ -0,0 +1,35 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: lite-explorer + labels: + app: lite-explorer +spec: + replicas: 1 + selector: + matchLabels: + app: lite-explorer + template: + metadata: + # Optional, if this'd be wrapped in a helm chart it can be generated as the SHA256 of the configmap + # to pod rolling updates reloads on configmap change + annotations: + checksum/config: 6733181240aa3db87503350771fb19fcaef0707e209928165a9cc7e3e3050781 + labels: + app: lite-explorer + spec: + containers: + - image: alethio/ethereum-lite-explorer + imagePullPolicy: Always + name: app + ports: + - containerPort: 80 + name: http + volumeMounts: + - mountPath: /usr/share/nginx/html/config.json + name: config + subPath: config.json + volumes: + - configMap: + name: lite-explorer + name: config diff --git a/.kubernetes/explorer-service.yaml b/.kubernetes/explorer-service.yaml new file mode 100644 index 00000000..8e3c7149 --- /dev/null +++ b/.kubernetes/explorer-service.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: lite-explorer +spec: + type: ClusterIP + ports: + - port: 80 + targetPort: http + protocol: TCP + name: http + selector: + app: lite-explorer diff --git a/.kubernetes/remove.sh b/.kubernetes/remove.sh new file mode 100755 index 00000000..c465feb9 --- /dev/null +++ b/.kubernetes/remove.sh @@ -0,0 +1,3 @@ +kubectl delete configmap lite-explorer +kubectl delete -f explorer-deployment.yaml +kubectl delete -f explorer-service.yaml diff --git a/README.md b/README.md index ac32b0d4..27b7c0c2 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ No need for servers, hosting or trusting any third parties to display chain data - [Prerequisites](#prerequisites) - [Configuration](#configuration) - [Running in Docker](#running-in-docker) + - [Running in Kubernetes](#running-in-kubernetes) - [Building from source](#building-from-source) - [Deploying the built assets to production](#deploying-the-built-assets-to-production) - [Custom build arguments](#custom-build-arguments) @@ -128,6 +129,13 @@ If more customization is needed, a full configuration file can be mounted in the ```sh $ docker run -p 80:80 -v /your-config-dir/config.json:/usr/share/nginx/html/config.json alethio/ethereum-lite-explorer ``` +### Running in Kubernetes +You can deploy the Lite Explorer in Kubernetes using the following steps: +- `cd .kubernetes` +- Run `./deploy.sh` to deploy, uses `config.default.json` as config. +- Use for example `./deploy.sh ../config.memento.json` to select other config files. +- Run `./remove.sh` to remove + ### Building from source Clone the explorer in a folder of your choosing