├── Bloque14ConfigMaps
├── k8s
│ ├── secretos.properties
│ ├── config.properties
│ ├── namespace.yml
│ ├── servicioMariadb.yml
│ ├── servicioWildfly.yml
│ ├── crear configMap.txt
│ ├── ingress.yml
│ ├── deploymentMariadb.yml
│ └── deploymentWildFly.yml
├── aplicacion
│ ├── src
│ │ └── main
│ │ │ ├── webapp
│ │ │ └── WEB-INF
│ │ │ │ └── web.xml
│ │ │ └── java
│ │ │ └── com
│ │ │ └── inigoserrano
│ │ │ └── docker
│ │ │ └── aplicacion
│ │ │ ├── LivenessProbe.java
│ │ │ ├── Propiedades.java
│ │ │ ├── ReadynessProbe.java
│ │ │ └── Aplicacion.java
│ └── pom.xml
└── k8sMariadb
│ └── deploymentMariadb.yml
├── Bloque12Probes
├── namespace.yml
├── servicioMariadb.yml
├── servicioWildfly.yml
├── ingress.yml
├── deploymentMariadb.yml
└── deploymentWildFly.yml
├── Bloque13Limites
├── namespace.yml
├── servicioMariadb.yml
├── servicioWildfly.yml
├── ingress.yml
├── deploymentWildFly.yml
└── deploymentMariadb.yml
├── Bloque05Namespace
└── namespace.yml
├── Bloque11Aplicacion
├── k8s
│ ├── namespace.yml
│ ├── servicioMariadb.yml
│ ├── servicioWildfly.yml
│ ├── ingress.yml
│ ├── deploymentWildFly.yml
│ └── deploymentMariadb.yml
└── aplicacion
│ ├── src
│ └── main
│ │ ├── webapp
│ │ └── WEB-INF
│ │ │ └── web.xml
│ │ └── java
│ │ └── com
│ │ └── inigoserrano
│ │ └── docker
│ │ └── aplicacion
│ │ ├── LivenessProbe.java
│ │ ├── ReadynessProbe.java
│ │ └── Aplicacion.java
│ └── pom.xml
├── Bloque06Pods
└── pod.yml
├── Bloque08Servicios
├── servicioMariadb.yml
├── deploymentWildFly.yml
└── deploymentMariadb.yml
├── Bloque09Ingress
├── servicioWildfly.yml
└── ingress.yml
└── Bloque07Deployments
└── deployment.yml
/Bloque14ConfigMaps/k8s/secretos.properties:
--------------------------------------------------------------------------------
1 | password=admin123
--------------------------------------------------------------------------------
/Bloque12Probes/namespace.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Namespace
3 | metadata:
4 | name: curso
5 |
--------------------------------------------------------------------------------
/Bloque13Limites/namespace.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Namespace
3 | metadata:
4 | name: curso
5 |
--------------------------------------------------------------------------------
/Bloque05Namespace/namespace.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Namespace
3 | metadata:
4 | name: curso-namespace
--------------------------------------------------------------------------------
/Bloque11Aplicacion/k8s/namespace.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Namespace
3 | metadata:
4 | name: curso
5 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/k8s/config.properties:
--------------------------------------------------------------------------------
1 | cadena=jdbc:mysql://mariadb-service:3306/curso
2 | usuario=root
3 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/k8s/namespace.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Namespace
3 | metadata:
4 | name: curso
5 |
--------------------------------------------------------------------------------
/Bloque06Pods/pod.yml:
--------------------------------------------------------------------------------
1 | apiVersion: v1
2 | kind: Pod
3 | metadata:
4 | name: wildfly
5 | spec:
6 | containers:
7 | - name: wildfly
8 | image: jboss/wildfly
9 |
--------------------------------------------------------------------------------
/Bloque08Servicios/servicioMariadb.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: mariadb-service
5 | spec:
6 | selector:
7 | app: mariadb
8 | ports:
9 | - protocol: TCP
10 | port: 3306
11 | targetPort: 3306
--------------------------------------------------------------------------------
/Bloque09Ingress/servicioWildfly.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: wildfly-service
5 | spec:
6 | selector:
7 | app: wildfly
8 | ports:
9 | - protocol: TCP
10 | port: 8080
11 | targetPort: 8080
--------------------------------------------------------------------------------
/Bloque12Probes/servicioMariadb.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: mariadb-service
5 | namespace: curso
6 | spec:
7 | selector:
8 | app: mariadb
9 | ports:
10 | - protocol: TCP
11 | port: 3306
12 | targetPort: 3306
--------------------------------------------------------------------------------
/Bloque12Probes/servicioWildfly.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: wildfly-service
5 | namespace: curso
6 | spec:
7 | selector:
8 | app: wildfly
9 | ports:
10 | - protocol: TCP
11 | port: 8080
12 | targetPort: 8080
--------------------------------------------------------------------------------
/Bloque13Limites/servicioMariadb.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: mariadb-service
5 | namespace: curso
6 | spec:
7 | selector:
8 | app: mariadb
9 | ports:
10 | - protocol: TCP
11 | port: 3306
12 | targetPort: 3306
--------------------------------------------------------------------------------
/Bloque13Limites/servicioWildfly.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: wildfly-service
5 | namespace: curso
6 | spec:
7 | selector:
8 | app: wildfly
9 | ports:
10 | - protocol: TCP
11 | port: 8080
12 | targetPort: 8080
--------------------------------------------------------------------------------
/Bloque11Aplicacion/k8s/servicioMariadb.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: mariadb-service
5 | namespace: curso
6 | spec:
7 | selector:
8 | app: mariadb
9 | ports:
10 | - protocol: TCP
11 | port: 3306
12 | targetPort: 3306
--------------------------------------------------------------------------------
/Bloque11Aplicacion/k8s/servicioWildfly.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: wildfly-service
5 | namespace: curso
6 | spec:
7 | selector:
8 | app: wildfly
9 | ports:
10 | - protocol: TCP
11 | port: 8080
12 | targetPort: 8080
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/k8s/servicioMariadb.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: mariadb-service
5 | namespace: curso
6 | spec:
7 | selector:
8 | app: mariadb
9 | ports:
10 | - protocol: TCP
11 | port: 3306
12 | targetPort: 3306
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/k8s/servicioWildfly.yml:
--------------------------------------------------------------------------------
1 | kind: Service
2 | apiVersion: v1
3 | metadata:
4 | name: wildfly-service
5 | namespace: curso
6 | spec:
7 | selector:
8 | app: wildfly
9 | ports:
10 | - protocol: TCP
11 | port: 8080
12 | targetPort: 8080
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/k8s/crear configMap.txt:
--------------------------------------------------------------------------------
1 | kubectl create configmap config-app --from-file=config.properties -n curso
2 |
3 | kubectl create secret generic db-user-pass --from-file=secretos.properties -n curso
4 |
5 | kubectl create secret generic db-pass --from-literal=usuario=admin321 -n curso
--------------------------------------------------------------------------------
/Bloque09Ingress/ingress.yml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Ingress
3 | metadata:
4 | name: wildfly-ingress
5 | annotations:
6 | nginx.ingress.kubernetes.io/rewrite-target: /
7 | spec:
8 | rules:
9 | - http:
10 | paths:
11 | - path: /
12 | backend:
13 | serviceName: wildfly-service
14 | servicePort: 8080
--------------------------------------------------------------------------------
/Bloque11Aplicacion/aplicacion/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Aplicacion
4 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/aplicacion/src/main/webapp/WEB-INF/web.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Aplicacion
4 |
--------------------------------------------------------------------------------
/Bloque12Probes/ingress.yml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Ingress
3 | metadata:
4 | name: wildfly-ingress
5 | namespace: curso
6 | annotations:
7 | nginx.ingress.kubernetes.io/rewrite-target: /
8 | spec:
9 | rules:
10 | - http:
11 | paths:
12 | - path: /
13 | backend:
14 | serviceName: wildfly-service
15 | servicePort: 8080
--------------------------------------------------------------------------------
/Bloque13Limites/ingress.yml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Ingress
3 | metadata:
4 | name: wildfly-ingress
5 | namespace: curso
6 | annotations:
7 | nginx.ingress.kubernetes.io/rewrite-target: /
8 | spec:
9 | rules:
10 | - http:
11 | paths:
12 | - path: /
13 | backend:
14 | serviceName: wildfly-service
15 | servicePort: 8080
--------------------------------------------------------------------------------
/Bloque11Aplicacion/k8s/ingress.yml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Ingress
3 | metadata:
4 | name: wildfly-ingress
5 | namespace: curso
6 | annotations:
7 | nginx.ingress.kubernetes.io/rewrite-target: /
8 | spec:
9 | rules:
10 | - http:
11 | paths:
12 | - path: /
13 | backend:
14 | serviceName: wildfly-service
15 | servicePort: 8080
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/k8s/ingress.yml:
--------------------------------------------------------------------------------
1 | apiVersion: extensions/v1beta1
2 | kind: Ingress
3 | metadata:
4 | name: wildfly-ingress
5 | namespace: curso
6 | annotations:
7 | nginx.ingress.kubernetes.io/rewrite-target: /
8 | spec:
9 | rules:
10 | - http:
11 | paths:
12 | - path: /
13 | backend:
14 | serviceName: wildfly-service
15 | servicePort: 8080
--------------------------------------------------------------------------------
/Bloque07Deployments/deployment.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: wildfly-deployment
5 | spec:
6 | selector:
7 | matchLabels:
8 | app: wildfly
9 | replicas: 1
10 | template:
11 | metadata:
12 | labels:
13 | app: wildfly
14 | spec:
15 | containers:
16 | - name: wildfly
17 | image: jboss/wildfly:15.0.0.Final
18 | ports:
19 | - containerPort: 8080
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Bloque08Servicios/deploymentWildFly.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: wildfly-deployment
5 | spec:
6 | selector:
7 | matchLabels:
8 | app: wildfly
9 | replicas: 1
10 | template:
11 | metadata:
12 | labels:
13 | app: wildfly
14 | spec:
15 | containers:
16 | - name: wildfly
17 | image: jboss/wildfly:15.0.0.Final
18 | ports:
19 | - containerPort: 8080
20 |
21 |
22 |
--------------------------------------------------------------------------------
/Bloque08Servicios/deploymentMariadb.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: mariadb-deployment
5 | spec:
6 | selector:
7 | matchLabels:
8 | app: mariadb
9 | replicas: 1
10 | template:
11 | metadata:
12 | labels:
13 | app: mariadb
14 | spec:
15 | containers:
16 | - name: mariadb
17 | image: mariadb
18 | ports:
19 | - containerPort: 3306
20 | env:
21 | - name: MYSQL_ROOT_PASSWORD
22 | value: "123"
23 |
24 |
25 |
--------------------------------------------------------------------------------
/Bloque11Aplicacion/k8s/deploymentWildFly.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: wildfly-deployment
5 | namespace: curso
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: wildfly
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: wildfly
15 | spec:
16 | containers:
17 | - name: wildfly
18 | image: inigoserrano/cursokuberneteswildfly:latest
19 | ports:
20 | - containerPort: 8080
21 | imagePullSecrets:
22 | - name: regsecret
23 |
24 |
--------------------------------------------------------------------------------
/Bloque12Probes/deploymentMariadb.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: mariadb-deployment
5 | namespace: curso
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: mariadb
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: mariadb
15 | spec:
16 | containers:
17 | - name: mariadb
18 | image: inigoserrano/cursokubernetesmariadb:latest
19 | ports:
20 | - containerPort: 3306
21 | imagePullSecrets:
22 | - name: regsecret
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Bloque11Aplicacion/k8s/deploymentMariadb.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: mariadb-deployment
5 | namespace: curso
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: mariadb
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: mariadb
15 | spec:
16 | containers:
17 | - name: mariadb
18 | image: inigoserrano/cursokubernetesmariadb:latest
19 | ports:
20 | - containerPort: 3306
21 | imagePullSecrets:
22 | - name: regsecret
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/Bloque13Limites/deploymentWildFly.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: wildfly-deployment
5 | namespace: curso
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: wildfly
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: wildfly
15 | spec:
16 | containers:
17 | - name: wildfly
18 | image: inigoserrano/cursokuberneteswildfly:latest
19 | ports:
20 | - containerPort: 8080
21 | resources:
22 | requests:
23 | memory: "150Mi"
24 | cpu: "100m"
25 | limits:
26 | memory: "512Mi"
27 | cpu: "500m"
28 |
29 |
--------------------------------------------------------------------------------
/Bloque13Limites/deploymentMariadb.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: mariadb-deployment
5 | namespace: curso
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: mariadb
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: mariadb
15 | spec:
16 | containers:
17 | - name: mariadb
18 | image: inigoserrano/cursokubernetesmariadb:latest
19 | ports:
20 | - containerPort: 3306
21 | resources:
22 | requests:
23 | memory: "100Mi"
24 | cpu: "100m"
25 | limits:
26 | memory: "512Mi"
27 | cpu: "500m"
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/k8s/deploymentMariadb.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: mariadb-deployment
5 | namespace: curso
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: mariadb
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: mariadb
15 | spec:
16 | containers:
17 | - name: mariadb
18 | image: inigoserrano/cursokubernetesmariadb:latest
19 | ports:
20 | - containerPort: 3306
21 | resources:
22 | requests:
23 | memory: "100Mi"
24 | cpu: "100m"
25 | limits:
26 | memory: "512Mi"
27 | cpu: "500m"
28 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/k8sMariadb/deploymentMariadb.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: mariadb-deployment
5 | namespace: curso
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: mariadb
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: mariadb
15 | spec:
16 | containers:
17 | - name: mariadb
18 | image: inigoserrano/cursokubernetesmariadb:latest
19 | ports:
20 | - containerPort: 3306
21 | env:
22 | - name: MYSQL_ROOT_PASSWORD
23 | valueFrom:
24 | secretKeyRef:
25 | name: db-pass
26 | key: usuario
27 | resources:
28 | requests:
29 | memory: "100Mi"
30 | cpu: "100m"
31 | limits:
32 | memory: "512Mi"
33 | cpu: "500m"
34 |
35 |
36 |
37 |
--------------------------------------------------------------------------------
/Bloque11Aplicacion/aplicacion/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.inigoserrano.dockersencillo
5 | aplicacionConBD
6 | 0.0.1-SNAPSHOT
7 | war
8 |
9 |
10 | Aplicacion
11 |
12 |
13 |
14 |
15 | javax.servlet
16 | javax.servlet-api
17 | 3.1.0
18 | provided
19 |
20 |
21 | org.mariadb.jdbc
22 | mariadb-java-client
23 | 2.0.1
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/aplicacion/src/main/java/com/inigoserrano/docker/aplicacion/LivenessProbe.java:
--------------------------------------------------------------------------------
1 | package com.inigoserrano.docker.aplicacion;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.annotation.WebServlet;
8 | import javax.servlet.http.HttpServlet;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 |
12 | @WebServlet({ "/livenessProbe" })
13 | public class LivenessProbe extends HttpServlet {
14 |
15 | /**
16 | *
17 | */
18 | private static final long serialVersionUID = 8532332299687592651L;
19 |
20 | @Override
21 | protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
22 | throws ServletException, IOException {
23 | try (final PrintWriter writer = response.getWriter()) {
24 | writer.println("OK");
25 | writer.flush();
26 | }
27 |
28 | }
29 |
30 | }
31 |
--------------------------------------------------------------------------------
/Bloque12Probes/deploymentWildFly.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: wildfly-deployment
5 | namespace: curso
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: wildfly
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: wildfly
15 | spec:
16 | containers:
17 | - name: wildfly
18 | image: inigoserrano/cursokuberneteswildfly:latest
19 | imagePullPolicy: Always
20 | ports:
21 | - containerPort: 8080
22 | livenessProbe:
23 | httpGet:
24 | path: /Aplicacion/livenessProbe
25 | port: 8080
26 | initialDelaySeconds: 3
27 | periodSeconds: 3
28 | readinessProbe:
29 | httpGet:
30 | path: /Aplicacion/readynessProbe
31 | port: 8080
32 | initialDelaySeconds: 3
33 | periodSeconds: 3
34 | imagePullSecrets:
35 | - name: regsecret
36 |
37 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/k8s/deploymentWildFly.yml:
--------------------------------------------------------------------------------
1 | apiVersion: apps/v1
2 | kind: Deployment
3 | metadata:
4 | name: wildfly-deployment
5 | namespace: curso
6 | spec:
7 | selector:
8 | matchLabels:
9 | app: wildfly
10 | replicas: 1
11 | template:
12 | metadata:
13 | labels:
14 | app: wildfly
15 | spec:
16 | containers:
17 | - name: wildfly
18 | image: inigoserrano/cursokuberneteswildfly:latest
19 | ports:
20 | - containerPort: 8080
21 | resources:
22 | requests:
23 | memory: "150Mi"
24 | cpu: "100m"
25 | limits:
26 | memory: "512Mi"
27 | cpu: "500m"
28 | volumeMounts:
29 | - name: config-volume
30 | mountPath: /properties/
31 | - name: secretos-volume
32 | mountPath: /secretos/
33 | volumes:
34 | - name: config-volume
35 | configMap:
36 | name: config-app
37 | - name: secretos-volume
38 | secret:
39 | secretName: db-user-pass
40 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/aplicacion/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.inigoserrano.dockersencillo
5 | aplicacionConBD
6 | 0.0.1-SNAPSHOT
7 | war
8 |
9 |
10 | 1.8
11 | 1.8
12 |
13 |
14 |
15 | Aplicacion
16 |
17 |
18 |
19 |
20 | javax.servlet
21 | javax.servlet-api
22 | 3.1.0
23 | provided
24 |
25 |
26 | org.mariadb.jdbc
27 | mariadb-java-client
28 | 2.0.1
29 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/Bloque11Aplicacion/aplicacion/src/main/java/com/inigoserrano/docker/aplicacion/LivenessProbe.java:
--------------------------------------------------------------------------------
1 | package com.inigoserrano.docker.aplicacion;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.annotation.WebServlet;
8 | import javax.servlet.http.HttpServlet;
9 | import javax.servlet.http.HttpServletRequest;
10 | import javax.servlet.http.HttpServletResponse;
11 | import java.util.Date;
12 |
13 |
14 | @WebServlet({ "/livenessProbe" })
15 | public class LivenessProbe extends HttpServlet {
16 |
17 | /**
18 | *
19 | */
20 | private static final long serialVersionUID = 8532332299687592651L;
21 |
22 | private static final Date inicio = new Date();
23 |
24 | private static final long espera = 5 * 60 * 1000;
25 |
26 | @Override
27 | protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
28 | throws ServletException, IOException {
29 | final PrintWriter writer = response.getWriter();
30 |
31 | Date ahora = new Date();
32 | if (inicio.getTime() + espera > ahora.getTime()){
33 | writer.println("OK");
34 | }else{
35 | response.sendError(500);
36 | }
37 | writer.println("OK");
38 | writer.flush();
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/aplicacion/src/main/java/com/inigoserrano/docker/aplicacion/Propiedades.java:
--------------------------------------------------------------------------------
1 | package com.inigoserrano.docker.aplicacion;
2 |
3 | import java.io.FileInputStream;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 | import java.util.Properties;
7 |
8 | public class Propiedades {
9 |
10 | public static String getPropiedad(final String propiedad) {
11 | try (InputStream input = new FileInputStream("/properties/config.properties")) {
12 | Properties prop = new Properties();
13 | prop.load(input);
14 | System.out.println("El valor para "+propiedad+" es: "+prop.getProperty(propiedad));
15 | return prop.getProperty(propiedad);
16 | } catch (IOException ex) {
17 | ex.printStackTrace();
18 | return null;
19 | }
20 | }
21 |
22 | public static String getSecreto(final String propiedad) {
23 | try (InputStream input = new FileInputStream("/secretos/secretos.properties")) {
24 | Properties prop = new Properties();
25 | prop.load(input);
26 | System.out.println("El valor para "+propiedad+" es: "+prop.getProperty(propiedad));
27 | return prop.getProperty(propiedad);
28 | } catch (IOException ex) {
29 | ex.printStackTrace();
30 | return null;
31 | }
32 | }
33 |
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/aplicacion/src/main/java/com/inigoserrano/docker/aplicacion/ReadynessProbe.java:
--------------------------------------------------------------------------------
1 | package com.inigoserrano.docker.aplicacion;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 | import java.sql.Connection;
6 | import java.sql.DriverManager;
7 | import java.sql.ResultSet;
8 | import java.sql.SQLException;
9 | import java.sql.Statement;
10 |
11 | import javax.servlet.ServletException;
12 | import javax.servlet.annotation.WebServlet;
13 | import javax.servlet.http.HttpServlet;
14 | import javax.servlet.http.HttpServletRequest;
15 | import javax.servlet.http.HttpServletResponse;
16 |
17 | @WebServlet({ "/readynessProbe" })
18 | public class ReadynessProbe extends HttpServlet {
19 |
20 | /**
21 | *
22 | */
23 | private static final long serialVersionUID = 8532332299687592651L;
24 |
25 |
26 |
27 | @Override
28 | protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
29 | throws ServletException, IOException {
30 |
31 |
32 | try(final PrintWriter writer = response.getWriter();
33 | final Connection connection = this.connectDatabase();
34 | final Statement stmt = connection.createStatement();
35 | final ResultSet resultSet = stmt.executeQuery("SELECT 1 FROM dual")) {
36 | if (resultSet.next()) {
37 | System.out.println("OK");
38 | writer.println("OK");
39 | }
40 | stmt.close();
41 | connection.close();
42 | writer.flush();
43 | } catch (ClassNotFoundException | SQLException e) {
44 | response.sendError(500);
45 | System.out.println("No OK");
46 | }
47 |
48 |
49 | }
50 |
51 | private Connection connectDatabase() throws ClassNotFoundException, SQLException {
52 | Class.forName("org.mariadb.jdbc.Driver");
53 | return DriverManager.getConnection("jdbc:mysql://mariadb-service:3306/curso", "root", "admin123");
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/Bloque11Aplicacion/aplicacion/src/main/java/com/inigoserrano/docker/aplicacion/ReadynessProbe.java:
--------------------------------------------------------------------------------
1 | package com.inigoserrano.docker.aplicacion;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 | import java.sql.Connection;
6 | import java.sql.DriverManager;
7 | import java.sql.ResultSet;
8 | import java.sql.SQLException;
9 | import java.sql.Statement;
10 |
11 | import javax.servlet.ServletException;
12 | import javax.servlet.annotation.WebServlet;
13 | import javax.servlet.http.HttpServlet;
14 | import javax.servlet.http.HttpServletRequest;
15 | import javax.servlet.http.HttpServletResponse;
16 |
17 | @WebServlet({ "/readynessProbe" })
18 | public class ReadynessProbe extends HttpServlet {
19 |
20 | /**
21 | *
22 | */
23 | private static final long serialVersionUID = 8532332299687592651L;
24 |
25 |
26 |
27 | @Override
28 | protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
29 | throws ServletException, IOException {
30 |
31 | final PrintWriter writer = response.getWriter();
32 | try {
33 | final Connection connection = this.connectDatabase();
34 | final Statement stmt = connection.createStatement();
35 | final ResultSet resultSet = stmt.executeQuery("SELECT * FROM Personas");
36 | if (resultSet.next()) {
37 | System.out.println("OK");
38 | writer.println("OK");
39 | }
40 | stmt.close();
41 | connection.close();
42 |
43 | } catch (final ClassNotFoundException e) {
44 | response.sendError(500);
45 | System.out.println("No OK");
46 | } catch (final SQLException e) {
47 | response.sendError(500);
48 | System.out.println("No OK");
49 | }
50 |
51 | writer.flush();
52 | }
53 |
54 | private Connection connectDatabase() throws ClassNotFoundException, SQLException {
55 | Class.forName("org.mariadb.jdbc.Driver");
56 | return DriverManager.getConnection("jdbc:mysql://mariadb-service:3306/curso", "root", "admin123");
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/Bloque14ConfigMaps/aplicacion/src/main/java/com/inigoserrano/docker/aplicacion/Aplicacion.java:
--------------------------------------------------------------------------------
1 | package com.inigoserrano.docker.aplicacion;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 | import java.sql.Connection;
6 | import java.sql.DriverManager;
7 | import java.sql.ResultSet;
8 | import java.sql.SQLException;
9 | import java.sql.Statement;
10 |
11 | import javax.servlet.ServletException;
12 | import javax.servlet.annotation.WebServlet;
13 | import javax.servlet.http.HttpServlet;
14 | import javax.servlet.http.HttpServletRequest;
15 | import javax.servlet.http.HttpServletResponse;
16 |
17 | @WebServlet({ "/aplicacion" })
18 | public class Aplicacion extends HttpServlet {
19 |
20 | /**
21 | *
22 | */
23 | private static final long serialVersionUID = 8532332299687592651L;
24 |
25 | @Override
26 | protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
27 | throws ServletException, IOException {
28 | System.out.println("Salida GET con BD");
29 | final PrintWriter writer = response.getWriter();
30 | writer.println("Salida GET con BD");
31 | try {
32 | final Connection connection = this.connectDatabase();
33 | final Statement stmt = connection.createStatement();
34 | final ResultSet resultSet = stmt.executeQuery("SELECT * FROM Personas");
35 | while (resultSet.next()) {
36 | writer.println("PersonaID: " + resultSet.getInt("PersonaID"));
37 | writer.println("Nombre: " + resultSet.getString("Nombre"));
38 | writer.println("Apellido1: " + resultSet.getString("Apellido1"));
39 | writer.println("Apellido2: " + resultSet.getString("Apellido2"));
40 | writer.println("Direccion: " + resultSet.getString("Direccion"));
41 | writer.println("Poblacion: " + resultSet.getString("Poblacion"));
42 | writer.println("-------------------------------------------------");
43 | }
44 | stmt.close();
45 | connection.close();
46 |
47 | } catch (final ClassNotFoundException e) {
48 | e.printStackTrace(writer);
49 | } catch (final SQLException e) {
50 | e.printStackTrace(writer);
51 | }
52 |
53 | writer.flush();
54 | }
55 |
56 | @Override
57 | protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
58 | throws ServletException, IOException {
59 | System.out.println("Salida POST");
60 | response.getWriter().println("Salida POST");
61 | response.getWriter().flush();
62 |
63 | }
64 |
65 | private Connection connectDatabase() throws ClassNotFoundException, SQLException {
66 | Class.forName("org.mariadb.jdbc.Driver");
67 | return DriverManager.getConnection(Propiedades.getPropiedad("cadena"), Propiedades.getPropiedad("usuario"),
68 | Propiedades.getSecreto("password"));
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/Bloque11Aplicacion/aplicacion/src/main/java/com/inigoserrano/docker/aplicacion/Aplicacion.java:
--------------------------------------------------------------------------------
1 | package com.inigoserrano.docker.aplicacion;
2 |
3 | import java.io.IOException;
4 | import java.io.PrintWriter;
5 | import java.sql.Connection;
6 | import java.sql.DriverManager;
7 | import java.sql.ResultSet;
8 | import java.sql.SQLException;
9 | import java.sql.Statement;
10 |
11 | import javax.servlet.ServletException;
12 | import javax.servlet.annotation.WebServlet;
13 | import javax.servlet.http.HttpServlet;
14 | import javax.servlet.http.HttpServletRequest;
15 | import javax.servlet.http.HttpServletResponse;
16 |
17 | @WebServlet({ "/aplicacion" })
18 | public class Aplicacion extends HttpServlet {
19 |
20 | /**
21 | *
22 | */
23 | private static final long serialVersionUID = 8532332299687592651L;
24 |
25 | @Override
26 | protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
27 | System.out.println("Salida GET con BD");
28 | final PrintWriter writer = response.getWriter();
29 | writer.println("Salida GET con BD");
30 | try{
31 | final Connection connection = this.connectDatabase();
32 | final Statement stmt = connection.createStatement();
33 | final ResultSet resultSet = stmt.executeQuery("SELECT * FROM Personas");
34 | while(resultSet.next()){
35 | writer.println("PersonaID: " + resultSet.getInt("PersonaID"));
36 | writer.println("Nombre: " + resultSet.getString("Nombre"));
37 | writer.println("Apellido1: " + resultSet.getString("Apellido1"));
38 | writer.println("Apellido2: " + resultSet.getString("Apellido2"));
39 | writer.println("Direccion: " + resultSet.getString("Direccion"));
40 | writer.println("Poblacion: " + resultSet.getString("Poblacion"));
41 | writer.println("-------------------------------------------------");
42 | }
43 | stmt.close();
44 | connection.close();
45 |
46 | }catch(final ClassNotFoundException e){
47 | e.printStackTrace(writer);
48 | }catch(final SQLException e){
49 | e.printStackTrace(writer);
50 | }
51 |
52 | writer.flush();
53 | }
54 |
55 | @Override
56 | protected void doPost(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
57 | System.out.println("Salida POST");
58 | response.getWriter().println("Salida POST");
59 | response.getWriter().flush();
60 |
61 | }
62 |
63 | private Connection connectDatabase() throws ClassNotFoundException, SQLException {
64 | Class.forName("org.mariadb.jdbc.Driver");
65 | return DriverManager.getConnection("jdbc:mysql://mariadb-service:3306/curso", "root", "admin123");
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------