Skip to content
This repository has been archived by the owner on Dec 20, 2021. It is now read-only.

Commit

Permalink
Lab 12: k8s config maps
Browse files Browse the repository at this point in the history
  • Loading branch information
kezzyhko committed Sep 27, 2021
2 parents 1eec9dd + 6ef0425 commit 4796c85
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 7 deletions.
2 changes: 2 additions & 0 deletions app_python/.dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/__pycache__
app_files/logs/**
app_files/db.sqlite3
2 changes: 2 additions & 0 deletions app_python/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/__pycache__
app_files/logs/**
app_files/db.sqlite3
1 change: 1 addition & 0 deletions app_python/app_files/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

urlpatterns = [
path('', views.datetime_view),
path('visits', views.visits),
]
16 changes: 15 additions & 1 deletion app_python/app_files/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
from django.http import HttpResponse
from datetime import datetime
import pytz
import os


DATETIME_TIMEZONE = pytz.timezone('Europe/Moscow')
DATETIME_FORMAT = "%d/%m/%Y %H:%M:%S"

def datetime_view(request):
current_moscow_datetime = datetime.now(DATETIME_TIMEZONE)
return HttpResponse(current_moscow_datetime.strftime(DATETIME_FORMAT))
time_string = current_moscow_datetime.strftime(DATETIME_FORMAT)
if not os.path.exists('logs'):
os.mkdir('logs')
f = open("logs/access.txt", "a")
f.write(time_string)
f.write("\n")
f.close()
return HttpResponse(time_string)

def visits(request):
f = open("logs/access.txt", 'r')
file_content = f.read().replace("\n", "<br>")
f.close()
return HttpResponse(file_content)
13 changes: 13 additions & 0 deletions k8s/12.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Lab 12 config output

```
kezzyhko@kezzyhko-laptop:~/windesktop/DevOps/k8s$ kubectl get po
NAME READY STATUS RESTARTS AGE
time-app-chart-588c77b667-hf886 1/1 Running 1 (40h ago) 8d
time-app-deployment-5bcc57b5c7-6lvcd 1/1 Running 0 4m31s
time-app-deployment-5bcc57b5c7-dr49l 1/1 Running 0 4m31s
kezzyhko@kezzyhko-laptop:~/windesktop/DevOps/k8s$ kubectl exec time-app-deployment-5bcc57b5c7-6lvcd -- cat /app/config.json
{
"config_key": "config_value"
}kezzyhko@kezzyhko-laptop:~/windesktop/DevOps/k8s$
```
3 changes: 3 additions & 0 deletions k8s/time-app/files/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"config_key": "config_value"
}
7 changes: 7 additions & 0 deletions k8s/time-app/templates/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
apiVersion: v1
kind: ConfigMap
metadadata:
name: example-config
data:
config.json: |-
{{ .Files.Get "files/config.json" }}
8 changes: 8 additions & 0 deletions k8s/time-app/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ spec:
serviceAccountName: {{ include "time-app.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
volumes:
- name: config-volume
configMap:
name: example-config
containers:
- name: {{ .Chart.Name }}
securityContext:
Expand All @@ -37,6 +41,10 @@ spec:
- name: http
containerPort: 5000
protocol: TCP
volumeMouns:
- name: config-volume
mountPath: /app/config.yaml
subPath: files/config.yaml
env:
- name: super-secret
valueFrom:
Expand Down
9 changes: 3 additions & 6 deletions monitoring/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,8 @@ services:
- 5000
ports:
- "5000:5000"
logging:
driver: "json-file"
options:
max-size: "100m"
max-file: "10"
tag: "{{.ImageName}}|{{.Name}}"
volumes:
- app-logs:/app/logs
networks:
- monitoring.network
logging:
Expand Down Expand Up @@ -207,3 +203,4 @@ volumes:
loki-data: {}
promtail-data: {}
prometheus-data: {}
app-logs: {}

0 comments on commit 4796c85

Please sign in to comment.