ci: add kubernetes helm chart and gcp deployment (#1854)

* ci: add kubernetes helm chart and gcp deployment

* use official or parity's docker images only
This commit is contained in:
gabriel klawitter
2019-02-27 12:37:10 +01:00
committed by GitHub
parent 5282615416
commit f5c32f71f4
11 changed files with 425 additions and 37 deletions
@@ -0,0 +1,10 @@
apiVersion: policy/v1beta1
kind: PodDisruptionBudget
metadata:
name: substrate
spec:
selector:
matchLabels:
app: substrate
maxUnavailable: 1
@@ -0,0 +1,11 @@
{{- if .Values.validator.keys }}
apiVersion: v1
kind: Secret
metadata:
name: substrate-secrets
labels:
app: substrate
type: Opaque
data:
secrets: {{ .Values.validator.keys | default "" }}
{{- end }}
@@ -0,0 +1,39 @@
# see:
# https://kubernetes.io/docs/tutorials/services/
# https://kubernetes.io/docs/concepts/services-networking/service/
# headless service for rpc
apiVersion: v1
kind: Service
metadata:
name: substrate-rpc
labels:
app: substrate
spec:
ports:
- port: 9933
name: http-rpc
- port: 9944
name: websocket-rpc
selector:
app: substrate
sessionAffinity: None
type: ClusterIP
clusterIP: None
---
apiVersion: v1
kind: Service
metadata:
name: substrate
spec:
ports:
- port: 30333
name: p2p
nodePort: 30333
protocol: TCP
selector:
app: substrate
sessionAffinity: None
type: NodePort
# don't route exteral traffic to non-local pods
externalTrafficPolicy: Local
@@ -0,0 +1,10 @@
{{- if .Values.rbac.enable }}
# service account for substrate pods themselves
# no permissions for the api are required
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
app: substrate
name: {{ .Values.rbac.name }}
{{- end }}
@@ -0,0 +1,135 @@
# https://kubernetes.io/docs/tutorials/stateful-application/basic-stateful-set/
# https://cloud.google.com/kubernetes-engine/docs/concepts/statefulset
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: substrate
spec:
selector:
matchLabels:
app: substrate
serviceName: substrate
replicas: {{ .Values.nodes.replicas }}
updateStrategy:
type: RollingUpdate
podManagementPolicy: Parallel
template:
metadata:
labels:
app: substrate
spec:
{{- if .Values.rbac.enable }}
serviceAccountName: {{ .Values.rbac.name }}
{{- else }}
serviceAccountName: default
{{- end }}
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node
operator: In
values:
- substrate
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: "app"
operator: In
values:
- substrate
topologyKey: "kubernetes.io/hostname"
terminationGracePeriodSeconds: 300
{{- if .Values.validator.keys }}
volumes:
- name: substrate-validator-secrets
secret:
secretName: substrate-secrets
initContainers:
- name: prepare-secrets
image: busybox
command: [ "/bin/sh" ]
args:
- -c
- sed -n -r "s/^${POD_NAME}-key ([^ ]+)$/\1/p" /etc/validator/secrets > {{ .Values.image.basepath }}/key;
sed -n -r "s/^${POD_NAME}-node-key ([^ ]+)$/\1/p" /etc/validator/secrets > {{ .Values.image.basepath }}/node-key
env:
# from (workaround for hostname)
# https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
volumeMounts:
- name: substrate-validator-secrets
readOnly: true
mountPath: "/etc/validator"
- name: substratedir
mountPath: {{ .Values.image.basepath }}
{{- end }}
containers:
- name: substrate
imagePullPolicy: "{{ .Values.image.pullPolicy }}"
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
{{- if .Values.resources }}
resources:
requests:
memory: {{ .Values.resources.memory }}
cpu: {{ .Values.resources.cpu }}
{{- end }}
ports:
- containerPort: 30333
name: p2p
- containerPort: 9933
name: http-rpc
- containerPort: 9944
name: websocket-rpc
command: ["/bin/sh"]
args:
- -c
- exec /usr/local/bin/substrate
--base-path {{ .Values.image.basepath }}
--name $(POD_NAME)
{{- if .Values.validator.enable }}
--validator
{{- end }}
{{- if .Values.validator.keys }}
--key $(cat {{ .Values.image.basepath }}/key)
--node-key $(cat {{ .Values.image.basepath }}/node-key)
{{- end }}
{{- range .Values.nodes.args }} {{ . }} {{- end }}
env:
- name: POD_NAME
valueFrom:
fieldRef:
fieldPath: metadata.name
volumeMounts:
- name: substratedir
mountPath: {{ .Values.image.basepath }}
readinessProbe:
httpGet:
path: /health
port: http-rpc
initialDelaySeconds: 10
periodSeconds: 10
livenessProbe:
httpGet:
path: /health
port: http-rpc
initialDelaySeconds: 10
periodSeconds: 10
securityContext:
runAsUser: 1000
fsGroup: 1000
volumeClaimTemplates:
- metadata:
name: substratedir
spec:
accessModes: [ "ReadWriteOnce" ]
storageClassName: ssd
resources:
requests:
storage: 32Gi