Bläddra i källkod

Merge branch 'main' of https://gitserver.reymota.es/creylopez/misfinanzas

Tino 5 månader sedan
förälder
incheckning
237ec6c859
4 ändrade filer med 60 tillägg och 20 borttagningar
  1. 40 0
      Jenkinsfile
  2. 15 0
      K8S/finanzas-service-lb.yaml
  3. 0 14
      K8S/finanzas-service-nodeport.yaml
  4. 5 6
      K8S/finanzas-service.yaml

+ 40 - 0
Jenkinsfile

@@ -26,6 +26,8 @@ pipeline {
     booleanParam(name: 'borranamespace', description: 'Borra namespace', defaultValue: false)
     booleanParam(name: 'creadb', description: 'Crea el objeto para crear la DB en el cúster', defaultValue: false)
     booleanParam(name: 'borradb', description: 'Borra el objeto que creó la DB, no la DB', defaultValue: false)
+    booleanParam(name: 'servicelb', description: 'Crea el servicio LoadBalancer', defaultValue: false)
+    booleanParam(name: 'servicenp', description: 'Crea el servicio NodePort', defaultValue: false)
   }
   
   stages {
@@ -95,6 +97,40 @@ pipeline {
       }      
     }
 
+    stage('Crea el servicio NodePort') {
+      when {
+        expression { params.servicenp}
+      }
+      steps {
+        echo "Creando el servicio NodePort..." 
+        container('kubectl') {
+          withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
+	  sh """#!/bin/bash
+	    cat K8S/${NOMBRE_APP}-service-lb.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl delete -f - || true
+	    cat K8S/${NOMBRE_APP}-service.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f - 
+            """
+          }
+        }
+      }      
+    }
+
+    stage('Crea el servicio LoadBalancer') {
+      when {
+        expression { params.servicelb}
+      }
+      steps {
+        echo "Creando el servicio LoadBalancer..." 
+        container('kubectl') {
+          withCredentials([file(credentialsId: env.Destino, variable: 'KUBECONFIG')]) {
+	  sh """#!/bin/bash
+	    cat K8S/${NOMBRE_APP}-service.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl delete -f - || true
+	    cat K8S/${NOMBRE_APP}-service-lb.yaml | sed -e "s/<NS>/${NAMESPACE}/" | kubectl create -f - 
+            """
+          }
+        }
+      }      
+    }
+
     stage('Borra todo') {
       when {
         expression { params.clean }
@@ -163,6 +199,8 @@ pipeline {
           expression { !params.borranamespace } 
           expression { !params.claims }
           expression { !params.borraclaims }
+          expression { !params.servicenp }
+          expression { !params.servicelb }
         }
       }
       steps {
@@ -215,6 +253,8 @@ pipeline {
           expression { !params.borranamespace } 
           expression { !params.claims }
           expression { !params.borraclaims }
+          expression { !params.servicenp }
+          expression { !params.servicelb }
         }
       }
       steps {

+ 15 - 0
K8S/finanzas-service-lb.yaml

@@ -0,0 +1,15 @@
+apiVersion: v1
+kind: Service
+metadata:
+  name: finanzas-lb
+  namespace: <NS>
+  annotations:
+    metallb.io/loadBalancerIPs: 192.168.1.202
+spec:
+  type: LoadBalancer
+  ports:
+    - name: "80"
+      port: 80
+      targetPort: 8080
+  selector:
+    app: finanzas

+ 0 - 14
K8S/finanzas-service-nodeport.yaml

@@ -1,14 +0,0 @@
-apiVersion: v1
-kind: Service
-metadata:
-  name: finanzas
-  namespace: <NS>
-spec:
-  type: NodePort
-  ports:
-    - name: "8080"
-      port: 8080
-      nodePort: 30351
-      targetPort: 8080
-  selector:
-    app: finanzas

+ 5 - 6
K8S/finanzas-service.yaml

@@ -3,13 +3,12 @@ kind: Service
 metadata:
   name: finanzas-lb
   namespace: <NS>
-  annotations:
-    metallb.io/loadBalancerIPs: 192.168.1.202
 spec:
-  type: LoadBalancer
+  type: NodePort
   ports:
-    - name: "80"
-      port: 80
-      targetPort: 8000
+    - name: "8080"
+      port: 8080
+      nodePort: 30351
+      targetPort: 8080
   selector:
     app: finanzas