-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add canary deployment demo chart based on podinfo
- Loading branch information
1 parent
27de9ce
commit 12d2687
Showing
12 changed files
with
477 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
apiVersion: v1 | ||
version: 2.0.0 | ||
appVersion: 1.4.0 | ||
name: podinfo | ||
engine: gotpl | ||
description: Flagger canary deployment demo chart | ||
home: https://github.com/stefanprodan/flagger | ||
maintainers: | ||
- email: stefanprodan@users.noreply.github.com | ||
name: stefanprodan | ||
sources: | ||
- https://github.com/stefanprodan/flagger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Podinfo | ||
|
||
Podinfo is a tiny web application made with Go | ||
that showcases best practices of running canary deployments with Flagger and Istio. | ||
|
||
## Installing the Chart | ||
|
||
Add Flagger Helm repository: | ||
|
||
```console | ||
helm repo add flagger https://flagger.app | ||
``` | ||
|
||
To install the chart with the release name `frontend`: | ||
|
||
```console | ||
helm upgrade -i frontend flagger/podinfo \ | ||
--namespace test \ | ||
--set nameOverride=frontend \ | ||
--set backend=http://backend.test:9898/echo \ | ||
--set canary.enabled=true \ | ||
--set canary.istioIngress.enabled=true \ | ||
--set canary.istioIngress.gateway=public-gateway.istio-system.svc.cluster.local \ | ||
--set canary.istioIngress.host=frontend.istio.example.com | ||
``` | ||
|
||
To install the chart as `backend`: | ||
|
||
```console | ||
helm upgrade -i backend flagger/podinfo \ | ||
--namespace test \ | ||
--set nameOverride=backend \ | ||
--set canary.enabled=true | ||
``` | ||
|
||
## Uninstalling the Chart | ||
|
||
To uninstall/delete the `frontend` deployment: | ||
|
||
```console | ||
$ helm delete --purge frontend | ||
``` | ||
|
||
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 podinfo chart and their default values. | ||
|
||
Parameter | Description | Default | ||
--- | --- | --- | ||
`image.repository` | image repository | `quay.io/stefanprodan/podinfo` | ||
`image.tag` | image tag | `<VERSION>` | ||
`image.pullPolicy` | image pull policy | `IfNotPresent` | ||
`hpa.enabled` | enables HPA | `true` | ||
`hpa.cpu` | target CPU usage per pod | `80` | ||
`hpa.memory` | target memory usage per pod | `512Mi` | ||
`hpa.minReplicas` | maximum pod replicas | `2` | ||
`hpa.maxReplicas` | maximum pod replicas | `4` | ||
`resources.requests/cpu` | pod CPU request | `1m` | ||
`resources.requests/memory` | pod memory request | `16Mi` | ||
`backend` | backend URL | None | ||
`faults.delay` | random HTTP response delays between 0 and 5 seconds | `false` | ||
`faults.error` | 1/3 chances of a random HTTP response error | `false` | ||
|
||
Specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. For example, | ||
|
||
```console | ||
$ helm install flagger/podinfo --name frontend \ | ||
--set=image.tag=1.4.1,hpa.enabled=false | ||
``` | ||
|
||
Alternatively, a YAML file that specifies the values for the above parameters can be provided while installing the chart. For example, | ||
|
||
```console | ||
$ helm install flagger/podinfo --name frontend -f values.yaml | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
podinfo {{ .Release.Name }} deployed! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{{/* vim: set filetype=mustache: */}} | ||
{{/* | ||
Expand the name of the chart. | ||
*/}} | ||
{{- define "podinfo.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 "podinfo.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 "podinfo.chart" -}} | ||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} | ||
{{- end -}} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{{- if .Values.canary.enabled }} | ||
apiVersion: flagger.app/v1alpha3 | ||
kind: Canary | ||
metadata: | ||
name: {{ template "podinfo.fullname" . }} | ||
labels: | ||
app: {{ template "podinfo.name" . }} | ||
chart: {{ template "podinfo.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
spec: | ||
targetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: {{ template "podinfo.fullname" . }} | ||
progressDeadlineSeconds: 60 | ||
autoscalerRef: | ||
apiVersion: autoscaling/v2beta1 | ||
kind: HorizontalPodAutoscaler | ||
name: {{ template "podinfo.fullname" . }} | ||
service: | ||
port: {{ .Values.service.port }} | ||
{{- if .Values.canary.istioIngress.enabled }} | ||
gateways: | ||
- {{ .Values.canary.istioIngress.gateway }} | ||
hosts: | ||
- {{ .Values.canary.istioIngress.host }} | ||
{{- end }} | ||
canaryAnalysis: | ||
interval: {{ .Values.canary.analysis.interval }} | ||
threshold: {{ .Values.canary.analysis.threshold }} | ||
maxWeight: {{ .Values.canary.analysis.maxWeight }} | ||
stepWeight: {{ .Values.canary.analysis.stepWeight }} | ||
metrics: | ||
- name: istio_requests_total | ||
threshold: {{ .Values.canary.thresholds.successRate }} | ||
interval: 1m | ||
- name: istio_request_duration_seconds_bucket | ||
threshold: {{ .Values.canary.thresholds.latency }} | ||
interval: 1m | ||
{{- if .Values.canary.loadtest.enabled }} | ||
webhooks: | ||
- name: load-test-get | ||
url: {{ .Values.canary.loadtest.url }} | ||
timeout: 5s | ||
metadata: | ||
cmd: "hey -z 1m -q 5 -c 2 http://{{ template "podinfo.fullname" . }}.{{ .Release.Namespace }}:{{ .Values.service.port }}" | ||
- name: load-test-post | ||
url: {{ .Values.canary.loadtest.url }} | ||
timeout: 5s | ||
metadata: | ||
cmd: "hey -z 1m -q 5 -c 2 -m POST -d '{\"test\": true}' http://{{ template "podinfo.fullname" . }}.{{ .Release.Namespace }}:{{ .Values.service.port }}/echo" | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: {{ template "podinfo.fullname" . }} | ||
labels: | ||
app: {{ template "podinfo.name" . }} | ||
chart: {{ template "podinfo.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
spec: | ||
strategy: | ||
type: RollingUpdate | ||
rollingUpdate: | ||
maxUnavailable: 1 | ||
selector: | ||
matchLabels: | ||
app: {{ template "podinfo.fullname" . }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ template "podinfo.fullname" . }} | ||
annotations: | ||
prometheus.io/scrape: 'true' | ||
spec: | ||
terminationGracePeriodSeconds: 30 | ||
containers: | ||
- name: {{ .Chart.Name }} | ||
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" | ||
imagePullPolicy: {{ .Values.image.pullPolicy }} | ||
command: | ||
- ./podinfo | ||
- --port={{ .Values.service.port }} | ||
- --level={{ .Values.logLevel }} | ||
- --random-delay={{ .Values.faults.delay }} | ||
- --random-error={{ .Values.faults.error }} | ||
env: | ||
{{- if .Values.message }} | ||
- name: PODINFO_UI_MESSAGE | ||
value: {{ .Values.message }} | ||
{{- end }} | ||
{{- if .Values.backend }} | ||
- name: PODINFO_BACKEND_URL | ||
value: {{ .Values.backend }} | ||
{{- end }} | ||
ports: | ||
- name: http | ||
containerPort: {{ .Values.service.port }} | ||
protocol: TCP | ||
livenessProbe: | ||
exec: | ||
command: | ||
- podcli | ||
- check | ||
- http | ||
- localhost:{{ .Values.service.port }}/healthz | ||
initialDelaySeconds: 5 | ||
timeoutSeconds: 5 | ||
readinessProbe: | ||
exec: | ||
command: | ||
- podcli | ||
- check | ||
- http | ||
- localhost:{{ .Values.service.port }}/readyz | ||
initialDelaySeconds: 5 | ||
timeoutSeconds: 5 | ||
volumeMounts: | ||
- name: data | ||
mountPath: /data | ||
resources: | ||
{{ toYaml .Values.resources | indent 12 }} | ||
{{- with .Values.nodeSelector }} | ||
nodeSelector: | ||
{{ toYaml . | indent 8 }} | ||
{{- end }} | ||
{{- with .Values.affinity }} | ||
affinity: | ||
{{ toYaml . | indent 8 }} | ||
{{- end }} | ||
{{- with .Values.tolerations }} | ||
tolerations: | ||
{{ toYaml . | indent 8 }} | ||
{{- end }} | ||
volumes: | ||
- name: data | ||
emptyDir: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{{- if .Values.hpa.enabled -}} | ||
apiVersion: autoscaling/v2beta1 | ||
kind: HorizontalPodAutoscaler | ||
metadata: | ||
name: {{ template "podinfo.fullname" . }} | ||
spec: | ||
scaleTargetRef: | ||
apiVersion: apps/v1beta2 | ||
kind: Deployment | ||
name: {{ template "podinfo.fullname" . }} | ||
minReplicas: {{ .Values.hpa.minReplicas }} | ||
maxReplicas: {{ .Values.hpa.maxReplicas }} | ||
metrics: | ||
{{- if .Values.hpa.cpu }} | ||
- type: Resource | ||
resource: | ||
name: cpu | ||
targetAverageUtilization: {{ .Values.hpa.cpu }} | ||
{{- end }} | ||
{{- if .Values.hpa.memory }} | ||
- type: Resource | ||
resource: | ||
name: memory | ||
targetAverageValue: {{ .Values.hpa.memory }} | ||
{{- end }} | ||
{{- if .Values.hpa.requests }} | ||
- type: Pod | ||
pods: | ||
metricName: http_requests | ||
targetAverageValue: {{ .Values.hpa.requests }} | ||
{{- end }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{{- if not .Values.canary.enabled }} | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: {{ template "podinfo.fullname" . }} | ||
labels: | ||
app: {{ template "podinfo.name" . }} | ||
chart: {{ template "podinfo.chart" . }} | ||
release: {{ .Release.Name }} | ||
heritage: {{ .Release.Service }} | ||
spec: | ||
type: {{ .Values.service.type }} | ||
ports: | ||
- port: {{ .Values.service.port }} | ||
targetPort: http | ||
protocol: TCP | ||
name: http | ||
selector: | ||
app: {{ template "podinfo.fullname" . }} | ||
{{- end }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{{- $suffix := "" -}} | ||
{{- if .Values.canary.enabled -}} | ||
{{- $suffix = "-primary" -}} | ||
{{- end -}} | ||
{{- $url := printf "%s%s:%v" (include "podinfo.fullname" .) $suffix .Values.service.port -}} | ||
apiVersion: v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: {{ template "podinfo.fullname" . }}-tests | ||
labels: | ||
heritage: {{ .Release.Service }} | ||
release: {{ .Release.Name }} | ||
chart: {{ .Chart.Name }}-{{ .Chart.Version }} | ||
app: {{ template "podinfo.name" . }} | ||
data: | ||
run.sh: |- | ||
@test "HTTP POST /echo" { | ||
run curl --retry 3 --connect-timeout 2 -sSX POST -d 'test' {{ $url }}/echo | ||
[ $output = "test" ] | ||
} | ||
@test "HTTP POST /store" { | ||
curl --retry 3 --connect-timeout 2 -sSX POST -d 'test' {{ $url }}/store | ||
} | ||
@test "HTTP GET /" { | ||
curl --retry 3 --connect-timeout 2 -sS {{ $url }} | grep hostname | ||
} |
Oops, something went wrong.