From 7c54a6249d0feb213e5e1b27b48596328b15eb01 Mon Sep 17 00:00:00 2001 From: Mohamad Liyaghi Date: Tue, 30 Jul 2024 14:12:45 +0330 Subject: [PATCH] feat(k8s): backend deployment and service --- Makefile | 6 +++-- kubernetes/backend.yaml | 58 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 kubernetes/backend.yaml diff --git a/Makefile b/Makefile index d8c5cc2..cb2097e 100644 --- a/Makefile +++ b/Makefile @@ -43,7 +43,9 @@ admin: docker exec -it food-anywhere-backend python manage.py createsuperuser local_confmap: - kubectl create configmap food-anywhere-env --from-env-file=.envs/.env.local + kubectl create configmap food-anywhere-env --from-env-file=envs/.env.local \ + && kubectl create configmap food-anywhere-env-file --from-file=.env=envs/.env.local prod_confmap: - kubectl create configmap food-anywhere-env --from-env-file=.envs/.env.prod + kubectl create configmap food-anywhere-env --from-env-file=.envs/.env.prod \ + && kubectl create configmap food-anywhere-env-file --from-file=.env=envs/.env.prod diff --git a/kubernetes/backend.yaml b/kubernetes/backend.yaml new file mode 100644 index 0000000..c7f7e92 --- /dev/null +++ b/kubernetes/backend.yaml @@ -0,0 +1,58 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: food-anywhere-backend-dp + labels: + app: food-anywhere-backend +spec: + replicas: 1 + selector: + matchLabels: + app: food-anywhere-backend + template: + metadata: + labels: + app: food-anywhere-backend + spec: + containers: + - name: backend + image: ml06py/food_anywhere:latest + command: ["/bin/sh"] + args: [ "/docker/scripts/backend.sh" ] + + volumeMounts: + - name: env-file + mountPath: /envs/.env + subPath: .env + envFrom: + - configMapRef: + name: food-anywhere-env + ports: + - containerPort: 8000 + env: + - name: DJANGO_SETTINGS_MODULE + value: "config.settings.local" + - name: ENVIRONMENT + value: "LOCAL" + - name: POSTGRES_PORT + value: "5432" + + volumes: + - name: env-file + configMap: + name: food-anywhere-env-file + items: + - key: .env + path: .env +--- +apiVersion: v1 +kind: Service +metadata: + name: backend +spec: + selector: + app: food-anywhere-backend + ports: + - protocol: TCP + port: 8000 + targetPort: 8000