mirror of
https://github.com/Dannecron/netology-devops.git
synced 2025-12-25 15:22:37 +03:00
homework 13.1: fix task 1
This commit is contained in:
@@ -1,4 +1,86 @@
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: postgres-config
|
||||
labels:
|
||||
app: postgres
|
||||
data:
|
||||
POSTGRES_DB: news
|
||||
POSTGRES_USER: db_user
|
||||
POSTGRES_PASSWORD: db_passwd
|
||||
PGDATA: /var/lib/postgresql/data
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
name: postgres-pv-volume # Sets PV's name
|
||||
labels:
|
||||
type: local # Sets PV's type to local
|
||||
app: postgres
|
||||
spec:
|
||||
storageClassName: manual
|
||||
capacity:
|
||||
storage: 1Gi # Sets PV Volume
|
||||
accessModes:
|
||||
- ReadWriteMany
|
||||
hostPath:
|
||||
path: "/mnt/pgsql_data"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: postgres-pv-claim # Sets name of PVC
|
||||
labels:
|
||||
app: postgres
|
||||
spec:
|
||||
storageClassName: manual
|
||||
accessModes:
|
||||
- ReadWriteMany # Sets read and write access
|
||||
resources:
|
||||
requests:
|
||||
storage: 1Gi # Sets volume size
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
labels:
|
||||
app: testing-app
|
||||
db-kind: postgresql
|
||||
name: testing-db
|
||||
namespace: default
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
db-kind: postgresql
|
||||
serviceName: postgres
|
||||
replicas: 1
|
||||
podManagementPolicy: "Parallel"
|
||||
updateStrategy:
|
||||
type: "RollingUpdate"
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
db-kind: postgresql
|
||||
spec:
|
||||
terminationGracePeriodSeconds: 60
|
||||
containers:
|
||||
- name: postgres
|
||||
image: postgres:13-alpine # Sets Image
|
||||
imagePullPolicy: "IfNotPresent"
|
||||
ports:
|
||||
- containerPort: 5432 # Exposes container port
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: postgres-config
|
||||
volumeMounts:
|
||||
- mountPath: /var/lib/postgresql/data
|
||||
name: postgredb
|
||||
volumes:
|
||||
- name: postgredb
|
||||
persistentVolumeClaim:
|
||||
claimName: postgres-pv-claim
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
@@ -8,7 +90,13 @@ metadata:
|
||||
namespace: default
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: testing-app
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: testing-app
|
||||
spec:
|
||||
containers:
|
||||
- image: dannecron/netology-devops-k8s-app:frontend-latest
|
||||
@@ -19,64 +107,5 @@ spec:
|
||||
name: netology-backend
|
||||
env:
|
||||
- name: DATABASE_URL
|
||||
value: "postgres://pg_user:pg_passwd@postgres:5432/news"
|
||||
value: "postgres://db_user:db_passwd@postgres:5432/news"
|
||||
terminationGracePeriodSeconds: 30
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
|
||||
metadata:
|
||||
labels:
|
||||
app: testing-app
|
||||
db-kind: postgresql
|
||||
name: testing-db
|
||||
namespace: default
|
||||
|
||||
spec:
|
||||
serviceName: postgres
|
||||
replicas: 1
|
||||
podManagementPolicy: "Parallel"
|
||||
updateStrategy:
|
||||
type: "RollingUpdate"
|
||||
selector:
|
||||
matchLabels:
|
||||
db-kind: postgresql
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
db-kind: postgresql
|
||||
specs:
|
||||
volumes: []
|
||||
terminationGracePeriodSeconds: 60
|
||||
containers:
|
||||
- name: postgres
|
||||
image: postgres:13-alpine
|
||||
imagePullPolicy: "IfNotPresent"
|
||||
ports:
|
||||
- name: postgres
|
||||
containerPort: 5432
|
||||
protocol: TCP
|
||||
resources:
|
||||
requests:
|
||||
cpu: 100m
|
||||
memory: 256Mi
|
||||
env:
|
||||
- name: POSTGRES_USER
|
||||
value: pg_user
|
||||
- name: POSTGRES_PASSWORD
|
||||
value: pg_passwd
|
||||
- name: POSTGRES_DB
|
||||
value: news
|
||||
- name: PGDATA
|
||||
value: /var/lib/postgresql/data
|
||||
volumeMounts:
|
||||
- mountPath: /var/lib/postgresql/data
|
||||
name: postgres
|
||||
volumeClaimTemplates:
|
||||
- metadata:
|
||||
name: postgres
|
||||
spec:
|
||||
accessModes: [ "ReadWriteOnce" ]
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
||||
|
||||
@@ -23,6 +23,30 @@
|
||||
и собраны два тега: `frontend-latest` и `backend-latest`.
|
||||
|
||||
Итоговая конфигурация для деплоя приложения в кластер k8s будет выглядеть следующим образом: [testing/deployment.yml](./config/testing/deployment.yml).
|
||||
Здесь будет создано несколько сущностей, а именно:
|
||||
* `ConfigMap` для хранения конфигурации `postgresql`
|
||||
* `PersistentVolume` - персистентное дисковое хранилище для базы данных
|
||||
* `PersistentVolumeClaim` - конфигурация для использования хранилища подами
|
||||
* `StatefulSet` - разворачивание базы данных `postgresql`
|
||||
* `Deployment` - разворачивание непосредственно приложения
|
||||
|
||||
Применение конфигурации:
|
||||
|
||||
```shell
|
||||
kubectl apply -f testing/deployment.yml
|
||||
```
|
||||
|
||||
После применения:
|
||||
```shell
|
||||
kubectl get pods
|
||||
```
|
||||
|
||||
```text
|
||||
kubectl get pods
|
||||
NAME READY STATUS RESTARTS AGE
|
||||
testing-app-57d756f489-r6gw8 2/2 Running 0 4m13s
|
||||
testing-db-0 1/1 Running 5 (6m20s ago) 7m53s
|
||||
```
|
||||
|
||||
### Задание 2
|
||||
|
||||
|
||||
Reference in New Issue
Block a user