diff --git a/docs/examples/README.md b/docs/examples/README.md index 723040ca8..230354aa0 100644 --- a/docs/examples/README.md +++ b/docs/examples/README.md @@ -17,3 +17,9 @@ and it illustrates more complex template usage. It deploys a `deployment` (which creates a `replica set`), a `config map`, and a `service`. The replica set starts an nginx pod. The config map stores the files that the nginx server can serve. + +## Guestbook + +The `guestbook` chart is a simple multi-tier app. The first tier is Apache httpd-based app that uses Redis master-slave cluster (the second tier). + +The app comprises of `deployment` for the each tier that are accessible thru its corresponding `service` diff --git a/docs/examples/guestbook/.helmignore b/docs/examples/guestbook/.helmignore new file mode 100644 index 000000000..f0c131944 --- /dev/null +++ b/docs/examples/guestbook/.helmignore @@ -0,0 +1,21 @@ +# 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 +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/docs/examples/guestbook/Chart.yaml b/docs/examples/guestbook/Chart.yaml new file mode 100644 index 000000000..62b6cf0bf --- /dev/null +++ b/docs/examples/guestbook/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A guestbook Helm chart for Kubernetes. +name: guestbook +version: 0.1.0 diff --git a/docs/examples/guestbook/README.md b/docs/examples/guestbook/README.md new file mode 100644 index 000000000..dc4cd41bd --- /dev/null +++ b/docs/examples/guestbook/README.md @@ -0,0 +1,68 @@ +# Guestbook + +[Guestbook](https://github.com/kubernetes/examples/tree/master/guestbook) is a simple, multi-tier PHP-based web application that uses redis chart. +## TL;DR; + +```console +$ helm install stable/guestbook +``` + +## Introduction + +This chart bootstraps a [guestbook](https://github.com/kubernetes/examples/tree/master/guestbook) deployment on a [Kubernetes](http://kubernetes.io) cluster using the [Helm](https://helm.sh) package manager. + +It also packages the [Bitnami Redis chart](https://github.com/kubernetes/charts/tree/master/stable/redis) which is required for bootstrapping a Redis deployment for the caching requirements of the guestbook application. + +## Prerequisites + +- Kubernetes 1.4+ with Beta APIs enabled +- PV provisioner support in the underlying infrastructure + +## Installing the Chart + +To install the chart with the release name `my-release`: + +```console +$ helm install --name my-release stable/guestbook +``` + +The command deploys the guestbook on the Kubernetes cluster in the default configuration. The [configuration](#configuration) section lists the parameters that can be configured during installation. + +> **Tip**: List all releases using `helm list` + +## Uninstalling the Chart + +To uninstall/delete the `my-release` deployment: + +```console +$ helm delete my-release +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release. + +## Configuration + +The following tables lists the configurable parameters of the WordPress chart and their default values. + +| Parameter | Description | Default | +| ------------------------------- | ------------------------------- | ---------------------------------------------------------- | +| `image` | apapche-php image | `google-samples/gb-frontend:{VERSION}` | +| `imagePullPolicy` | Image pull policy | `IfNotPresent` | +| `nodeSelector` | Node labels for pod assignment | `{}` | + +The above parameters map to the env variables defined in [bitnami/wordpress](http://github.com/bitnami/bitnami-docker-wordpress). For more information please refer to the [bitnami/wordpress](http://github.com/bitnami/bitnami-docker-wordpress) image documentation. + +Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, + +```console +$ helm install --name my-release \ + --set redis.usePassword=false \ + stable/guestbook +``` + +```console +$ helm install --name my-release -f values.yaml stable/guestbook +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) + diff --git a/docs/examples/guestbook/charts/redis-1.1.4.tgz b/docs/examples/guestbook/charts/redis-1.1.4.tgz new file mode 100644 index 000000000..a000e0fec Binary files /dev/null and b/docs/examples/guestbook/charts/redis-1.1.4.tgz differ diff --git a/docs/examples/guestbook/requirements.lock b/docs/examples/guestbook/requirements.lock new file mode 100644 index 000000000..d2e8910c5 --- /dev/null +++ b/docs/examples/guestbook/requirements.lock @@ -0,0 +1,6 @@ +dependencies: +- name: redis + repository: https://kubernetes-charts.storage.googleapis.com/ + version: 1.1.4 +digest: sha256:ca7a601363b96fed2bf4774ef8fbc5cdbdb91a0fb5bc083192072e39eee844ae +generated: 2017-12-31T21:26:54.89952-08:00 diff --git a/docs/examples/guestbook/requirements.yaml b/docs/examples/guestbook/requirements.yaml new file mode 100644 index 000000000..2c222e728 --- /dev/null +++ b/docs/examples/guestbook/requirements.yaml @@ -0,0 +1,7 @@ +dependencies: +- name: redis + version: 1.1.4 + repository: https://kubernetes-charts.storage.googleapis.com/ + condition: redis.enabled + tags: + - redis-database diff --git a/docs/examples/guestbook/templates/NOTES.txt b/docs/examples/guestbook/templates/NOTES.txt new file mode 100644 index 000000000..8317fa08d --- /dev/null +++ b/docs/examples/guestbook/templates/NOTES.txt @@ -0,0 +1,19 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + http://{{ . }} +{{- end }} +{{- else if contains "NodePort" .Values.service.frontend.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "guestbook.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.frontend.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 {{ template "guestbook.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "guestbook.fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.externalPort }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "guestbook.name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:{{ .Values.service.internalPort }} +{{- end }} diff --git a/docs/examples/guestbook/templates/_helpers.tpl b/docs/examples/guestbook/templates/_helpers.tpl new file mode 100644 index 000000000..bb1d9afcd --- /dev/null +++ b/docs/examples/guestbook/templates/_helpers.tpl @@ -0,0 +1,19 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "guestbook.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). +*/}} +{{- define "guestbook.fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- define "redis.fullname" -}} +{{- printf "%s-%s" .Release.Name "redis" | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/docs/examples/guestbook/templates/deployment.yaml b/docs/examples/guestbook/templates/deployment.yaml new file mode 100644 index 000000000..e0f599f7b --- /dev/null +++ b/docs/examples/guestbook/templates/deployment.yaml @@ -0,0 +1,52 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "guestbook.fullname" . }} + labels: + app: {{ template "guestbook.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{ template "guestbook.name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.frontend.internalPort }} + livenessProbe: + httpGet: + path: / + port: {{ .Values.service.frontend.internalPort }} + readinessProbe: + httpGet: + path: / + port: {{ .Values.service.frontend.internalPort }} + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} + env: + - name: {{"GET_HOSTS_FROM"}} + value: {{"env"}} + - name: {{"REDIS_MASTER_SERVICE_HOST"}} + {{- if .Values.redis.enabled }} + value: {{ template "redis.fullname" . }} + {{- else }} + value: {{ .Values.externalDatabase.host | quote }} + {{- end }} + - name: {{"REDIS_SLAVE_SERVICE_HOST"}} + {{- if .Values.redis.enabled }} + value: {{ template "redis.fullname" . }} + {{- else }} + value: {{ .Values.externalDatabase.host | quote }} + {{- end }} diff --git a/docs/examples/guestbook/templates/ingress.yaml b/docs/examples/guestbook/templates/ingress.yaml new file mode 100644 index 000000000..108b2f03d --- /dev/null +++ b/docs/examples/guestbook/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if .Values.ingress.enabled -}} +{{- $serviceName := include "guestbook.fullname" . -}} +{{- $servicePort := .Values.service.externalPort -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "guestbook.fullname" . }} + labels: + app: {{ template "guestbook.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + annotations: + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + rules: + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host }} + http: + paths: + - path: / + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + {{- end -}} +{{- end -}} diff --git a/docs/examples/guestbook/templates/service.yaml b/docs/examples/guestbook/templates/service.yaml new file mode 100644 index 000000000..55aa34e48 --- /dev/null +++ b/docs/examples/guestbook/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "guestbook.fullname" . }} + labels: + app: {{ template "guestbook.name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.frontend.type }} + ports: + - port: {{ .Values.service.frontend.externalPort }} + targetPort: {{ .Values.service.frontend.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "guestbook.name" . }} + release: {{ .Release.Name }} diff --git a/docs/examples/guestbook/values.yaml b/docs/examples/guestbook/values.yaml new file mode 100644 index 000000000..de89ccca4 --- /dev/null +++ b/docs/examples/guestbook/values.yaml @@ -0,0 +1,44 @@ +# Default values for guestbook. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: + repository: gcr.io/google-samples/gb-frontend + tag: v4 + pullPolicy: IfNotPresent +service: + frontend: + type: LoadBalancer + externalPort: 80 + internalPort: 80 + selector: + app: guestbook + tier: frontend +ingress: + enabled: false + # Used to create an Ingress record. + #hosts: + # - chart-example.local + annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + tls: + # Secrets must be manually created in the namespace. + # - secretName: chart-example-tls + # hosts: + # - chart-example.local +resources: + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + limits: + cpu: 100m + memory: 128Mi + requests: + cpu: 100m + memory: 128Mi +redis: + enabled: true +externalDatabase: + host: localhost