瀏覽代碼

Preparado para fleet

Celestino Rey 1 年之前
父節點
當前提交
20f3790a19

+ 7 - 0
Fleet/15-namespace.yaml

@@ -0,0 +1,7 @@
+###################################################
+# Namespace finanzas
+###################################################
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: finanzas

+ 8 - 0
Fleet/20-reg-secret.yaml

@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Secret
+metadata:
+  name: myregistrykey
+  namespace: finanzas
+data:
+  .dockerconfigjson: ewoJImF1dGhzIjogewoJCSJyZWdpc3RyeS5yZXltb3RhLmVzIjogewoJCQkiYXV0aCI6ICJZM0psZVd4dmNHVjZPbEpsZVMweE1UYzIiCgkJfQoJfQp9
+type: kubernetes.io/dockerconfigjson

+ 15 - 0
Fleet/25-env-prod-configmap.yaml

@@ -0,0 +1,15 @@
+apiVersion: v1
+data:
+  DEBUG: "False"
+  ENTORNO: "Producción"
+  # APP_VERSION: 16.0.0
+  SECRET_KEY: change_me
+  SQL_HOST: postgresql
+  SQL_PORT: "5432"
+  DATABASE: postgres
+kind: ConfigMap
+metadata:
+  labels:
+    io.kompose.service: web-env-prod
+  name: env-prod
+  namespace: finanzas

+ 11 - 0
Fleet/30-env-prod-db-configmap.yaml

@@ -0,0 +1,11 @@
+apiVersion: v1
+data:
+  POSTGRES_DB: finanzas
+  POSTGRES_PASSWORD: Dsa-0213
+  POSTGRES_USER: creylopez
+kind: ConfigMap
+metadata:
+  labels:
+    io.kompose.service: db-env-prod-db
+  name: env-prod-db
+  namespace: finanzas

+ 74 - 0
Fleet/35-pv-local-finanzas.yaml

@@ -0,0 +1,74 @@
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: finanzas-media-folder
+  namespace: finanzas
+  labels:
+    app: finanzas
+spec:
+  capacity:
+    storage: 100Mi
+  accessModes:
+    - ReadWriteOnce
+  hostPath:
+    path: "/mnt/Externo/finanzas/media"
+---
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: finanzas-finanzas-migrations-folder
+  namespace: finanzas
+  labels:
+    app: finanzas
+spec:
+  capacity:
+    storage: 52Mi
+  accessModes:
+    - ReadWriteOnce
+  hostPath:
+    path: "/mnt/Externo/finanzas/migrations/finanzas"
+---
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: finanzas-reymotausers-migrations-folder
+  namespace: finanzas
+  labels:
+    app: finanzas
+spec:
+  capacity:
+    storage: 53Mi
+  accessModes:
+    - ReadWriteOnce
+  hostPath:
+    path: "/mnt/Externo/finanzas/migrations/reymotausers"
+---
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: finanzas-static-folder
+  namespace: finanzas
+  labels:
+    app: finanzas
+spec:
+  capacity:
+    storage: 70Mi
+  accessModes:
+    - ReadWriteOnce
+  hostPath:
+    path: "/mnt/Externo/finanzas/static"
+---
+apiVersion: v1
+kind: PersistentVolume
+metadata:
+  name: finanzas-pg-folder
+  namespace: finanzas
+  labels:
+    app: finanzas
+spec:
+  capacity:
+    storage: 200Mi
+  accessModes:
+    - ReadWriteOnce
+  hostPath:
+    path: "/mnt/Externo/finanzas/pg"

+ 47 - 0
Fleet/40-finanzas-prod-persistentvolumeclaim.yaml

@@ -0,0 +1,47 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  creationTimestamp: null
+  labels:
+    io.kompose.service: finanzas-media
+  name: finanzas-media
+  namespace: finanzas
+spec:
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 100Mi
+status: {}
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  creationTimestamp: null
+  labels:
+    io.kompose.service: finanzas-reymotausers-migrations
+  name: finanzas-reymotausers-migrations
+  namespace: finanzas
+spec:
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 53Mi
+status: {}
+---
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  creationTimestamp: null
+  labels:
+    io.kompose.service: finanzas-finanzas-migrations
+  name: finanzas-finanzas-migrations
+  namespace: finanzas
+spec:
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 52Mi
+status: {}

+ 13 - 0
Fleet/43-static-volume-persistentvolumeclaim.yaml

@@ -0,0 +1,13 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  labels:
+    io.kompose.service: static-volume
+  name: static-volume
+  namespace: finanzas
+spec:
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 70Mi

+ 13 - 0
Fleet/45-postgres-data-persistentvolumeclaim.yaml

@@ -0,0 +1,13 @@
+apiVersion: v1
+kind: PersistentVolumeClaim
+metadata:
+  labels:
+    io.kompose.service: postgres-data
+  name: postgres-data
+  namespace: finanzas
+spec:
+  accessModes:
+    - ReadWriteOnce
+  resources:
+    requests:
+      storage: 100Mi

+ 52 - 0
Fleet/55-db-deployment.yaml

@@ -0,0 +1,52 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  annotations:
+    kompose.cmd: kompose convert
+    kompose.version: 1.34.0 (cbf2835db)
+  labels:
+    io.kompose.service: postgresql
+  name: postgresql
+  namespace: finanzas
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      io.kompose.service: postgresql
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+      annotations:
+        kompose.cmd: kompose convert
+        kompose.version: 1.34.0 (cbf2835db)
+      labels:
+        io.kompose.service: postgresql
+    spec:
+      containers:
+        - env:
+            - name: POSTGRES_DB
+              valueFrom:
+                configMapKeyRef:
+                  key: POSTGRES_DB
+                  name: env-prod-db
+            - name: POSTGRES_PASSWORD
+              valueFrom:
+                configMapKeyRef:
+                  key: POSTGRES_PASSWORD
+                  name: env-prod-db
+            - name: POSTGRES_USER
+              valueFrom:
+                configMapKeyRef:
+                  key: POSTGRES_USER
+                  name: env-prod-db
+          image: postgres:15
+          name: postgresql
+          volumeMounts:
+            - mountPath: /var/lib/postgresql/data
+              name: postgres-data
+      restartPolicy: Always
+      volumes:
+        - name: postgres-data
+          persistentVolumeClaim:
+            claimName: postgres-data

+ 17 - 0
Fleet/60-db-service.yaml

@@ -0,0 +1,17 @@
+apiVersion: v1
+kind: Service
+metadata:
+  annotations:
+    kompose.cmd: kompose convert
+    kompose.version: 1.34.0 (cbf2835db)
+  labels:
+    io.kompose.service: postgresql
+  name: postgresql
+  namespace: finanzas
+spec:
+  ports:
+    - name: "5432"
+      port: 5432
+      targetPort: 5432
+  selector:
+    io.kompose.service: postgresql

+ 20 - 0
Fleet/65-nginx-service.yaml

@@ -0,0 +1,20 @@
+apiVersion: v1
+kind: Service
+metadata:
+  annotations:
+    kompose.cmd: kompose convert
+    kompose.version: 1.34.0 (cbf2835db)
+  labels:
+    io.kompose.service: nginx
+  name: nginx
+  namespace: finanzas
+spec:
+  type: NodePort
+  ports:
+    - name: "1337"
+      port: 1337
+      nodePort: 30342
+      targetPort: 80
+  selector:
+    io.kompose.service: nginx
+

+ 105 - 0
Fleet/70-finanzas-deployment.yaml

@@ -0,0 +1,105 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: finanzas
+  namespace: finanzas
+spec:
+  ports:
+    - name: "8000"
+      port: 8000
+      targetPort: 8000
+  selector:
+    app: finanzas
+---
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  name: finanzas
+  namespace: finanzas
+  labels:
+    app: finanzas
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      app: finanzas
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+      labels:
+        app: finanzas
+    spec:
+      containers:
+      - args:
+          - gunicorn
+          - misfinanzas.wsgi:application
+          - --bind
+          - 0.0.0.0:8000
+        name: finanzas
+        image: registry.reymota.es/finanzas-x86_64:0.41
+        env:
+        - name: IMG_VERSION
+          value: "0.41"
+        - name: OPENSHIFT
+          value: "False"
+        - name: ENVIRONMENT
+          valueFrom:
+            configMapKeyRef:
+              key: ENTORNO
+              name: env-prod
+        - name: DEBUG
+          valueFrom:
+            configMapKeyRef:
+              key: DEBUG
+              name: env-prod
+#        - name: APP_VERSION
+#          valueFrom:
+#            configMapKeyRef:
+#              key: APP_VERSION
+#              name: env-prod
+        - name: DATABASE
+          valueFrom:
+            configMapKeyRef:
+              key: DATABASE
+              name: env-prod
+        - name: SQL_HOST
+          valueFrom:
+            configMapKeyRef:
+              key: SQL_HOST
+              name: env-prod
+        - name: SQL_PORT
+          valueFrom:
+            configMapKeyRef:
+              key: SQL_PORT
+              name: env-prod
+        ports:
+        - containerPort: 8000
+          protocol: TCP
+        volumeMounts:
+        - mountPath: /app/src/mediafiles
+          name: finanzas-media
+        - mountPath: /app/src/finanzas/migrations
+          name: finanzas-finanzas-migrations
+        - mountPath: /app/src/reymotausers/migrations
+          name: finanzas-reymotausers-migrations
+
+        - mountPath: /app/src/staticfiles
+          name: static-volume
+      imagePullSecrets:
+      - name: myregistrykey
+      restartPolicy: Always
+      volumes:
+      - name: finanzas-media
+        persistentVolumeClaim:
+          claimName: finanzas-media
+      - name: finanzas-finanzas-migrations
+        persistentVolumeClaim:
+          claimName: finanzas-finanzas-migrations
+      - name: finanzas-reymotausers-migrations
+        persistentVolumeClaim:
+          claimName: finanzas-reymotausers-migrations
+      - name: static-volume
+        persistentVolumeClaim:
+          claimName: static-volume
+status: {}

+ 46 - 0
Fleet/75-nginx-deployment.yaml

@@ -0,0 +1,46 @@
+apiVersion: apps/v1
+kind: Deployment
+metadata:
+  annotations:
+    kompose.cmd: kompose convert
+    kompose.version: 1.34.0 (cbf2835db)
+  labels:
+    io.kompose.service: nginx
+  name: nginx
+  namespace: finanzas
+spec:
+  replicas: 1
+  selector:
+    matchLabels:
+      io.kompose.service: nginx
+  strategy:
+    type: Recreate
+  template:
+    metadata:
+      annotations:
+        kompose.cmd: kompose convert
+        kompose.version: 1.34.0 (cbf2835db)
+      labels:
+        io.kompose.service: nginx
+    spec:
+      containers:
+        - image: registry.reymota.es/nginx-finanzas-x86_64:1.2
+          name: nginx
+          ports:
+            - containerPort: 80
+              protocol: TCP
+          volumeMounts:
+            - mountPath: /app/finanzas/staticfiles
+              name: static-volume
+            - mountPath: /app/finanzas/mediafiles
+              name: finanzas-media
+      imagePullSecrets:
+      - name: myregistrykey
+      restartPolicy: Always
+      volumes:
+        - name: static-volume
+          persistentVolumeClaim:
+            claimName: static-volume
+        - name: finanzas-media
+          persistentVolumeClaim:
+            claimName: finanzas-media

+ 31 - 0
Fleet/80-finanzas-ingress.yaml

@@ -0,0 +1,31 @@
+apiVersion: networking.k8s.io/v1
+kind: Ingress
+metadata:
+  generation: 1
+  managedFields:
+    - apiVersion: networking.k8s.io/v1
+      fieldsType: FieldsV1
+      fieldsV1:
+        f:spec:
+          f:defaultBackend:
+            .: {}
+            f:service:
+              .: {}
+              f:name: {}
+              f:port: {}
+          f:rules: {}
+      manager: rancher
+      operation: Update
+  name: finanzas
+  namespace: finanzas
+spec:
+  defaultBackend:
+    service:
+      name: nginx
+      port:
+        number: 1337
+  ingressClassName: nginx
+  rules:
+    - host: finanzas.rancher.reymota.lab
+status:
+  loadBalancer: {}

+ 16 - 2
K8S/Makefile

@@ -44,6 +44,7 @@ clean:
 	-kubectl delete -f finanzas-prod-persistentvolumeclaim.yaml
 	-kubectl delete -f pv-local-finanzas.yaml
 	-kubectl delete -f reg-secret.yaml
+	-kubectl delete -f finanzas-ingress.yaml
 	-kubectl delete -f namespace.yaml
 
 nginx:
@@ -52,5 +53,18 @@ nginx:
 backup:
 	kubectl --kubeconfig /home/creylopez/.kube/config -n finanzas exec -ti deployment.apps/db -- /usr/lib/postgresql/15/bin/pg_dump --username=creylopez --dbname=finanzas > finanzas-$(IMG_VERSION).sql
 
-muestra:
-	-envsubst < finanzas-deployment.yaml > /tmp/deployment.yaml
+fleet:
+	-cp namespace.yaml ../Fleet/15-namespace.yaml
+	-cp reg-secret.yaml ../Fleet/20-reg-secret.yaml
+	-cp env-prod-configmap.yaml  ../Fleet/25-env-prod-configmap.yaml
+	-cp env-prod-db-configmap.yaml  ../Fleet/30-env-prod-db-configmap.yaml
+	-cp pv-local-finanzas.yaml ../Fleet/35-pv-local-finanzas.yaml
+	-cp finanzas-prod-persistentvolumeclaim.yaml ../Fleet/40-finanzas-prod-persistentvolumeclaim.yaml
+	-cp static-volume-persistentvolumeclaim.yaml ../Fleet/43-static-volume-persistentvolumeclaim.yaml
+	-cp postgres-data-persistentvolumeclaim.yaml ../Fleet/45-postgres-data-persistentvolumeclaim.yaml
+	-cp db-deployment.yaml ../Fleet/55-db-deployment.yaml
+	-cp db-service.yaml ../Fleet/60-db-service.yaml
+	-cp nginx-service.yaml ../Fleet/65-nginx-service.yaml
+	-envsubst < finanzas-deployment.yaml > ../Fleet/70-finanzas-deployment.yaml
+	-envsubst < nginx-deployment.yaml > ../Fleet/75-nginx-deployment.yaml
+	-cp finanzas-ingress.yaml ../Fleet/80-finanzas-ingress.yaml