diff --git a/Chart.yaml b/Chart.yaml new file mode 100644 index 0000000..2072634 --- /dev/null +++ b/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "1.0" +description: Ruby application that consumes Service Catalog bindings +name: ruby-with-binding +version: 0.1.0 diff --git a/README.md b/README.md new file mode 100644 index 0000000..f05999b --- /dev/null +++ b/README.md @@ -0,0 +1,25 @@ +# Spring Music for Kubernetes Service Catalog + +To deploy the sample Ruby/Sinatra application with a service instance/binding from your Service Catalog: + +```shell +helm upgrade --install show-me-secrets . \ + --set "database.service.class=cleardb,database.service.plan=spark" +``` + +In the example above, it is assumed that your Service Catalog has a service class "cleardb" with a service plan "spark". + +To run Spring Music without a database service instnace/binding: + +```shell +helm upgrade --install show-me-secrets . \ + --set "database.service.class=null" +``` + +## Clean up + +To remove the sample application: + +```shell +helm delete --purge show-me-secrets +``` \ No newline at end of file diff --git a/templates/NOTES.txt b/templates/NOTES.txt new file mode 100644 index 0000000..fd9549d --- /dev/null +++ b/templates/NOTES.txt @@ -0,0 +1,15 @@ +1. Get the application URL by running these commands: +{{- if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "ruby-with-binding.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 the status of by running 'kubectl get svc -w {{ include "ruby-with-binding.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "ruby-with-binding.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + 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 "ruby-with-binding.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:{{ .Values.service.port }} to use your application" + kubectl port-forward $POD_NAME {{ .Values.service.port }}:8080 +{{- end }} diff --git a/templates/_helpers.tpl b/templates/_helpers.tpl new file mode 100644 index 0000000..2dbc577 --- /dev/null +++ b/templates/_helpers.tpl @@ -0,0 +1,32 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "ruby-with-binding.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 "ruby-with-binding.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 "ruby-with-binding.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/templates/database-binding.yaml b/templates/database-binding.yaml new file mode 100644 index 0000000..1d9561c --- /dev/null +++ b/templates/database-binding.yaml @@ -0,0 +1,11 @@ +{{- if .Values.database.service.class -}} +# svcat bind app-db --name db-binding --secret-name db-secret +apiVersion: servicecatalog.k8s.io/v1beta1 +kind: ServiceBinding +metadata: + name: {{ include "ruby-with-binding.fullname" . }}-db-binding +spec: + instanceRef: + name: {{ include "ruby-with-binding.fullname" . }}-db-instance + secretName: {{ template "ruby-with-binding.fullname" . }}-db-secret +{{- end -}} \ No newline at end of file diff --git a/templates/database-instance.yaml b/templates/database-instance.yaml new file mode 100644 index 0000000..3074c9a --- /dev/null +++ b/templates/database-instance.yaml @@ -0,0 +1,10 @@ +{{- if .Values.database.service.class -}} +# svcat provision app-db --class cleardb --plan spark +apiVersion: servicecatalog.k8s.io/v1beta1 +kind: ServiceInstance +metadata: + name: {{ include "ruby-with-binding.fullname" . }}-db-instance +spec: + clusterServiceClassExternalName: {{ .Values.database.service.class }} + clusterServicePlanExternalName: {{ .Values.database.service.plan }} +{{- end -}} \ No newline at end of file diff --git a/templates/deployment.yaml b/templates/deployment.yaml new file mode 100644 index 0000000..285fbc6 --- /dev/null +++ b/templates/deployment.yaml @@ -0,0 +1,66 @@ +apiVersion: apps/v1beta2 +kind: Deployment +metadata: + name: {{ include "ruby-with-binding.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "ruby-with-binding.name" . }} + helm.sh/chart: {{ include "ruby-with-binding.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "ruby-with-binding.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "ruby-with-binding.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + {{- if .Values.database.service.class }} + env: + - name: DATABASE_URL + valueFrom: + secretKeyRef: + name: {{ template "ruby-with-binding.fullname" . }}-db-secret + key: uri + - name: DATABASE_JDBC_URL + valueFrom: + secretKeyRef: + name: {{ template "ruby-with-binding.fullname" . }}-db-secret + key: jdbcUrl + - name: DATABASE_USERNAME + valueFrom: + secretKeyRef: + name: {{ template "ruby-with-binding.fullname" . }}-db-secret + key: username + - name: DATABASE_PASSWORD + valueFrom: + secretKeyRef: + name: {{ template "ruby-with-binding.fullname" . }}-db-secret + key: password + {{- end }} + livenessProbe: + httpGet: + path: / + port: http + readinessProbe: + httpGet: + path: / + port: http + {{- if .Values.database.service.class }} + volumes: + - name: db-credentials + secret: + secretName: {{ template "ruby-with-binding.fullname" . }}-db-secret + {{- end }} \ No newline at end of file diff --git a/templates/service.yaml b/templates/service.yaml new file mode 100644 index 0000000..53a97f5 --- /dev/null +++ b/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "ruby-with-binding.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "ruby-with-binding.name" . }} + helm.sh/chart: {{ include "ruby-with-binding.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.port }} + targetPort: http + protocol: TCP + name: http + selector: + app.kubernetes.io/name: {{ include "ruby-with-binding.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/values.yaml b/values.yaml new file mode 100644 index 0000000..b43c4ec --- /dev/null +++ b/values.yaml @@ -0,0 +1,23 @@ +# Default values for ruby-with-binding. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +database: + service: + class: cleardb + plan: spark + +image: + repository: drnic/show-me-secrets-ruby + tag: latest + pullPolicy: Always + +nameOverride: "" +fullnameOverride: "" + +service: + type: ClusterIP + port: 3000 +