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

Improve manifest for reliability #8

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<title>ExampleApp</title>
<script>
function load() {
setTimeout(function() {location=''}, 50)
setTimeout(function() {location=''}, 1000)
}
window.onload = load;
</script>
Expand Down
24 changes: 22 additions & 2 deletions kubernetes/helm/ecsdemo-frontend/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,33 @@ spec:
protocol: TCP
env:
- name: CRYSTAL_URL
value: http://ecsdemo-crystal.{{ .Values.ecsdemoCrystal.namespace }}.svc.cluster.local/crystal
value: http://ecsdemo-crystal.{{ .Values.ecsdemoCrystal.namespace }}.svc.cluster.local./crystal
- name: NODEJS_URL
value: http://ecsdemo-nodejs.{{ .Values.ecsdemoNodejs.namespace }}.svc.cluster.local/
value: http://ecsdemo-nodejs.{{ .Values.ecsdemoNodejs.namespace }}.svc.cluster.local./
livenessProbe:
failureThreshold: 3
httpGet:
path: /
port: http
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 10
initialDelaySeconds: 60
readinessProbe:
failureThreshold: 3
httpGet:
path: /
port: http
scheme: HTTP
periodSeconds: 10
successThreshold: 1
timeoutSeconds: 10
initialDelaySeconds: 60
lifecycle:
preStop:
exec:
command: ["/bin/sh", "-c", "sleep 180"]
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
Expand All @@ -64,3 +80,7 @@ spec:
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.topologySpreadConstraints }}
topologySpreadConstraints:
{{- toYaml . | nindent 8 }}
{{- end }}
10 changes: 7 additions & 3 deletions kubernetes/helm/ecsdemo-frontend/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "ecsdemo-frontend.fullname" . }}
Expand All @@ -17,12 +17,16 @@ spec:
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
target:
type: Utilization
averageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions kubernetes/helm/ecsdemo-frontend/templates/pdb.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- if .Values.pdb.enabled }}
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: {{ include "ecsdemo-frontend.fullname" . }}
labels:
{{- include "ecsdemo-frontend.labels" . | nindent 4 }}
spec:
maxUnavailable: 1
selector:
matchLabels:
app.kubernetes.io/name: {{ include "ecsdemo-frontend.fullname" . }}
{{- end }}
2 changes: 2 additions & 0 deletions kubernetes/helm/ecsdemo-frontend/templates/service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ metadata:
name: {{ include "ecsdemo-frontend.fullname" . }}
labels:
{{- include "ecsdemo-frontend.labels" . | nindent 4 }}
annotations:
service.kubernetes.io/topology-aware-hints: auto
spec:
type: {{ .Values.service.type }}
ports:
Expand Down
27 changes: 18 additions & 9 deletions kubernetes/helm/ecsdemo-frontend/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ image:
repository: public.ecr.aws/aws-containers/ecsdemo-frontend
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"
tag: 'latest'

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""
nameOverride: ''
fullnameOverride: ''

serviceAccount:
# Specifies whether a service account should be created
Expand All @@ -25,14 +25,16 @@ serviceAccount:
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""
name: ''

podAnnotations: {}

podSecurityContext: {}
podSecurityContext:
{}
# fsGroup: 2000

securityContext: {}
securityContext:
{}
# capabilities:
# drop:
# - ALL
Expand All @@ -46,8 +48,9 @@ service:

ingress:
enabled: false
className: ""
annotations: {}
className: ''
annotations:
{}
# kubernetes.io/ingress.class: nginx
# kubernetes.io/tls-acme: "true"
hosts:
Expand All @@ -60,7 +63,8 @@ ingress:
# hosts:
# - chart-example.local

resources: {}
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
Expand All @@ -79,8 +83,13 @@ autoscaling:
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80

pdb:
enabled: true

nodeSelector: {}

tolerations: []

affinity: {}

topologySpreadConstraints: []
8 changes: 6 additions & 2 deletions startup-cdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,17 @@ if [[ "${orchestrator}" == 'kubernetes' ]]; then
fi
fi



if [[ ${orchestrator} == 'unknown' ]]; then
zone=$(curl -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
zone=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
fi

# Am I on ec2 instances?
if [[ ${zone} == "unknown" ]]; then
zone=$(curl -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
zone=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -m2 -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.availabilityZone' | grep -o .$)
fi

# Still no luck? Perhaps we're running fargate!
Expand Down