k8s-lbry: Adds bash wrapper run.sh and new configs

Squashed commit of the following:

commit ce1e033f36f0b1e41c48cfa09b4660771af0e6f3
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Fri May 17 09:04:05 2019 -0400

    Added spee.ch README and speech-lbrynet services.

commit 7aa73f3d58885c7e2ff56161861fe9d9c73b70e0
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Thu May 16 19:03:28 2019 -0400

    Fix Speech downloads dirs

commit 3137b0c82e9f83482a48b721d176794efeeb6164
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Thu May 16 17:52:55 2019 -0400

    speech-lbrynet should mount speech-data volume to store downloads.

commit 727c59800a91cedf545b1f3f767e9481455c1897
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Thu May 16 17:40:34 2019 -0400

    applying shell-check (part 1)

commit 251e2b104b7f87cc0b3e430371be7a6fdfca1d08
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Wed May 15 20:43:18 2019 -0400

    TLS / HTTPs

commit b3de768909a827a2a3b65e7ecbe1795d1ab75e7b
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Wed May 15 17:51:52 2019 -0400

    Spee.ch+lbrynet sidecar (in progress)

commit 1eb08ae6f9dd57e4bdfe9c196493f609908e4105
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Tue May 14 10:43:20 2019 -0400

    Add asciicast

commit 067e9c8325c5148fb16b3a96e8c4de7d39c8f25d
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Mon May 13 09:49:50 2019 -0400

    Updates lbrynet image

commit b85026d6488c9b00d2cb8ad86f4be626db2e9d66
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Mon May 13 08:36:40 2019 -0400

    README

commit 1f5bd113205164fcc4e279e5ef51b2dad3a8e477
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 21:40:46 2019 -0400

    fix helm app names

commit 28ea709507643a4385bd0618b1de9b69f62752eb
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 21:31:22 2019 -0400

    lbrycrd-override-snapshot

commit 0d5b2ae7743e721c08d940a15e73540ce4411886
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 21:00:24 2019 -0400

    remove set -x

commit b2d380197befe8de716ea2f09bfdf7f984d2a867
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 20:41:18 2019 -0400

    fix lbrynet-copy-wallet

commit 2dcb98dee79eacb64d9ca14b0eed6a90c249c6fe
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 20:29:59 2019 -0400

    run.sh messaging

commit b766ffc624aa165c2a987bd7cd7911e3dd0a78df
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 20:21:21 2019 -0400

    fix linkages

commit 4d07652d1af1fd741bbec6debe8462bcd9e6cf65
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 19:39:23 2019 -0400

    fix container linkage

commit 8f4bd26ac7b658d3cc1b201a6870fe889e3a39d9
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 19:26:53 2019 -0400

    run.sh help

commit ef2f0fe4b7c5b5e3aef5d14b99a3293a41e45ae5
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 18:43:43 2019 -0400

    remove old messaging

commit b8a6696b0f38724ce5f0472943233da681181a72
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 17:19:33 2019 -0400

    add setup-alias command

commit fbc5c202fe48e0f5867b899795fb4e9ab696e96f
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 16:06:04 2019 -0400

    README

commit 34410c1e1f4fd3546b76a55dc0fdb713ed8a1279
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 15:51:20 2019 -0400

    Depend on external kubectl and helm tab completion scripts.

commit a9af588c42f8bcd11266733646d7990ab722a84c
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 15:23:35 2019 -0400

    Fix tab completion script

commit c82efd5463af24118249240b738a70eb0f5e9d3d
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 15:12:21 2019 -0400

    Refactor run.sh script to k8s-lbry alias.

commit d14eb6691226788f0e08cc5b162fd29de8c1782f
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 14:44:16 2019 -0400

    Fix tab completion script.

commit 77ecaab2f934290e20da969182c7f09f71d1b819
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 14:22:25 2019 -0400

    Fix kubectl namespace during tab completion

commit 29ff6d25b0256a51a05c96a0f8f9a7d443ff58d1
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sun May 12 12:13:03 2019 -0400

    k8s-lbry: Adds tab completion

commit da961eb75ea5468ad4240bf7ad4f8a8058a0909f
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 20:54:43 2019 -0400

    README

commit 934e43be256aee490385cbf9f40115e464ba930e
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 20:23:03 2019 -0400

    Chainquery snapshot restore

commit 56029260f3f6c436847efb89a37fa206f5d7265f
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 18:13:58 2019 -0400

    lbrycrd-cli credentials

commit 03bc538174e874cbf82ec061edb184583ee293b9
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 18:07:25 2019 -0400

    Open port 9246

commit 339688bb28f9fd63bdce944c55d5d2d0c57d87be
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 17:37:15 2019 -0400

    delete old package script

commit 4cef33826bcaef72eb3acecfb83d2627bd2a1dd7
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 17:31:17 2019 -0400

    fix pod names

commit babcb688a747d58b7c8b4cf5c44f46d36307d111
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 16:47:30 2019 -0400

    more

commit 88192a8992604aa9fb7edbb41d0194b70a7a00ca
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 16:13:27 2019 -0400

    enable args

commit 01bcf85e1478b47814788cc4f1d44b5b91a0ea26
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 15:55:14 2019 -0400

    more

commit 76ab5019b85a43b04554af8da6a55d30d13dedf3
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 15:41:36 2019 -0400

    k8s-lbry: lbrynet

commit 3432c9e3a089e5789c1b30d5119cfb25d087d707
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 11:41:32 2019 -0400

    README

commit 813b6ab95b2320000405dca973492d6cba19b288
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 11:40:02 2019 -0400

    fix regex

commit d010eb5ee96fded843247e0d12980f38b910c9f1
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 11:36:47 2019 -0400

    Add git dependency

commit 092c496f9bf3e86dc1a138ac404daa582fe1632e
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 11:27:14 2019 -0400

    Fix helm

commit fa7dea7139031931ff372024ee914a60d68b6157
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 10:57:17 2019 -0400

    Make run.sh bootstrappable

commit f512878a70f70f85f2e7f5bc7c239d681846e508
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Sat May 11 10:21:35 2019 -0400

    k8s-lbry: README

commit fd77fa2527962198b204a3de852c0b891e078178
Author: Ryan McGuire <ryan@enigmacurry.com>
Date:   Wed May 8 02:50:24 2019 -0400

    k8s-lbry: Adds run.sh wrapper script and new README.
This commit is contained in:
Ryan McGuire 2019-05-17 09:19:20 -04:00 committed by Leopere
parent 2849405dcc
commit c5dc75d685
12 changed files with 1399 additions and 512 deletions

View file

@ -1,4 +1,6 @@
index.yaml
*.tgz
requirements-dev.yaml
values-dev.yaml
values-staging.yaml
values-production.yaml
completion.bash.inc

View file

@ -2,7 +2,7 @@ apiVersion: v1
appVersion: "1.0"
description: LBRY on Kubernetes with Helm
name: k8s-lbry
version: 0.1.1
version: 0.1.4
maintainers:
- email: ryan@enigmacurry.com
name: EnigmaCurry

File diff suppressed because it is too large Load diff

View file

@ -30,4 +30,7 @@ data:
{{- with .Values.slack }}
slackConfig.json: {{ toJson . | quote }}
{{- end }}
{{- with .Values.lbrynet.daemon_settings }}
daemon_settings.yml: {{ toYaml . | quote }}
{{- end }}
{{- end }}

View file

@ -27,7 +27,7 @@ spec:
initContainers:
- name: copy-lbrycrd-config
image: busybox
command: ['sh', '-c', 'cp /configmap/chainqueryConfig.json /configmap/lbryConfig.json /configmap/loggerConfig.json /configmap/mysqlConfig.json /configmap/siteConfig.json /configmap/slackConfig.json /config && cp /configmap/authConfig.json /private']
command: ['sh', '-c', 'cp /configmap/chainqueryConfig.json /configmap/lbryConfig.json /configmap/loggerConfig.json /configmap/mysqlConfig.json /configmap/siteConfig.json /configmap/slackConfig.json /configmap/daemon_settings.yml /config && cp /configmap/authConfig.json /private']
volumeMounts:
- name: configmap
mountPath: /configmap
@ -48,21 +48,46 @@ spec:
mountPath: /spee.ch/site/config
- name: private
mountPath: /spee.ch/site/private
- name: data
- name: speech-data
mountPath: /data
{{- if .Values.lbrynet.enabled }}
- name: {{ template "speech.fullname" . }}-lbrynet
image: "{{ .Values.lbrynet.image.repository }}:{{ .Values.lbrynet.image.tag }}"
imagePullPolicy: {{ .Values.lbrynet.image.pullPolicy }}
resources: {{ toYaml .Values.resources | indent 10 }}
ports:
- name: rpc
containerPort: {{ .Values.lbrynet.service.rpcPort }}
volumeMounts:
- name: configmap
mountPath: /etc/lbry
- name: lbrynet-home
mountPath: /home/lbrynet
- name: speech-data
mountPath: /data
{{- end }}
volumes:
- name: config
mountPath: /spee.ch/site/config
- name: private
mountPath: /spee.ch/site/private
- name: configmap
configMap:
name: {{ template "speech.fullname" . }}
- name: data
- name: speech-data
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
claimName: {{ .Values.persistence.existingClaim | default (include "speech.fullname" .) }}
{{- else }}
emptyDir: {}
{{- end -}}
{{- end }}
- name: lbrynet-home
{{- if .Values.persistence.enabled }}
persistentVolumeClaim:
{{- if .Values.lbrynet.persistence.existingClaim }}
claimName: {{ .Values.lbrynet.persistence.existingClaim }}
{{- else }}
claimName: {{ template "speech.fullname" .}}-lbrynet
{{- end }}
{{- else }}
emptyDir: {}
{{- end }}
{{- end }}

View file

@ -28,4 +28,35 @@ spec:
{{- end }}
{{- end }}
{{- end }}
---
{{- if and .Values.lbrynet.persistence.enabled (not .Values.lbrynet.persistence.existingClaim) }}
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: {{ template "speech.fullname" . }}-lbrynet
labels:
app: {{ template "speech.name" . }}
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
release: "{{ .Release.Name }}"
heritage: "{{ .Release.Service }}"
{{- with .Values.persistence.annotations }}
annotations:
{{ toYaml . | indent 4 }}
{{- end }}
spec:
accessModes:
- {{ .Values.persistence.accessMode | quote }}
resources:
requests:
storage: {{ .Values.persistence.size | quote }}
{{- if .Values.persistence.storageClass }}
{{- if (eq "-" .Values.persistence.storageClass) }}
storageClassName: ""
{{- else }}
storageClassName: "{{ .Values.persistence.storageClass }}"
{{- end }}
{{- end }}
{{- end }}
---
{{- end }}

View file

@ -1,12 +1,9 @@
dependencies:
- name: percona
repository: https://kubernetes-charts.storage.googleapis.com
version: 0.3.5
- name: mysql
repository: https://kubernetes-charts.storage.googleapis.com
version: 0.19.0
- name: mysql
repository: https://kubernetes-charts.storage.googleapis.com
version: 0.19.0
digest: sha256:c97a2ebaa817e80a3c343e24befc75b133758c17438a5a520ecb0780aaa2ecef
generated: 2019-05-04T13:44:28.303905337-04:00
digest: sha256:dcb695ba5d5865f2a0b760e1bbef189b9465df4592a69463d18eed925e34e91a
generated: 2019-05-17T10:07:58.995024521-04:00

View file

@ -1,8 +1,4 @@
dependencies:
- name: percona
repository: "@stable"
version: 0.3.5
condition: percona.enabled,global.percona.enabled
- name: mysql
alias: chainquery-mysql
repository: "@stable"

661
contrib/k8s-lbry/run.sh Executable file
View file

@ -0,0 +1,661 @@
#!/bin/bash
BASEDIR=$(cd $(dirname "$0"); pwd)
BASENAME=$(basename "$0")
## RELEASE - The name for the helm release.
RELEASE=${RELEASE:-k8s-lbry}
## NAMESPACE - The Kubernetes namespace for the release
NAMESPACE=${NAMESPACE:-k8s-lbry}
## CHART - The helm chart location (local path, or from repository)
### Use the stable chart from the HELM_REPO repository:
CHART=${CHART:-lbry/k8s-lbry}
### Use the chart from the current directory:
#CHART=${CHART:-$BASEDIR}
## VALUES - The path to your configured helm values.yaml:
VALUES=${VALUES:-$BASEDIR/values-dev.yaml}
DEFAULT_VALUES_URL=${DEFAULT_VALUES_URL:-https://raw.githubusercontent.com/EnigmaCurry/lbry-docker/k8s-lbry/contrib/k8s-lbry/values.yaml}
## HELM_REPO - The stable helm chart repository for this chart:
HELM_REPO=${HELM_REPO:-https://k8s-lbry.sfo2.digitaloceanspaces.com}
## TILLER_HOST - The host that runs tiller
TILLER_HOST=${TILLER_HOST:-localhost}
## CERTMANAGER_NAMESPACE - The namespace cert-manager runs in
CERTMANAGER_NAMESPACE=${CERTMANAGER_NAMESPACE:-cert-manager}
CERTMANAGER_VERSION=v0.7.1
## NGINX_ENABLE_HTTPS - This needs to be set false until DNS is setup.
NGINX_ENABLE_HTTPS=${NGINX_ENABLE_HTTPS:-false}
## Mysql Database snapshot download url:
CHAINQUERY_SNAPSHOT_URL=${CHAINQUERY_SNAPSHOT_URL:-https://lbry-chainquery-mysql-dump.sfo2.digitaloceanspaces.com/chainquery_height_560900.mysql-backup.tar.gz}
## lbrycrd snapshot download url:
LBRYCRD_SNAPSHOT_URL=${LBRYCRD_SNAPSHOT_URL:-https://lbry-chainquery-mysql-dump.sfo2.digitaloceanspaces.com/lbrycrd-566588-snapshot.tar.gz}
LBRYCRD_RPC_USER=${LBRYCRD_RPC_USER:-lbry}
LBRYCRD_RPC_PASSWORD=${LBRYCRD_RPC_PASSWORD:-lbry}
## Bash alias name for run.sh
## defaults to $NAMESPACE (k8s-lbry)
RUN_ALIAS=${RUN_ALIAS:-$NAMESPACE}
## Package bucket (ignore this, only used by developer of this package)
PACKAGE_BUCKET=${PACKAGE_BUCKET:-"s3://k8s-lbry"}
exe() { ( echo "## $*"; $*; ) }
setup() {
### Check for external dependencies:
if ! which helm > /dev/null; then
echo "Error: You must install helm"
echo "On Ubuntu you can run: sudo snap install --classic helm"
echo "For other platforms, see https://github.com/helm/helm/releases/latest"
exit 1
fi
if ! which kubectl > /dev/null; then
echo "Error: You must install kubectl"
echo "On Ubuntu you can run: sudo snap install --classic kubectl"
echo "For other platforms, see https://kubernetes.io/docs/tasks/tools/install-kubectl/"
exit 1
fi
if ! which git > /dev/null; then
echo "Error: You must install git"
echo "On Ubuntu you can run: sudo apt install -y git"
echo "For other platforms, see https://git-scm.com/downloads"
exit 1
fi
### Initialize helm locally, but do not install tiller to the cluster:
HELM=$(which helm)
if [ ! -f "$HOME"/.helm/repository/repositories.yaml ]; then
exe "$HELM" init --client-only
fi
### Add the stable helm chart repository:
if [ "$CHART" != "$BASEDIR" ]; then
exe "$HELM" repo add lbry "$HELM_REPO"
exe "$HELM" repo update
fi
### Install helm-tiller plugin, so that no tiller needs to be installed to the cluster:
exe "$HELM" plugin install https://github.com/rimusz/helm-tiller || true
### Setup the values.yaml for the chart, using the VALUES environment variable or script default
### If no values file exists, interactively ask if a default config should be created in its place.
if [ ! -f "$VALUES" ]; then
echo ""
echo "Values file does not exist: $VALUES"
read -p "Would you like to create a default config file here? (y/N)" choice
echo ""
case "$choice" in
y|Y ) curl "$DEFAULT_VALUES_URL" -Lo "$VALUES"
echo "Default configuration created: $VALUES"
;;
* ) echo "You must create your own values file: $VALUES (using values.yaml as a template.)"
echo "Or set VALUES=/path/to/values.yaml before subsequent commands."
exit 1
;;
esac
else
echo "Configuration found: $VALUES"
fi
echo "Edit this config file to suit your own environment before install/upgrade"
}
helm() {
## Redefine all helm commands to run through local tiller instance
## https://rimusz.net/tillerless-helm
HELM=$(which helm)
exe "$HELM" tiller run "$NAMESPACE" -- helm "$*"
}
kubectl() {
## kubectl wrapper that defaults to k8s-lbry namespace, so you don't have to
## type as much, but still passes all the provided arguments on to kubectl.
## So you can still specify a different namespace, because the client args
## are applied last.
KUBECTL=$(which kubectl)
exe "$KUBECTL" --namespace "$NAMESPACE" "$*"
}
install-nginx-ingress() {
### Install nginx-ingress from stable helm repository
### See https://github.com/helm/charts/tree/master/stable/nginx-ingress
helm install stable/nginx-ingress --namespace "$NAMESPACE" --name nginx-ingress --set nginx-ingress.controller.service.enableHttps="$NGINX_ENABLE_HTTPS" --set tcp.9246="$NAMESPACE/lbrycrd:9246"
}
upgrade-nginx-ingress() {
### Upgrade nginx-ingress
helm upgrade nginx-ingress stable/nginx-ingress --namespace "$NAMESPACE" --set nginx-ingress.controller.service.enableHttps="$NGINX_ENABLE_HTTPS" --set tcp.9246="$NAMESPACE/lbrycrd:9246"
}
install-cert-manager() {
### Install cert-manager from jetstack helm repository
### See https://docs.cert-manager.io/en/latest/index.html
kubectl apply -f https://raw.githubusercontent.com/jetstack/cert-manager/release-0.7/deploy/manifests/00-crds.yaml
helm repo add jetstack https://charts.jetstack.io
helm repo update
helm install --name cert-manager --namespace "$CERTMANAGER_NAMESPACE" jetstack/cert-manager --version $CERTMANAGER_VERSION
kubectl label namespace "$CERTMANAGER_NAMESPACE" certmanager.k8s.io/disable-validation="true"
}
upgrade-cert-manager() {
### Upgrade cert-manager
helm upgrade cert-manager jetstack/cert-manager --namespace "$CERTMANAGER_NAMESPACE" --version $CERTMANAGER_VERSION
}
install() {
### Install the k8s-lbry helm chart
if [ ! -f "$VALUES" ]; then
echo "Could not find chart values file: $VALUES"
exit 1
fi
helm install "$CHART" --name "$RELEASE" --namespace="$NAMESPACE" -f "$VALUES"
}
upgrade() {
### Upgrade the k8s-lbry helm chart
if [ ! -f "$VALUES" ]; then
echo "Could not find chart values file: $VALUES"
exit 1
fi
helm upgrade "$RELEASE" "$CHART" --namespace="$NAMESPACE" -f "$VALUES"
}
shell() {
### Execute a shell in the running container with helm app name provided by first argument
(
if [ "$#" -eq 1 ]; then
KUBECTL=$(which kubectl)
POD=$($KUBECTL get --namespace "$NAMESPACE" pod -l app="$1" -o name | sed s+pod/++)
exe kubectl exec -it "$POD" /bin/bash
else
echo "Required arg: helm app name of pod to shell into"
fi
)
}
shell-pvc() {
### Start a utility container shell with an attached Persistent Volume Claim.
(
# From https://gist.github.com/yuanying/3aa7d59dcce65470804ab43def646ab6
IMAGE="ubuntu:18.04"
COMMAND="/bin/bash"
SUFFIX=$(date +%s | shasum | base64 | fold -w 10 | head -1 | tr '[:upper:]' '[:lower:]')
usage_exit() {
echo "Usage: $0 [-c command] [-i image] PVC ..." 1>&2
exit 1
}
if [ "$#" -ne 1 ]; then
usage_exit
fi
while getopts i:h OPT
do
case $OPT in
i) IMAGE=$OPTARG
;;
c) COMMAND=$OPTARG
;;
h) usage_exit
;;
\?) usage_exit
;;
esac
done
shift $(($OPTIND - 1))
VOL_MOUNTS=""
VOLS=""
COMMA=""
for i in $@
do
VOL_MOUNTS="${VOL_MOUNTS}${COMMA}{\"name\": \"${i}\",\"mountPath\": \"/pvcs/${i}\"}"
VOLS="${VOLS}${COMMA}{\"name\": \"${i}\",\"persistentVolumeClaim\": {\"claimName\": \"${i}\"}}"
COMMA=","
done
$(which kubectl) --namespace "$NAMESPACE" run -it --rm --restart=Never --image="${IMAGE}" pvc-mounter-"${SUFFIX}" --overrides "
{
\"spec\": {
\"hostNetwork\": true,
\"containers\":[
{
\"args\": [\"${COMMAND}\"],
\"stdin\": true,
\"tty\": true,
\"name\": \"pvc\",
\"image\": \"${IMAGE}\",
\"volumeMounts\": [
${VOL_MOUNTS}
]
}
],
\"volumes\": [
${VOLS}
]
}
}
" -- "${COMMAND}"
)
}
restart() {
### Restart the pod given by a helm app name
(
if [ "$#" -eq 1 ]; then
KUBECTL=$(which kubectl)
POD=$($KUBECTL get --namespace "$NAMESPACE" pod -l app="$1" -o name | sed s+pod/++)
exe kubectl delete pod "$POD"
else
echo "Required arg: helm app name of pod to restart"
fi
)
}
package() {
### Create a packaged helm release and upload to the S3 repository
(
cd $BASEDIR
set -e
if [ "$#" -eq 1 ]; then
if ! grep "version: $1" Chart.yaml; then
echo "Chart.yaml version does not match intended package version ($1)."
exit 1
fi
else
echo "required argument: package version"
exit 1
fi
PACKAGE="k8s-lbry-$1.tgz"
## Build Helm package repository and upload to s3
if which s3cmd > /dev/null; then
if s3cmd info $PACKAGE_BUCKET > /dev/null; then
# Download all remote releases, to re-include in new index.yaml
exe s3cmd sync $PACKAGE_BUCKET .
# Check if release already exists
s3_url="$PACKAGE_BUCKET/$PACKAGE"
if s3cmd info "$s3_url"; then
echo "$s3_url already exists. Aborting."
exit 1
fi
# Package release and rebuild repository
exe helm dependency update
exe helm package .
exe helm repo index .
# Publish packages to s3
exe s3cmd put --acl-public index.yaml "$PACKAGE" $PACKAGE_BUCKET
exe s3cmd put --acl-public charts/*.tgz $PACKAGE_BUCKET/charts/
else
echo "s3cmd is not setup, run s3cmd --configure"
exit 1
fi
else
echo "s3cmd is not installed"
exit 1
fi
)
}
chainquery-mysql-client() {
### Access the mysql shell for chainquery
KUBECTL=$(which kubectl)
POD=$($KUBECTL -n "$NAMESPACE" get pod -l app=chainquery-mysql -o name | sed s+pod/++)
if [ ${#POD} -gt 0 ]; then
kubectl exec -it "$POD" -- mysql -u chainquery -pchainquery
else
echo "chainquery-mysql pod not found"
fi
}
speech-mysql-client() {
### Access the mysql shell for speech
KUBECTL=$(which kubectl)
POD=$($KUBECTL -n "$NAMESPACE" get pod -l app=speech-mysql -o name | sed s+pod/++)
if [ ${#POD} -gt 0 ]; then
kubectl exec -it "$POD" -- mysql -u speech -pspeech
else
echo "speech-mysql pod not found"
fi
}
chainquery-override-snapshot() {
### Delete the existing chainquery database and download a snapshot to restore
read -p "Would you like to DESTROY the existing chainquery database,
and restore from a fresh snapshot? (y/N) " destroy_chainquery
case "$destroy_chainquery" in
y|Y )
kubectl delete deployments chainquery chainquery-mysql || true
echo "Please wait.."
IMAGE="ubuntu:18.04"
SUFFIX=$(date +%s | shasum | base64 | fold -w 10 | head -1 | tr '[:upper:]' '[:lower:]')
VOL_MOUNTS="{\"name\": \"chainquery-mysql\",\"mountPath\": \"/pvcs/chainquery-mysql\"}"
VOLS="{\"name\": \"chainquery-mysql\",\"persistentVolumeClaim\": {\"claimName\": \"chainquery-mysql\"}}"
COMMAND="rm -rf /pvcs/chainquery-mysql/* && apt-get update && apt-get install -y curl && curl -s ${CHAINQUERY_SNAPSHOT_URL} | tar xvz -C /pvcs/chainquery-mysql/"
$(which kubectl) --namespace "$NAMESPACE" run -it --rm --restart=Never --image=${IMAGE} pvc-mounter-"${SUFFIX}" --overrides "
{
\"spec\": {
\"hostNetwork\": true,
\"containers\":[
{
\"args\": [\"bin/bash\", \"-c\", \"${COMMAND}\"],
\"stdin\": true,
\"tty\": true,
\"name\": \"pvc\",
\"image\": \"${IMAGE}\",
\"volumeMounts\": [
${VOL_MOUNTS}
]
}
],
\"volumes\": [
${VOLS}
]
}
}
"
echo "Extraction complete"
;;
* ) echo "Aborted."
;;
esac
}
lbrycrd-override-snapshot() {
### Delete the existing lbrycrd data and download a snapshot to restore
read -p "Would you like to DESTROY the existing lbrycrd data,
and restore from a fresh snapshot? (y/N) " destroy_lbrycrd
case "$destroy_lbrycrd" in
y|Y )
kubectl delete deployments lbrycrd || true
echo "Please wait.."
IMAGE="ubuntu:18.04"
SUFFIX=$(date +%s | shasum | base64 | fold -w 10 | head -1 | tr '[:upper:]' '[:lower:]')
VOL_MOUNTS="{\"name\": \"lbrycrd\",\"mountPath\": \"/pvcs/lbrycrd\"}"
VOLS="{\"name\": \"lbrycrd\",\"persistentVolumeClaim\": {\"claimName\": \"lbrycrd\"}}"
COMMAND="rm -rf /pvcs/lbrycrd/* && apt-get update && apt-get install -y curl && curl -s ${LBRYCRD_SNAPSHOT_URL} | tar xvz -C /pvcs/lbrycrd/"
$(which kubectl) --namespace "$NAMESPACE" run -it --rm --restart=Never --image=${IMAGE} pvc-mounter-"${SUFFIX}" --overrides "
{
\"spec\": {
\"hostNetwork\": true,
\"containers\":[
{
\"args\": [\"bin/bash\", \"-c\", \"${COMMAND}\"],
\"stdin\": true,
\"tty\": true,
\"name\": \"pvc\",
\"image\": \"${IMAGE}\",
\"volumeMounts\": [
${VOL_MOUNTS}
]
}
],
\"volumes\": [
${VOLS}
]
}
}
"
echo "Extraction complete"
;;
* ) echo "Aborted."
;;
esac
}
logs() {
### Watch the logs of a pod by helm app name
(
set -e
if [ "$#" -eq 1 ]; then
kubectl logs -l app="$1" -f
elif [ "$#" -eq 2 ]; then
KUBECTL=$(which kubectl)
POD=$($KUBECTL get --namespace "$NAMESPACE" pod -l app="$1" -o name | sed s+pod/++)
kubectl logs "$POD" "$2" -f
else
echo "Required arg: app_name"
fi
)
}
lbrynet-copy-wallet() {
### Copy the lbrynet wallet to a local path for backup
(
set -e
if [ "$#" -eq 1 ]; then
WALLET=/home/lbrynet/.local/share/lbry/lbryum/wallets/default_wallet
KUBECTL=$(which kubectl)
POD=$($KUBECTL -n "$NAMESPACE" get pod -l app=lbrynet -o name | sed s+pod/++)
kubectl cp "$POD":$WALLET "$1"
chmod 600 "$1"
echo "lbrynet wallet copied to $1"
else
echo "Required arg: path of backup location for wallet"
fi
)
}
speech-lbrynet-copy-wallet() {
### Copy the speech-lbrynet wallet to a local path for backup
(
set -e
if [ "$#" -eq 1 ]; then
WALLET=/home/lbrynet/.local/share/lbry/lbryum/wallets/default_wallet
KUBECTL=$(which kubectl)
POD=$($KUBECTL -n "$NAMESPACE" get pod -l app=speech -o name | sed s+pod/++)
kubectl cp "$POD":$WALLET "$1" -c speech-lbrynet
chmod 600 "$1"
echo "lbrynet wallet copied to $1"
else
echo "Required arg: path of backup location for wallet"
fi
)
}
lbrycrd-cli() {
## Run lbrycrd-cli client from inside the running pod outputting to your local terminal
KUBECTL=$(which kubectl)
POD=$($KUBECTL -n "$NAMESPACE" get pod -l app=lbrycrd -o name | sed s+pod/++)
if [ ${#POD} -gt 0 ]; then
kubectl exec "$POD" -- lbrycrd-cli -rpcuser="$LBRYCRD_RPC_USER" -rpcpassword="$LBRYCRD_RPC_PASSWORD" "$*"
else
echo "lbrycrd pod not found"
fi
}
lbrynet() {
## Run lbrynet client from inside the running pod outputting to your local terminal
KUBECTL=$(which kubectl)
POD=$($KUBECTL -n "$NAMESPACE" get pod -l app=lbrynet -o name | sed s+pod/++)
if [ ${#POD} -gt 0 ]; then
kubectl exec "$POD" -- lbrynet "$*"
else
echo "lbrynet pod not found"
fi
}
speech-lbrynet() {
## Run lbrynet client from inside the running pod outputting to your local terminal
KUBECTL=$(which kubectl)
POD=$($KUBECTL -n "$NAMESPACE" get pod -l app=speech -o name | sed s+pod/++)
if [ ${#POD} -gt 0 ]; then
kubectl exec "$POD" -c speech-lbrynet -- lbrynet "$*"
else
echo "lbrynet pod not found"
fi
}
SUBCOMMANDS_NO_ARGS=(setup install install-nginx-ingress install-cert-manager upgrade
upgrade-nginx-ingress upgrade-cert-manager chainquery-mysql-client
speech-mysql-client chainquery-override-snapshot lbrycrd-override-snapshot
setup-alias)
SUBCOMMANDS_PASS_ARGS=(helm kubectl shell shell-pvc restart package logs lbrynet-copy-wallet lbrynet speech-lbrynet-copy-wallet speech-lbrynet lbrycrd-cli completion)
completion() {
if [ "$#" -eq 1 ] && [ "$1" == "bash" ]; then
cat <<EOF
__delegate_k8s_lbry() {
alias kubectl="kubectl --namespace=$NAMESPACE"
local cur subs
cur="\${COMP_WORDS[COMP_CWORD]}" # partial word, if any
subs="${SUBCOMMANDS_NO_ARGS[*]} ${SUBCOMMANDS_PASS_ARGS[*]}"
if [[ \${COMP_CWORD} -gt 1 ]]; then
# complete subcommands
_command \${@: -1}
else
# complete with the list of subcommands
COMPREPLY=( \$(compgen -W "\${subs}" -- \${cur}) )
fi
}
if [[ $(type -t compopt) = "builtin" ]]; then
complete -o default -F __delegate_k8s_lbry $RUN_ALIAS
else
complete -o default -o nospace -F __delegate_k8s_lbry $RUN_ALIAS
fi
EOF
else
echo "## I only know how to do completion for the bash shell."
echo "## Try '$0 completion bash' instead."
fi
}
setup-alias() {
$(which kubectl) completion bash > "$BASEDIR"/completion.bash.inc
$(which helm) completion bash >> "$BASEDIR"/completion.bash.inc
completion bash >> "$BASEDIR"/completion.bash.inc
if [[ -z $K8S_LBRY_HOME ]] && ! grep "K8S_LBRY_HOME" "$HOME"/.bashrc > /dev/null; then
echo "K8S_LBRY_HOME not set."
read -p "Would you this script to edit $HOME/.bashrc to add tab completion support? (y/N) " choice
case "$choice" in
y|Y )
cat <<EOF >> "$HOME"/.bashrc
## Enable bash completion
if [ -f /etc/bash_completion ]; then
source /etc/bash_completion
fi
## k8s-lbry alias and tab completion
K8S_LBRY_HOME=$BASEDIR
alias $RUN_ALIAS=\$K8S_LBRY_HOME/run.sh
if [ -f \$K8S_LBRY_HOME/completion.bash.inc ]; then
source \$K8S_LBRY_HOME/completion.bash.inc
fi
EOF
echo "Created new alias: $RUN_ALIAS"
echo "To use the new alias, run \"source ~/.bashrc\" or just close your terminal session and restart it."
;;
* ) echo "Aborting" && exit 1;;
esac
else
echo "K8S_LBRY_HOME environment already setup. Nothing left to do."
fi
}
if printf '%s\n' ${SUBCOMMANDS_NO_ARGS[@]} | grep -q -P "^$1$"; then
## Subcommands that take no arguments:
(
set -e
if [ "$#" -eq 1 ]; then
$*
else
echo "$1 does not take any additional arguments"
fi
)
elif printf '%s\n' ${SUBCOMMANDS_PASS_ARGS[@]} | grep -q -P "^$1$"; then
## Subcommands that pass all arguments:
(
set -e
$*
)
else
if [[ $# -gt 0 ]]; then
echo "## Invalid command: $1"
else
echo "## Must specify a command:"
fi
echo ""
echo "## $0 setup"
echo "## - Setup dependencies"
echo ""
echo "## $0 install-nginx-ingress"
echo "## - Deploy nginx-ingress chart"
echo ""
echo "## $0 install-cert-manager"
echo "## - Deploy cert-manager chart"
echo ""
echo "## $0 install"
echo "## - Deploy main k8s-lbry chart"
echo ""
echo "## $0 upgrade"
echo "## - Upgrade an existing release"
echo ""
echo "## $0 shell <app>"
echo "## - execute shell into running helm application pod"
echo ""
echo "## $0 shell-pvc [-c command] [-i image] PVC"
echo "## - run a utility shell with the named PVC mounted in /pvcs"
echo ""
echo "## $0 helm <cmd> [...] "
echo "## - run any helm command (through helm-tiller wrapper)"
echo ""
echo "## $0 kubectl <cmd> [...]"
echo "## - run any kubectl command (defaulting to configured namespace)"
echo ""
echo "## $0 chainquery-mysql-client"
echo "## - run mysql shell for chainquery database"
echo ""
echo "## $0 speech-mysql-client"
echo "## - run mysql shell for speech database"
echo ""
echo "## $0 chainquery-override-snapshot"
echo "## - Restore chainquery database from snapshot"
echo ""
echo "## $0 lbrycrd-override-snapshot"
echo "## - Restore lbrycrd database from snapshot"
echo ""
echo "## $0 logs <app> [container]"
echo "## - Stream the logs for the pod running the helm app name provided"
echo "## (specify which container if the pod has more than one.)"
echo ""
echo "## $0 lbrynet-copy-wallet <local-path>"
echo "## - Backup the lbrynet wallet file to a local path"
echo ""
echo "## $0 lbrynet <args ... >"
echo "## - Run lbrynet client inside running lbrynet pod"
echo ""
echo "## $0 speech-lbrynet-copy-wallet <local-path>"
echo "## - Backup the speech-lbrynet wallet file to a local path"
echo ""
echo "## $0 speech-lbrynet <args ... >"
echo "## - Run speech-lbrynet client inside running speech pod"
echo ""
echo "## $0 setup-alias"
echo "## - Setup bash alias and tab completion for run.sh"
echo ""
exit 1
fi

View file

@ -1,65 +0,0 @@
#!/bin/bash
# From https://gist.github.com/yuanying/3aa7d59dcce65470804ab43def646ab6
IMAGE="ubuntu:18.04"
COMMAND="/bin/bash"
SUFFIX=$(date +%s | shasum | base64 | fold -w 10 | head -1 | tr '[:upper:]' '[:lower:]')
usage_exit() {
echo "Usage: $0 [-c command] [-i image] PVC ..." 1>&2
exit 1
}
if [ "$#" -ne 1 ]; then
usage_exit
fi
while getopts i:h OPT
do
case $OPT in
i) IMAGE=$OPTARG
;;
c) COMMAND=$OPTARG
;;
h) usage_exit
;;
\?) usage_exit
;;
esac
done
shift $(($OPTIND - 1))
VOL_MOUNTS=""
VOLS=""
COMMA=""
for i in $@
do
VOL_MOUNTS="${VOL_MOUNTS}${COMMA}{\"name\": \"${i}\",\"mountPath\": \"/pvcs/${i}\"}"
VOLS="${VOLS}${COMMA}{\"name\": \"${i}\",\"persistentVolumeClaim\": {\"claimName\": \"${i}\"}}"
COMMA=","
done
kubectl run -it --rm --restart=Never --image=${IMAGE} pvc-mounter-${SUFFIX} --overrides "
{
\"spec\": {
\"hostNetwork\": true,
\"containers\":[
{
\"args\": [\"${COMMAND}\"],
\"stdin\": true,
\"tty\": true,
\"name\": \"pvc\",
\"image\": \"${IMAGE}\",
\"volumeMounts\": [
${VOL_MOUNTS}
]
}
],
\"volumes\": [
${VOLS}
]
}
}
" -- ${COMMAND}

View file

@ -1,20 +0,0 @@
#!/bin/bash
## Build Helm package and upload to s3 repository
exe() { echo "\$ $@" ; "$@" ; }
# Work from the parent directory to this script:
cd `dirname "$0"` && cd ..
if s3cmd info s3://k8s-lbry > /dev/null; then
exe helm dependency update
exe helm package .
exe helm repo index .
exe s3cmd put --acl-public index.yaml k8s-lbry-*.tgz s3://k8s-lbry/
exe s3cmd put --acl-public charts/*.tgz s3://k8s-lbry/charts/
else
echo "s3cmd is not setup, run s3cmd --configure"
exit 1
fi

View file

@ -2,19 +2,8 @@ cert-manager-issuer:
# Enter your email address to receive important notices from Let's Encrypt:
email: "fred@example.com"
echo-http-server:
enabled: false
# Enter your domain name for the echo test service:
hostname: "echo.example.com"
service: echo-http-server
enableHttps: true
certificateIssuer: letsencrypt-prod
echo-socket-server:
enabled: false
service: echo-socket-server
lbrycrd:
fullnameOverride: lbrycrd
enabled: true
image:
repository: lbry/lbrycrd
@ -28,7 +17,9 @@ lbrycrd:
accessMode: ReadWriteOnce
size: 50Gi
annotations:
"helm.sh/resource-policy": keep
"helm.sh/resource-policy": keep
# If on AWS:
# storageClass: "ebs-gp2"
configurationFile:
lbrycrd.conf: |-
datadir=/data
@ -36,14 +27,14 @@ lbrycrd:
rpcpassword=lbry
regtest=0
txindex=1
rpcallowip=10.244.0.0/16
rpcallowip=10.0.0.0/8
server=1
listen=1
daemon=0
externalip=
chainquery-mysql:
nameOverride: chainquery-mysql
fullnameOverride: chainquery-mysql
enabled: false
mysqlUser: chainquery
mysqlPassword: chainquery
@ -54,8 +45,11 @@ chainquery-mysql:
size: 100Gi
annotations:
"helm.sh/resource-policy": keep
# If on AWS:
# storageClass: "ebs-gp2"
chainquery:
fullnameOverride: chainquery
enabled: false
image:
repository: lbry/chainquery
@ -65,17 +59,16 @@ chainquery:
port: 6300
configurationFile:
chainqueryconfig.toml: |-
lbrycrdurl="rpc://lbry:lbry@k8s-lbry-lbrycrd:9245"
mysqldsn="chainquery:chainquery@tcp(k8s-lbry-chainquery-mysql:3306)/chainquery"
apimysqldsn="chainquery:chainquery@tcp(k8s-lbry-chainquery-mysql:3306)/chainquery"
lbrycrdurl="rpc://lbry:lbry@lbrycrd:9245"
mysqldsn="chainquery:chainquery@tcp(chainquery-mysql:3306)/chainquery"
apimysqldsn="chainquery:chainquery@tcp(chainquery-mysql:3306)/chainquery"
lbrynet:
fullnameOverride: lbrynet
enabled: false
image:
# repository: lbry/lbrynet
# tag: linux-x86_64-production
repository: enigmacurry/dump
tag: lbrynet
repository: lbry/lbrynet
tag: linux-x86_64-production
pullPolicy: Always
service:
rpcPort: 5279
@ -85,15 +78,20 @@ lbrynet:
size: 10Gi
annotations:
"helm.sh/resource-policy": keep
# If on AWS:
# storageClass: "ebs-gp2"
daemon_settings:
api: 0.0.0.0:5279
use_upnp: false
auto_re_reflect_interval: 0
max_key_fee: {amount: 0, currency: LBC}
run_reflector_server: false
save_files: false
speech-mysql:
nameOverride: speech-mysql
fullnameOverride: speech-mysql
labels:
app: speech-mysql
enabled: false
mysqlUser: speech
mysqlPassword: speech
@ -104,11 +102,15 @@ speech-mysql:
size: 100Gi
annotations:
"helm.sh/resource-policy": keep
# If on AWS:
# storageClass: "ebs-gp2"
speech:
fullnameOverride: speech
enabled: false
service:
name: k8s-lbry-speech
name: speech
hostname: "speech.example.com"
port: 3000
enableHttps: true
@ -123,25 +125,48 @@ speech:
size: 20Gi
annotations:
"helm.sh/resource-policy": keep
# If on AWS:
# storageClass: "ebs-gp2"
auth:
masterPassword: speech
sessionKey: mysecretkeyword
mysql:
host: k8s-lbry-speech-mysql
host: speech-mysql
database: speech
username: speech
password: speech
chainquery:
host: k8s-lbry-chainquery-mysql
host: chainquery-mysql
port: 3306
timeout: 30
database: chainquery
username: chainquery
password: chainquery
lbrynet:
apiHost: k8s-lbry-lbrynet
enabled: true
apiHost: 127.0.0.1
apiPort: 5279
getTimeout: 30
image:
repository: enigmacurry/dump
tag: lbrynet-v0.33.0
pullPolicy: Always
service:
rpcPort: 5279
daemon_settings:
api: 0.0.0.0:5279
use_upnp: false
auto_re_reflect_interval: 0
max_key_fee: {amount: 0, currency: LBC}
run_reflector_server: false
download_dir: /data/Downloads
persistence:
enabled: true
accessMode: ReadWriteOnce
size: 10Gi
annotations:
"helm.sh/resource-policy": keep
# If on AWS:
# storageClass: "ebs-gp2"
logger:
logLevel: verbose
slack:
@ -167,11 +192,11 @@ speech:
primaryClaimAddress:
additionalClaimAddresses: []
approvedChannels: []
channelClaimBidAmount: 0.1
channelClaimBidAmount: "0.1"
closedRegistration: false
disabled: false
disabledMessage: 'Default publishing disabled message'
fileClaimBidAmount: 0.01
fileClaimBidAmount: "0.01"
fileSizeLimits:
application: 50000000
audio: 50000000
@ -243,21 +268,14 @@ speech:
performChecks: true
performUpdates: true
percona:
#### Prefer mysql over percona for now:
echo-http-server:
enabled: false
# mysqlUser: chainquery
# mysqlPassword: chainquery
# mysqlDatabase: chainquery
# persistence:
# enabled: true
# accessMode: ReadWriteOnce
# size: 100Gi
# resources:
# requests:
# memory: 1Gi
# cpu: 1
# Enter your domain name for the echo test service:
hostname: "echo.example.com"
service: echo-http-server
enableHttps: true
certificateIssuer: letsencrypt-prod
echo-socket-server:
enabled: false
service: echo-socket-server