Skip to content

Commit

Permalink
lab 12 part2 done
Browse files Browse the repository at this point in the history
  • Loading branch information
smasIner committed Nov 16, 2024
1 parent a5bba4d commit af98095
Show file tree
Hide file tree
Showing 8 changed files with 146 additions and 5 deletions.
4 changes: 4 additions & 0 deletions app_python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,8 @@ All steps are chained with needs:

docker-compose build

<<<<<<< Updated upstream
docker-compose up
=======
docker-compose up
>>>>>>> Stashed changes
4 changes: 4 additions & 0 deletions app_python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ def visits():
if not os.path.exists('visits'):
os.makedirs('visits')

<<<<<<< Updated upstream
app.run(debug=True, host='0.0.0.0', port=8080)
=======
app.run(debug=True, host='0.0.0.0', port=8080)
>>>>>>> Stashed changes
31 changes: 31 additions & 0 deletions k8s/12.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< Updated upstream
```bash
apiVersion: v1
kind: ConfigMap
Expand All @@ -20,4 +21,34 @@ data:
kubectl exec your-app-77c6ff4fdc-l8fql -- cat /config.json
cat: can't open '/config.json': No such file or directory
=======
# 2 outputs
```bash
(venv) smasiner@smasIners-MacBook-Pro k8s % helm upgrade helmapp ./helmapp
Release "helmapp" has been upgraded. Happy Helming!
NAME: helmapp
LAST DEPLOYED: Sat Nov 16 23:33:05 2024
NAMESPACE: default
STATUS: deployed
REVISION: 3
NOTES:
1. Get the application URL by running these commands:
export POD_NAME=$(kubectl get pods --namespace default -l "app.kubernetes.io/name=helmapp,app.kubernetes.io/instance=helmapp" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace default $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace default port-forward $POD_NAME 8080:$CONTAINER_PORT
(venv) smasiner@smasIners-MacBook-Pro k8s % kubectl get pods
NAME READY STATUS RESTARTS AGE
helmapp-5d4558f75f-qj9tk 1/1 Running 0 4m11s
helmapp-7dfd8bd68-g7cv4 0/1 Running 0 9s
(venv) smasiner@smasIners-MacBook-Pro k8s % kubectl get pods
NAME READY STATUS RESTARTS AGE
helmapp-7dfd8bd68-g7cv4 1/1 Running 0 16s
(venv) smasiner@smasIners-MacBook-Pro k8s % kubectl exec helmapp-7dfd8bd68-g7cv4 -- cat /config.json
{
"abra": "kadabra",
"abraabra": "abc"
}%
>>>>>>> Stashed changes
```
5 changes: 5 additions & 0 deletions k8s/helmapp/files/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"abra": "kadabra",
"abraabra": "abc"
}

77 changes: 77 additions & 0 deletions k8s/helmapp/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "helmapp.fullname" . }}
labels:
{{- include "helmapp.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "helmapp.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "helmapp.labels" . | nindent 8 }}
{{- with .Values.podLabels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "helmapp.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
ports:
- name: http
containerPort: {{ .Values.service.port }} # gets it from values
protocol: TCP
livenessProbe:
{{- toYaml .Values.livenessProbe | nindent 12 }}
readinessProbe:
{{- toYaml .Values.readinessProbe | nindent 12 }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.volumeMounts }}
volumeMounts:
{{- toYaml . | nindent 12 }}
envFrom:
- configMapRef:
name: env-configmap
{{- end }}
env:
- name: MY_PASS
valueFrom:
secretKeyRef:
name: my-secret
key: MY_PASS
{{- with .Values.volumes }}
volumes:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
10 changes: 10 additions & 0 deletions k8s/your-app/templates/configmap.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< Updated upstream:k8s/your-app/templates/configmap.yaml
#https://stackoverflow.com/questions/64662568/how-can-i-use-a-json-file-in-my-configmap-yaml-helm
apiVersion: v1
kind: ConfigMap
Expand All @@ -6,3 +7,12 @@ metadata:
data:
config.json: |
{{ .Files.Get "files/config.json" | indent 4 }}
=======
apiVersion: v1
kind: ConfigMap
metadata:
name: config-configmap
data:
config.json: |-
{{ .Files.Get "files/config.json" | indent 4}}
>>>>>>> Stashed changes:k8s/helmapp/templates/configmap.yaml
6 changes: 6 additions & 0 deletions k8s/your-app/templates/env-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: env-configmap
data:
MY_SECRET: "a"
14 changes: 9 additions & 5 deletions k8s/your-app/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,21 @@ autoscaling:
# targetMemoryUtilizationPercentage: 80

# Additional volumes on the output Deployment definition.
volumes: []
volumes:
- name: config
configMap:
name: config-configmap
# - name: foo
# secret:
# secretName: mysecret
# optional: false

# Additional volumeMounts on the output Deployment definition.
volumeMounts: []
# - name: foo
# mountPath: "/etc/foo"
# readOnly: true
volumeMounts:
- name: config
mountPath: "/config.json"
subPath: config.json
readOnly: true

nodeSelector: {}

Expand Down

0 comments on commit af98095

Please sign in to comment.