helm chart with service provision/binding
This commit is contained in:
parent
b3e06bc48c
commit
fc2890a665
|
@ -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
|
|
@ -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
|
||||
```
|
|
@ -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 }}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 -}}
|
|
@ -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 }}
|
|
@ -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 }}
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue