Skip to content

Commit

Permalink
lab 10 improved
Browse files Browse the repository at this point in the history
  • Loading branch information
smasIner committed Nov 16, 2024
1 parent 87e08a5 commit 39d5e19
Show file tree
Hide file tree
Showing 19 changed files with 86 additions and 153 deletions.
40 changes: 0 additions & 40 deletions k8s/HELM.md

This file was deleted.

22 changes: 0 additions & 22 deletions k8s/deployment.yml

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion k8s/your-app/Chart.yaml → k8s/helmapp/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
apiVersion: v2
name: your-app
name: helmapp
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
{{- 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 "your-app.fullname" . }})
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "helmapp.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 its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "your-app.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "your-app.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
You can watch its status by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "helmapp.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "helmapp.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 "your-app.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 "helmapp.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 "your-app.name" -}}
{{- define "helmapp.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 "your-app.fullname" -}}
{{- define "helmapp.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 "your-app.chart" -}}
{{- define "helmapp.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "your-app.labels" -}}
helm.sh/chart: {{ include "your-app.chart" . }}
{{ include "your-app.selectorLabels" . }}
{{- define "helmapp.labels" -}}
helm.sh/chart: {{ include "helmapp.chart" . }}
{{ include "helmapp.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 "your-app.selectorLabels" -}}
app.kubernetes.io/name: {{ include "your-app.name" . }}
{{- define "helmapp.selectorLabels" -}}
app.kubernetes.io/name: {{ include "helmapp.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "your-app.serviceAccountName" -}}
{{- define "helmapp.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "your-app.fullname" .) .Values.serviceAccount.name }}
{{- default (include "helmapp.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "your-app.fullname" . }}
name: {{ include "helmapp.fullname" . }}
labels:
{{- include "your-app.labels" . | nindent 4 }}
{{- include "helmapp.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "your-app.selectorLabels" . | nindent 6 }}
{{- include "helmapp.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "your-app.labels" . | nindent 8 }}
{{- include "helmapp.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
Expand All @@ -27,7 +27,7 @@ spec:
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "your-app.serviceAccountName" . }}
serviceAccountName: {{ include "helmapp.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
Expand All @@ -38,7 +38,7 @@ spec:
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }}
containerPort: {{ .Values.service.port }} # gets it from values
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "your-app.fullname" . }}
name: {{ include "helmapp.fullname" . }}
labels:
{{- include "your-app.labels" . | nindent 4 }}
{{- include "helmapp.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "your-app.fullname" . }}
name: {{ include "helmapp.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: {{ include "your-app.fullname" . }}
name: {{ include "helmapp.fullname" . }}
labels:
{{- include "your-app.labels" . | nindent 4 }}
{{- include "helmapp.labels" . | nindent 4 }}
{{- with .Values.ingress.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down Expand Up @@ -35,7 +35,7 @@ spec:
{{- end }}
backend:
service:
name: {{ include "your-app.fullname" $ }}
name: {{ include "helmapp.fullname" $ }}
port:
number: {{ $.Values.service.port }}
{{- end }}
Expand Down
15 changes: 15 additions & 0 deletions k8s/helmapp/templates/post-install-hook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: postinstall-hook
annotations:
"helm.sh/hook": "post-install"
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
spec:
containers:
- name: post-install-container
image: busybox
imagePullPolicy: Always
command: ['sh', '-c', 'echo The post-install hook is running && sleep 15' ]
restartPolicy: Never
terminationGracePeriodSeconds: 0
15 changes: 15 additions & 0 deletions k8s/helmapp/templates/pre-install-hook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: v1
kind: Pod
metadata:
name: preinstall-hook
annotations:
"helm.sh/hook": "pre-install"
"helm.sh/hook-delete-policy": hook-succeeded,hook-failed
spec:
containers:
- name: pre-install-container
image: busybox
imagePullPolicy: IfNotPresent
command: ['sh', '-c', 'echo The pre-install hook is running && sleep 20' ]
restartPolicy: Never
terminationGracePeriodSeconds: 0
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
apiVersion: v1
kind: Service
metadata:
name: {{ include "your-app.fullname" . }}
name: {{ include "helmapp.fullname" . }}
labels:
{{- include "your-app.labels" . | nindent 4 }}
{{- include "helmapp.labels" . | nindent 4 }}
spec:
type: {{ .Values.service.type }}
ports:
Expand All @@ -12,4 +12,4 @@ spec:
protocol: TCP
name: http
selector:
{{- include "your-app.selectorLabels" . | nindent 4 }}
{{- include "helmapp.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 "your-app.serviceAccountName" . }}
name: {{ include "helmapp.serviceAccountName" . }}
labels:
{{- include "your-app.labels" . | nindent 4 }}
{{- include "helmapp.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
Expand Down
15 changes: 15 additions & 0 deletions k8s/helmapp/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 "helmapp.fullname" . }}-test-connection"
labels:
{{- include "helmapp.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": test
spec:
containers:
- name: wget
image: busybox
command: ['wget']
args: ['{{ include "helmapp.fullname" . }}:{{ .Values.service.port }}']
restartPolicy: Never
17 changes: 9 additions & 8 deletions k8s/your-app/values.yaml → k8s/helmapp/values.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Default values for your-app.
# Default values for helmapp.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

Expand Down Expand Up @@ -85,14 +85,15 @@ resources: {}
# cpu: 100m
# memory: 128Mi


# This is to setup the liveness and readiness probes more information can be found here: https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
## httpGet:
## port: http
#readinessProbe:
# httpGet:
# path: /
# port: http
livenessProbe:
httpGet:
path: /
port: http
readinessProbe:
httpGet:
path: /
port: http

# This section is for setting up autoscaling more information can be found here: https://kubernetes.io/docs/concepts/workloads/autoscaling/
autoscaling:
Expand Down
12 changes: 0 additions & 12 deletions k8s/service.yml

This file was deleted.

12 changes: 0 additions & 12 deletions k8s/your-app/templates/postinstall-hook.yaml

This file was deleted.

12 changes: 0 additions & 12 deletions k8s/your-app/templates/preinstall-hook.yaml

This file was deleted.

Loading

0 comments on commit 39d5e19

Please sign in to comment.