Assigment 2 finish
This commit is contained in:
parent
70d6f6578c
commit
2646bede01
45
z2/README.md
Normal file
45
z2/README.md
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
# My Web Application
|
||||||
|
|
||||||
|
## Project Description
|
||||||
|
|
||||||
|
This project is a simple web application that provides a user interface to manage a MySQL database. The application consists of a single page that allows the user to perform basic CRUD operations on a list of items stored in the database.
|
||||||
|
Containers
|
||||||
|
|
||||||
|
## The application consists of the following containers:
|
||||||
|
|
||||||
|
mysql: This container runs the MySQL database server.
|
||||||
|
web: This container runs the web server and serves the web pages to the user.
|
||||||
|
|
||||||
|
|
||||||
|
## The following Kubernetes objects are used in the application:
|
||||||
|
|
||||||
|
PersistentVolume: This object is used to create a named volume for the MySQL data.
|
||||||
|
StatefulSet: This object is used to manage the mysql container and ensure that there is only one instance running at any given time.
|
||||||
|
Deployment: This object is used to manage the web container and ensure that there is always at least one instance running.
|
||||||
|
Service: This object is used to provide access to the mysql and web containers from outside the Kubernetes cluster.
|
||||||
|
|
||||||
|
## Virtual Networks and Named Volumes
|
||||||
|
|
||||||
|
The application uses a virtual network to allow communication between the mysql and web containers. The mysql container stores its data in a named volume called mysql-persistent-storage.
|
||||||
|
|
||||||
|
## Container Configuration
|
||||||
|
|
||||||
|
The mysql container is configured to use the mysql-persistent-storage volume for data storage. The web container is configured to connect to the mysql container using the Kubernetes service mysql.
|
||||||
|
|
||||||
|
## To run the application, perform the following steps:
|
||||||
|
|
||||||
|
Install Kubernetes on your machine.
|
||||||
|
Clone the project repository.
|
||||||
|
Change into the project directory.
|
||||||
|
Execute "./start-app.sh" make sure it have execution permission.
|
||||||
|
Wait for the mysql and web containers to start: kubectl get pods -n my-app.
|
||||||
|
|
||||||
|
## To view the application on the web, perform the following steps:
|
||||||
|
|
||||||
|
Get the IP address of the web service "kubectl get services -n my-app" or use loclahost.
|
||||||
|
In your web browser, navigate to http://<web-service-ip>.
|
||||||
|
|
||||||
|
|
||||||
|
## To clean up the application, perform the following steps:
|
||||||
|
|
||||||
|
Execute "./stop-app.sh" make sure it have execution permission.
|
25
z2/deployment.yaml
Normal file
25
z2/deployment.yaml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: phpmyadmin
|
||||||
|
namespace: ibanweb
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: phpmyadmin
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: phpmyadmin
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: phpmyadmin
|
||||||
|
image: phpmyadmin/phpmyadmin:latest
|
||||||
|
env:
|
||||||
|
- name: PMA_HOST
|
||||||
|
value: mysql
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
name: http
|
||||||
|
|
4
z2/namespace.yaml
Normal file
4
z2/namespace.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: ibanweb
|
14
z2/prepare-app.sh
Executable file
14
z2/prepare-app.sh
Executable file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# create namespace
|
||||||
|
kubectl apply -f namespace.yaml
|
||||||
|
|
||||||
|
# create mysql secrets
|
||||||
|
kubectl create secret generic mysql-secret --from-literal=password=dromedario -n ibanweb
|
||||||
|
|
||||||
|
# create mysql statefulset and service
|
||||||
|
kubectl apply -f statefulset.yaml
|
||||||
|
kubectl apply -f service.yaml
|
||||||
|
|
||||||
|
# create phpmyadmin deployment
|
||||||
|
kubectl apply -f deployment.yaml
|
8
z2/secret.yaml
Normal file
8
z2/secret.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Secret
|
||||||
|
metadata:
|
||||||
|
name: mysql-secret
|
||||||
|
namespace: ibanweb
|
||||||
|
type: Opaque
|
||||||
|
data:
|
||||||
|
password: YWxtZW5kcmE= #la contraseña es "almendra" en base64
|
12
z2/service.yaml
Normal file
12
z2/service.yaml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: mysql
|
||||||
|
namespace: ibanweb
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- name: mysql
|
||||||
|
port: 3306
|
||||||
|
selector:
|
||||||
|
app: mysql
|
||||||
|
|
7
z2/start-app.sh
Executable file
7
z2/start-app.sh
Executable file
@ -0,0 +1,7 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# prepare app
|
||||||
|
./prepare-app.sh
|
||||||
|
|
||||||
|
# expose phpmyadmin deployment
|
||||||
|
kubectl expose deployment phpmyadmin --type=LoadBalancer --port=80 --target-port=80 -n ibanweb
|
53
z2/statefulset.yaml
Normal file
53
z2/statefulset.yaml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolume
|
||||||
|
metadata:
|
||||||
|
name: my-pv
|
||||||
|
spec:
|
||||||
|
capacity:
|
||||||
|
storage: 1Gi
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
persistentVolumeReclaimPolicy: Retain
|
||||||
|
storageClassName: slow
|
||||||
|
hostPath:
|
||||||
|
path: /data/my-pv/
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: mysql
|
||||||
|
namespace: ibanweb
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: mysql
|
||||||
|
serviceName: mysql
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: mysql
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: mysql
|
||||||
|
image: mysql:latest
|
||||||
|
env:
|
||||||
|
- name: MYSQL_ROOT_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: mysql-secret
|
||||||
|
key: password
|
||||||
|
ports:
|
||||||
|
- containerPort: 3306
|
||||||
|
name: mysql
|
||||||
|
volumeMounts:
|
||||||
|
- name: mysql-persistent-storage
|
||||||
|
mountPath: /var/lib/mysql
|
||||||
|
volumeClaimTemplates:
|
||||||
|
- metadata:
|
||||||
|
name: mysql-persistent-storage
|
||||||
|
spec:
|
||||||
|
accessModes: [ "ReadWriteOnce" ]
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 1Gi
|
8
z2/stop-app.sh
Executable file
8
z2/stop-app.sh
Executable file
@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# delete app objects
|
||||||
|
kubectl delete -f deployment.yaml
|
||||||
|
kubectl delete -f service.yaml
|
||||||
|
kubectl delete -f statefulset.yaml
|
||||||
|
kubectl delete secret mysql-secret -n ibanweb
|
||||||
|
kubectl delete namespace ibanweb
|
Loading…
Reference in New Issue
Block a user