Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap Kubernetes deployment for GLVD #78

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions 00_db-statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
apiVersion: v1
kind: Service
metadata:
name: glvd-database
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: database
spec:
selector:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: database
ports:
- protocol: TCP
port: 5432
name: postgres
targetPort: postgres
type: ClusterIP
clusterIP: None
---
# apiVersion: v1
# kind: Secret
# metadata:
# name: postgres-credentials
# labels:
# app.kubernetes.io/name: glvd
# gardenlinux.io/glvd-component: database
# stringData:
# username: glvd
# password: change-me-i-am-not-secure123
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: glvd-database
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: database
spec:
replicas: 1
serviceName: "glvd-database"
selector:
matchLabels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: database
template:
metadata:
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: database
spec:
containers:
- image: ghcr.io/gardenlinux/glvd-postgres:latest
name: glvd-postgres
ports:
- containerPort: 5432
protocol: TCP
name: postgres
env:
- name: POSTGRES_DATABASE
value: glvd
- name: POSTGRES_USER
valueFrom:
secretKeyRef:
name: postgres-credentials
key: username
- name: POSTGRES_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
- name: POSTGRES_HOST
value: glvd-postgres
- name: POSTGRES_PORT
value: "5432"
- name: PGDATA
value: /var/lib/postgresql/data/pgdata
volumeMounts:
- mountPath: "/var/lib/postgresql/data"
name: postgres-storage
volumeClaimTemplates:
- metadata:
name: postgres-storage
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
storageClassName: 'default'
118 changes: 118 additions & 0 deletions 01_glvd-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: glvd-config
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: glvd-tracker
data:
connectionString: jdbc:postgresql://glvd-database-0.glvd-database:5432/glvd
databaseName: glvd
---
apiVersion: v1
kind: Service
metadata:
name: glvd
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: glvd-tracker
spec:
ports:
- port: 8080
protocol: TCP
targetPort: glvd
selector:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: glvd-tracker
type: ClusterIP
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: glvd
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: glvd-tracker
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: glvd-tracker
template:
metadata:
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: glvd-tracker
spec:
containers:
- image: ghcr.io/gardenlinux/glvd-api:latest
name: glvd-api
# resources:
# requests:
# cpu: "1"
# memory: "2Gi"
# limits:
# cpu: "2"
# memory: "4Gi"
ports:
- containerPort: 8080
protocol: TCP
name: glvd
env:
# cf https://github.com/spring-projects/spring-lifecycle-smoke-tests/tree/main/data/data-jpa#prevent-early-database-interaction
- name: SPRING_DATASOURCE_URL
valueFrom:
configMapKeyRef:
name: glvd-config
key: connectionString
- name: SPRING_DATASOURCE_USERNAME
valueFrom:
secretKeyRef:
name: postgres-credentials
key: username
- name: SPRING_DATASOURCE_PASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
- name: SPRING_JPA_DATABASEPLATFORM
value: "org.hibernate.dialect.PostgreSQLDialect"
- name: SPRING_JPA_PROPERTIES_HIBERNATE_BOOT_ALLOW_JDBC_METADATA_ACCESS
value: "false"
- name: SPRING_JPA_HIBERNATE_DDLAUTO
value: "none"
- name: SPRING_SQL_INIT_MODE
value: "never"
livenessProbe:
httpGet:
path: "/actuator/health/liveness"
port: 8080
readinessProbe:
httpGet:
path: "/actuator/health/readiness"
port: 8080

---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: glvd-api-ingress
annotations:
cert.gardener.cloud/purpose: managed
spec:
rules:
- host: glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: glvd
port:
number: 8080
tls:
- hosts:
- glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com
secretName: glvd-ingress-tls
67 changes: 67 additions & 0 deletions 02_ingestion-job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: glvd-ingestion
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: glvd-ingestion
data:
databaseName: glvd
databaseHost: glvd-database-0.glvd-database
databasePort: "5432"
---
apiVersion: batch/v1
kind: Job
metadata:
name: glvd-ingestion
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: glvd-ingestion
spec:
template:
metadata:
labels:
app.kubernetes.io/name: glvd
gardenlinux.io/glvd-component: glvd-ingestion
spec:
restartPolicy: OnFailure
containers:
- name: data-ingestion
image: ghcr.io/gardenlinux/glvd:edge
resources:
requests:
cpu: "1"
memory: "2Gi"
limits:
cpu: "2"
memory: "4Gi"
command:
- /bin/bash
- -c
- sleep 5 && echo start && /usr/local/src/ingest-postgres.sh && echo done && sleep infinity
env:
- name: PGDATABASE
valueFrom:
configMapKeyRef:
name: glvd-ingestion
key: databaseName
- name: PGUSER
valueFrom:
secretKeyRef:
name: postgres-credentials
key: username
- name: PGPASSWORD
valueFrom:
secretKeyRef:
name: postgres-credentials
key: password
- name: PGHOST
valueFrom:
configMapKeyRef:
name: glvd-ingestion
key: databaseHost
- name: PGPORT
valueFrom:
configMapKeyRef:
name: glvd-ingestion
key: databasePort
23 changes: 23 additions & 0 deletions charts/glvd/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
6 changes: 6 additions & 0 deletions charts/glvd/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v2
name: glvd
description: A Helm chart for glvd
type: application
version: 0.1.0
appVersion: "0.0.1"
22 changes: 22 additions & 0 deletions charts/glvd/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "glvd.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "glvd.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "glvd.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "glvd.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
62 changes: 62 additions & 0 deletions charts/glvd/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "glvd.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "glvd.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "glvd.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "glvd.labels" -}}
helm.sh/chart: {{ include "glvd.chart" . }}
{{ include "glvd.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "glvd.selectorLabels" -}}
app.kubernetes.io/name: {{ include "glvd.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "glvd.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "glvd.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
Loading