Skip to content

Commit

Permalink
upd hpa
Browse files Browse the repository at this point in the history
  • Loading branch information
rajks24 committed Jul 17, 2023
1 parent 4b8985f commit d200778
Show file tree
Hide file tree
Showing 18 changed files with 140 additions and 83 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,18 @@ This repo is packed with some of the poc helm charts in various programming lang
## list of Charts

1. petclinic (Java)
2. helloapppython (Python)
2. helloapp (Python)
3. helloappjava (Java)

## TODOs

1. Add project in nodejs


## Contact

You can reach me on [Twitter @rajinh24](https://twitter.com/rajinh24)

## License

[![License](https://img.shields.io/github/license/rajks24/markdown-badges?style=flat-square&logo=github)](./LICENSE)
Binary file removed charts/demo-chart-test/extras/image.png
Binary file not shown.
15 changes: 0 additions & 15 deletions charts/demo-chart-test/templates/service.yaml

This file was deleted.

15 changes: 0 additions & 15 deletions charts/demo-chart-test/templates/tests/test-connection.yaml

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
name: demo-chart-test
name: helloapp
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
Expand All @@ -22,4 +22,3 @@ version: 0.1.0
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "1.16.0"

21 changes: 15 additions & 6 deletions charts/demo-chart-test/README.md → charts/helloappp/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
# helloapppython chart
# helloapp chart

## Introduction

This is a test api and webapp with some common functionalities to test various needs for development, environment setup and devops tools connectivity and workflows.

![App snapshot](extras/image.png)

## Image Usage

This helm chart has been tested with following app images

- For Java App use
Image: ghcr.io/rajks24/helloappjava:1.1.0
Github Project : https://github.com/rajks24/helloappjava

- For Python App use
Image: ghcr.io/rajks24/helloapppython:2.0
Github Project : https://github.com/rajks24/helloapppython


## Api's for the app

- Api to update the app version
Expand Down Expand Up @@ -34,8 +47,4 @@ This is a test api and webapp with some common functionalities to test various n

## Contact

You can reach me on [Twitter @rajinh24](https://twitter.com/rajinh24)

## License

[![License](https://img.shields.io/github/license/rajks24/markdown-badges?style=flat-square&logo=github)](./LICENSE)
You can reach me on [Twitter @rajinh24](https://twitter.com/rajinh24)
Binary file added charts/helloappp/extras/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions charts/helloappp/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
labels:
app.kubernetes.io/name: helloapp
name: test-helloapp
namespace: appns
spec:
maxReplicas: 100
metrics:
- resource:
name: cpu
target:
averageUtilization: 80
type: Utilization
type: Resource
minReplicas: 1
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: test-helloapp
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
1. Get the application URL by running these commands:
1. App image used for helloapp is {{ .Values.image.repository }}:{{ .Values.image.tag }}
2. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "demo-chart-test.fullname" . }})
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "helloapp.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 --namespace {{ .Release.Namespace }} svc -w {{ include "demo-chart-test.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "demo-chart-test.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "helloapp.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "helloapp.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
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 "demo-chart-test.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "helloapp.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "demo-chart-test.name" -}}
{{- define "helloapp.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

Expand All @@ -10,7 +10,7 @@ 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 "demo-chart-test.fullname" -}}
{{- define "helloapp.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
Expand All @@ -26,16 +26,16 @@ If release name contains chart name it will be used as a full name.
{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "demo-chart-test.chart" -}}
{{- define "helloapp.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "demo-chart-test.labels" -}}
helm.sh/chart: {{ include "demo-chart-test.chart" . }}
{{ include "demo-chart-test.selectorLabels" . }}
{{- define "helloapp.labels" -}}
helm.sh/chart: {{ include "helloapp.chart" . }}
{{ include "helloapp.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
Expand All @@ -45,17 +45,17 @@ app.kubernetes.io/managed-by: {{ .Release.Service }}
{{/*
Selector labels
*/}}
{{- define "demo-chart-test.selectorLabels" -}}
app.kubernetes.io/name: {{ include "demo-chart-test.name" . }}
{{- define "helloapp.selectorLabels" -}}
app.kubernetes.io/name: {{ include "helloapp.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "demo-chart-test.serviceAccountName" -}}
{{- define "helloapp.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "demo-chart-test.fullname" .) .Values.serviceAccount.name }}
{{- default (include "helloapp.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "demo-chart-test.fullname" . }}
name: {{ include "helloapp.fullname" . }}
labels:
{{- include "demo-chart-test.labels" . | nindent 4 }}
{{- include "helloapp.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "demo-chart-test.selectorLabels" . | nindent 6 }}
{{- include "helloapp.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "demo-chart-test.selectorLabels" . | nindent 8 }}
{{- include "helloapp.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "demo-chart-test.serviceAccountName" . }}
serviceAccountName: {{ include "helloapp.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
Expand All @@ -35,7 +35,7 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
containerPort: {{- if .Values.service.targetPort }} {{ .Values.service.targetPort }} {{- else }} {{ .Values.service.port }} {{- end }}
protocol: TCP
env:
- name: NODE_NAME
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
apiVersion: autoscaling/v1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "demo-chart-test.fullname" . }}
name: {{ include "helloapp.fullname" . }}
labels:
{{- include "demo-chart-test.labels" . | nindent 4 }}
{{- include "helloapp.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "demo-chart-test.fullname" . }}
name: {{ include "helloapp.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- 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 }}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{- if .Values.ingress.enabled -}}
{{- $fullName := include "demo-chart-test.fullname" . -}}
{{- $fullName := include "helloapp.fullname" . -}}
{{- $svcPort := .Values.service.port -}}
{{- if and .Values.ingress.className (not (semverCompare ">=1.18-0" .Capabilities.KubeVersion.GitVersion)) }}
{{- if not (hasKey .Values.ingress.annotations "kubernetes.io/ingress.class") }}
Expand All @@ -17,7 +17,7 @@ kind: Ingress
metadata:
name: {{ $fullName }}
labels:
{{- include "demo-chart-test.labels" . | nindent 4 }}
{{- include "helloapp.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
15 changes: 15 additions & 0 deletions charts/helloappp/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "helloapp.fullname" . }}
labels:
{{- include "helloapp.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
- port: {{ .Values.service.port }}
targetPort: {{- if .Values.service.targetPort }} {{ .Values.service.targetPort }} {{- else }} http {{- end }}
protocol: TCP
name: http
selector:
{{- include "helloapp.selectorLabels" . | nindent 4 }}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "demo-chart-test.serviceAccountName" . }}
name: {{ include "helloapp.serviceAccountName" . }}
labels:
{{- include "demo-chart-test.labels" . | nindent 4 }}
{{- include "helloapp.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
15 changes: 15 additions & 0 deletions charts/helloappp/templates/tests/test-connection.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: "{{ include "helloapp.fullname" . }}-test-connection"
labels:
{{- include "helloapp.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "helloapp.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
Loading

0 comments on commit d200778

Please sign in to comment.