Загрузить файлы в « z2»
This commit is contained in:
parent
16525b1b2f
commit
ddf6e217ac
24
z2/Dockerfile
Normal file
24
z2/Dockerfile
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
# исп официальный образ Nginx
|
||||||
|
|
||||||
|
|
||||||
|
FROM nginx:latest
|
||||||
|
|
||||||
|
# коп конфиг файлы в конт
|
||||||
|
|
||||||
|
COPY nginx/nginx.conf /etc/nginx/nginx.conf
|
||||||
|
COPY nginx/default.conf /etc/nginx/conf.d/default.conf
|
||||||
|
|
||||||
|
# коп содержимое веб-приложения в конт
|
||||||
|
|
||||||
|
|
||||||
|
COPY ./app /usr/share/nginx/html
|
||||||
|
|
||||||
|
# откр порт для веб-сервера
|
||||||
|
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
|
||||||
|
# запускаем нгингс
|
||||||
|
|
||||||
|
|
||||||
|
CMD ["nginx", "-g", "daemon off;"]
|
67
z2/README.md
Normal file
67
z2/README.md
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
# Docker Web Application with MySQL and Nginx
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
- Docker
|
||||||
|
- Docker Compose
|
||||||
|
|
||||||
|
## Description
|
||||||
|
This web application consists of two services:
|
||||||
|
1. A **web service** using Nginx to serve static HTML files.
|
||||||
|
2. A **database service** using MySQL, which persists its data in a Docker volume.
|
||||||
|
|
||||||
|
## Docker Volumes and Networks
|
||||||
|
- **Volume**: `db_data` - used to persist MySQL data.
|
||||||
|
- **Network**: `app-network` - internal network for the services to communicate.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
- **Nginx**: Serves static HTML files from the `/html` directory.
|
||||||
|
- **MySQL**: Configured with `MYSQL_ROOT_PASSWORD` and a default database `mydb`.
|
||||||
|
|
||||||
|
## How to Use
|
||||||
|
|
||||||
|
### Preparing the app
|
||||||
|
Run the following command to prepare the application:
|
||||||
|
```bash
|
||||||
|
./prepare-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Starting the app
|
||||||
|
To start the app, run:
|
||||||
|
```bash
|
||||||
|
./start-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
The app will be available at `http://localhost:5000`.
|
||||||
|
|
||||||
|
### Stopping the app
|
||||||
|
To stop the app, run:
|
||||||
|
```bash
|
||||||
|
./stop-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Removing the app
|
||||||
|
To remove all resources related to the app, run:
|
||||||
|
```bash
|
||||||
|
./remove-app.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Prepare the app
|
||||||
|
./prepare-app.sh
|
||||||
|
Preparing app...
|
||||||
|
|
||||||
|
# Start the app
|
||||||
|
./start-app.sh
|
||||||
|
Running app ...
|
||||||
|
The app is available at http://localhost:5000
|
||||||
|
|
||||||
|
# Stop the app
|
||||||
|
./stop-app.sh
|
||||||
|
Stopping app...
|
||||||
|
|
||||||
|
# Remove the app
|
||||||
|
./remove-app.sh
|
||||||
|
Removed app.
|
||||||
|
```
|
22
z2/deployment.yaml
Normal file
22
z2/deployment.yaml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: web-deployment
|
||||||
|
namespace: webapp
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: web
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: web
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: nginx
|
||||||
|
image: web-app:latest
|
||||||
|
imagePullPolicy: Never
|
||||||
|
ports:
|
||||||
|
- containerPort: 80
|
||||||
|
|
32
z2/docker-compose.yml
Normal file
32
z2/docker-compose.yml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
version: "3.7"
|
||||||
|
services:
|
||||||
|
web:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
ports:
|
||||||
|
- "5000:80"
|
||||||
|
volumes:
|
||||||
|
- ./app:/usr/share/nginx/html
|
||||||
|
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
|
||||||
|
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
restart: always
|
||||||
|
db:
|
||||||
|
image: mysql:5.7
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: yankasabutski
|
||||||
|
volumes:
|
||||||
|
- db_data:/var/lib/mysql
|
||||||
|
networks:
|
||||||
|
- app-network
|
||||||
|
restart: always
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
|
|
||||||
|
networks:
|
||||||
|
app-network:
|
||||||
|
driver: bridge
|
||||||
|
|
||||||
|
|
4
z2/namespace.yaml
Normal file
4
z2/namespace.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: webapp
|
14
z2/prepare-app.sh
Normal file
14
z2/prepare-app.sh
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
docker build -t web-app:latest .
|
||||||
|
|
||||||
|
|
||||||
|
# включаем созд контейнеров
|
||||||
|
|
||||||
|
|
||||||
|
docker-compose build
|
||||||
|
|
||||||
|
# создание сети и томов
|
||||||
|
|
||||||
|
|
||||||
|
docker network create app-network
|
||||||
|
docker volume create db_data
|
9
z2/remove-app.sh
Normal file
9
z2/remove-app.sh
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# удал все конт тома и сети
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
docker-compose down --volumes --remove-orphans
|
||||||
|
docker network rm app-network
|
||||||
|
docker volume rm db_data
|
26
z2/service.yaml
Normal file
26
z2/service.yaml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: web-service
|
||||||
|
namespace: webapp
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: web
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 80
|
||||||
|
targetPort: 80
|
||||||
|
type: NodePort
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: postgres
|
||||||
|
namespace: webapp
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 5432
|
||||||
|
selector:
|
||||||
|
app: postgres
|
22
z2/start-app.sh
Normal file
22
z2/start-app.sh
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
kubectl apply -f namespace.yaml
|
||||||
|
kubectl apply -f deployment.yaml
|
||||||
|
kubectl apply -f statefulset.yaml
|
||||||
|
kubectl apply -f service.yaml
|
||||||
|
|
||||||
|
|
||||||
|
# запуск конт в фоновом режиме
|
||||||
|
|
||||||
|
|
||||||
|
docker-compose up -d
|
||||||
|
|
||||||
|
|
||||||
|
# вывод на каком порте доступно приложение
|
||||||
|
|
||||||
|
|
||||||
|
echo "The app is available at http://localhost:5000"
|
||||||
|
#!/bin/bash
|
||||||
|
kubectl apply -f namespace.yaml
|
||||||
|
kubectl apply -f deployment.yaml
|
||||||
|
kubectl apply -f statefulset.yaml
|
||||||
|
kubectl apply -f service.yaml
|
66
z2/statefulset.yaml
Normal file
66
z2/statefulset.yaml
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolume
|
||||||
|
metadata:
|
||||||
|
name: pg-pv
|
||||||
|
namespace: webapp
|
||||||
|
spec:
|
||||||
|
capacity:
|
||||||
|
storage: 1Gi
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
hostPath:
|
||||||
|
path: "/mnt/data/pgdata"
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: PersistentVolumeClaim
|
||||||
|
metadata:
|
||||||
|
name: pg-pvc
|
||||||
|
namespace: webapp
|
||||||
|
spec:
|
||||||
|
accessModes:
|
||||||
|
- ReadWriteOnce
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 1Gi
|
||||||
|
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: StatefulSet
|
||||||
|
metadata:
|
||||||
|
name: postgres
|
||||||
|
namespace: webapp
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: postgres
|
||||||
|
serviceName: "postgres"
|
||||||
|
replicas: 1
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: postgres
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: postgres
|
||||||
|
image: postgres:15
|
||||||
|
env:
|
||||||
|
- name: POSTGRES_DB
|
||||||
|
value: mydb
|
||||||
|
- name: POSTGRES_USER
|
||||||
|
value: user
|
||||||
|
- name: POSTGRES_PASSWORD
|
||||||
|
value: password
|
||||||
|
ports:
|
||||||
|
- containerPort: 5432
|
||||||
|
volumeMounts:
|
||||||
|
- name: pg-storage
|
||||||
|
mountPath: /var/lib/postgresql/data
|
||||||
|
volumeClaimTemplates:
|
||||||
|
- metadata:
|
||||||
|
name: pg-storage
|
||||||
|
spec:
|
||||||
|
accessModes: ["ReadWriteOnce"]
|
||||||
|
resources:
|
||||||
|
requests:
|
||||||
|
storage: 1Gi
|
12
z2/stop-app.sh
Normal file
12
z2/stop-app.sh
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
kubectl delete -f service.yaml
|
||||||
|
kubectl delete -f statefulset.yaml
|
||||||
|
kubectl delete -f deployment.yaml
|
||||||
|
kubectl delete -f namespace.yaml
|
||||||
|
|
||||||
|
|
||||||
|
# ост все конт
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
docker-compose down
|
Loading…
Reference in New Issue
Block a user