From 696a7658a6d6115b7b3c847e6f818dee8ad2f147 Mon Sep 17 00:00:00 2001 From: Julien-Robert Lecadou Date: Mon, 3 Apr 2023 18:18:14 -0400 Subject: [PATCH] Improve the k8s manifest and other minor details --- .vs/VSWorkspaceState.json | 7 ++ .vs/azure-voting-app-redis/v17/.wsuo | Bin 0 -> 11264 bytes Pipfile | 12 ++ azure-vote-all-in-one-redis.yaml | 39 ++++++- azure-vote/Dockerfile | 12 +- azure-vote/Dockerfile-for-app-service | 5 +- azure-vote/azure-vote/templates/index.html | 2 +- notes.md | 130 +++++++++++++++++++++ 8 files changed, 202 insertions(+), 5 deletions(-) create mode 100644 .vs/VSWorkspaceState.json create mode 100644 .vs/azure-voting-app-redis/v17/.wsuo create mode 100644 Pipfile create mode 100644 notes.md diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json new file mode 100644 index 0000000000..8ac564e451 --- /dev/null +++ b/.vs/VSWorkspaceState.json @@ -0,0 +1,7 @@ +{ + "ExpandedNodes": [ + "" + ], + "SelectedNode": "\\C:\\Users\\jlecadou\\Source\\Repos\\azure-voting-app-redis", + "PreviewInSolutionExplorer": false +} \ No newline at end of file diff --git a/.vs/azure-voting-app-redis/v17/.wsuo b/.vs/azure-voting-app-redis/v17/.wsuo new file mode 100644 index 0000000000000000000000000000000000000000..2cee29561a922126e3945973bcc8907dd4a664c9 GIT binary patch literal 11264 zcmeHN%W@k<6uoi?ArK(JU`WWqP_9%Kj7yRoA(OkVm_xJGW|ZZu$aAQ(?a}V;E?=>X;xHW{3fz(^K1~^y8&W}DmwRMo z=rkrLTRcCx$Ecsq?EJ7%`ZM+n`<-$+F9NYD8}dHTODNrt&-a+6^YxgFwD3vx&bR)x zSJ4ddRY~I$w*XOKUO=S4i!dGee2Y2@ed zus`d=baW{2IQ9RV-+pQ7|L?8;KcJquP~d(z_am4TqWn>-RdNMJ|H=y!Y{}pbF{spnME3 zFS{L<6!kad15m#Ku4l1x`ru8;E2-Rz2K0YVU@m?31mWs;FQLFQjfs9gC9V#cvmpyN zv5vB$z4lCsSV^;|RLn%6e<%N|YNuPkq|`41zajMf6 zpS~UMj7;Vp=b-`A0>=_fLgu%XPF6vYcY#ZZsL6-uL1}d;auxXJF%NY*EI#c8eF>(p z_)9>iEKnC}h9*G&Vx%X1`mp%K)%aORcpjR@-F=3+3)op*CYAh~=i($RR24ffC`+&n zIyE_sVE=vd{}qhW_NO0wo>NU&Y@W&$ta=Ue%tpW`zufB=_F2Si)blkZWkk4zHtIe1 z_z`$citub~w5&8Ha8nxij3IDOVd-z$zaaiE0=0rq5mdjacHNdcjSu$7~@IYJCj~lP|ov8+rJ?EWnhpC3y^r`q=PplBkZ5P zkG}uv`F?yb`s-K!$ZcH@n{U~TX0d+$wW#C2-udp^OFPlWhh68epFaht2eijg)1c!i zhlAi#k2t&}q>1hXxAhsP7_XmqFUhc@DZ9GbkSgOZy>F#&Qh#UcoabGqM8n z)lfFOf%1m(Z{zA+rEaiI`iJ^*m6^nX~sG8dvRQ}&5zZp1((b*EFW0ny)<_xHejMuN~G;#@=a@cI#aZ!lktRQrxQslm�~ z?JN0wsWhdCqOPl)XML9SYgTq?CXUY+#VhetE|bVx`BXe*O{Y?}m5JLKE0LTkBnpXQ zBAJ_dKq_-3I(__*9EhGKx^CbN8AmLFL{GpE<#$jTRDR6(oLN4I_#fvVro%;nVf^QK z$A9K=4&H{v@y3D2jYwFK{fQEP;a#0}bib0RQTsJ#Kl2=Ad~f_ILi|tt59oi4|Ec)b zMKFwf2*Wos{@~sJaf|CS54gkdPUvc!N?f@CazBHH@!>TyN>_);XA*8 z71WJmuk|qgOItdMhimAK+J3{|YI@-h`QJDH72S_2|Fu*^jo%F#|D)_OeoV=Y5`P@V K4>bp)<^KWb!r!a_ literal 0 HcmV?d00001 diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000000..04edd2a087 --- /dev/null +++ b/Pipfile @@ -0,0 +1,12 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.11" +python_full_version = "3.11.2" diff --git a/azure-vote-all-in-one-redis.yaml b/azure-vote-all-in-one-redis.yaml index e971a76092..e578141ea5 100644 --- a/azure-vote-all-in-one-redis.yaml +++ b/azure-vote-all-in-one-redis.yaml @@ -13,7 +13,7 @@ spec: app: azure-vote-back spec: nodeSelector: - "beta.kubernetes.io/os": linux + "kubernetes.io/os": linux containers: - name: azure-vote-back image: mcr.microsoft.com/oss/bitnami/redis:6.0.8 @@ -23,6 +23,27 @@ spec: ports: - containerPort: 6379 name: redis + resources: + requests: + cpu: 100m + memory: 100Mi + limits: + cpu: 200m + memory: 200Mi + livenessProbe: + exec: + command: + - redis-cli + - ping + initialDelaySeconds: 15 + periodSeconds: 10 + readinessProbe: + exec: + command: + - redis-cli + - ping + initialDelaySeconds: 5 + periodSeconds: 10 --- apiVersion: v1 kind: Service @@ -54,7 +75,7 @@ spec: app: azure-vote-front spec: nodeSelector: - "beta.kubernetes.io/os": linux + "kubernetes.io/os": linux containers: - name: azure-vote-front image: mcr.microsoft.com/azuredocs/azure-vote-front:v1 @@ -63,11 +84,25 @@ spec: resources: requests: cpu: 250m + memory: 128Mi limits: cpu: 500m + memory: 256Mi env: - name: REDIS value: "azure-vote-back" + livenessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 15 + periodSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 5 + periodSeconds: 10 --- apiVersion: v1 kind: Service diff --git a/azure-vote/Dockerfile b/azure-vote/Dockerfile index ac103827a0..c990425066 100644 --- a/azure-vote/Dockerfile +++ b/azure-vote/Dockerfile @@ -1,3 +1,13 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6 +# FROM tiangolo/uwsgi-nginx-flask:python3.6 + +# Update the base image to use Python 3.11 +FROM tiangolo/uwsgi-nginx:python3.11 +LABEL maintainer="Sebastian Ramirez " +# Make /app/* available to be imported by Python globally to better support several use cases like Alembic migrations. + +ENV PYTHONPATH=/app + + + RUN pip install redis ADD /azure-vote /app diff --git a/azure-vote/Dockerfile-for-app-service b/azure-vote/Dockerfile-for-app-service index 2086975bd7..bc3adaedb7 100644 --- a/azure-vote/Dockerfile-for-app-service +++ b/azure-vote/Dockerfile-for-app-service @@ -1,4 +1,7 @@ -FROM tiangolo/uwsgi-nginx-flask:python3.6 +# FROM tiangolo/uwsgi-nginx-flask:python3.6 +FROM tiangolo/uwsgi-nginx:python3.11 +LABEL maintainer="Sebastian Ramirez " +ENV PYTHONPATH=/app COPY sshd_config /etc/ssh/ COPY app_init.supervisord.conf /etc/supervisor/conf.d diff --git a/azure-vote/azure-vote/templates/index.html b/azure-vote/azure-vote/templates/index.html index 603e11002b..b1d86052ad 100644 --- a/azure-vote/azure-vote/templates/index.html +++ b/azure-vote/azure-vote/templates/index.html @@ -12,7 +12,7 @@
-
+
diff --git a/notes.md b/notes.md new file mode 100644 index 0000000000..4948683ea9 --- /dev/null +++ b/notes.md @@ -0,0 +1,130 @@ +# Improvements to azure-vote-all-in-one-redis.yaml + +1. Use resource requests and limits for both azure-vote-back and azure-vote-front containers to ensure they have predictable resource usage and prevent resource starvation. + +2. Set up liveness and readiness probes for both containers to improve the self-healing capabilities of your deployments and ensure the availability of your services. + +```yml +apiVersion: apps/v1 +kind: Deployment +metadata: + name: azure-vote-back +spec: + replicas: 1 + selector: + matchLabels: + app: azure-vote-back + template: + metadata: + labels: + app: azure-vote-back + spec: + nodeSelector: + "kubernetes.io/os": linux + containers: + - name: azure-vote-back + image: mcr.microsoft.com/oss/bitnami/redis:6.0.8 + env: + - name: ALLOW_EMPTY_PASSWORD + value: "yes" + ports: + - containerPort: 6379 + name: redis + resources: + requests: + cpu: 100m + memory: 100Mi + limits: + cpu: 200m + memory: 200Mi + livenessProbe: + exec: + command: + - redis-cli + - ping + initialDelaySeconds: 15 + periodSeconds: 10 + readinessProbe: + exec: + command: + - redis-cli + - ping + initialDelaySeconds: 5 + periodSeconds: 10 +--- +apiVersion: v1 +kind: Service +metadata: + name: azure-vote-back +spec: + ports: + - port: 6379 + selector: + app: azure-vote-back +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: azure-vote-front +spec: + replicas: 1 + selector: + matchLabels: + app: azure-vote-front + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + minReadySeconds: 5 + template: + metadata: + labels: + app: azure-vote-front + spec: + nodeSelector: + "kubernetes.io/os": linux + containers: + - name: azure-vote-front + image: mcr.microsoft.com/azuredocs/azure-vote-front:v1 + ports: + - containerPort: 80 + resources: + requests: + cpu: 250m + memory: 128Mi + limits: + cpu: 500m + memory: 256Mi + env: + - name: REDIS + value: "azure-vote-back" + livenessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 15 + periodSeconds: 10 + readinessProbe: + httpGet: + path: / + port: 80 + initialDelaySeconds: 5 + periodSeconds: 10 +--- +apiVersion: v1 +kind: Service +metadata: + name: azure-vote-front +spec: + type: LoadBalancer + ports: + - port: 80 + selector: + app: azure-vote-front +``` + +## Changes made + +1. Added memory requests and limits to both `azure-vote-back` and `azure-vote-front` containers. +2. Changed nodeSelector key from `beta.kubernetes.io/os` to `kubernetes.io/os` as the beta label has been deprecated. +3. Added liveness