Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homework 4 #4

Merged
merged 1 commit into from
May 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions kubernetes-volumes/cm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: homework-4-conf
namespace: homework
data:
health: "100"
player_initial_lives: "3"
ui_properties_file_name: "user-interface.properties"
power: "3000"
speed: "18"
41 changes: 41 additions & 0 deletions kubernetes-volumes/configmap-nginx.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-conf
namespace: homework
data:
default.conf: |
server {
listen 8000;
listen [::]:8000;
server_name localhost;
#access_log /var/log/nginx/host.access.log main;

location / {
root /homework;
index index.php; #костыль, чтобы отображалось содержимое директории, даже если в ней есть файл index.html
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
charset utf-8;
}

location /homepage { #заглушка для /homepage чтоб не было 404
root /homework;
try_files $uri $uri/ /homepage.html;
}

location ~/conf/ {
autoindex on;
root /homework;
default_type "text/html";
}

# error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;

location = /50x.html {
root /usr/share/nginx/html;
}
}
61 changes: 61 additions & 0 deletions kubernetes-volumes/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx
namespace: homework
labels:
app: nginx
spec:
replicas: 3
selector:
matchLabels:
app: nginx
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
template:
metadata:
labels:
app: nginx
spec:
nodeSelector:
homework: "true"
initContainers:
- name: init-container
image: busybox:1.36.1
command: ["/bin/sh", "-c", "echo Hello, world! > /init/index.html && echo Hello from homepage > /init/homepage.html"]
volumeMounts:
- name: shared-data
mountPath: /init
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 8000
readinessProbe:
httpGet:
path: /index.html
port: 8000
scheme: HTTP
volumeMounts:
- name: shared-data
mountPath: /homework
- name: nginx-conf
mountPath: /etc/nginx/conf.d
- name: homework-4-conf
mountPath: /homework/conf
lifecycle:
preStop:
exec:
command: ["rm", "-f", "/homework/index.html"]
volumes:
- name: nginx-conf
configMap:
name: nginx-conf
- name: homework-4-conf
configMap:
name: homework-4-conf
- name: shared-data
persistentVolumeClaim:
claimName: homework-pvc
27 changes: 27 additions & 0 deletions kubernetes-volumes/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: nginx-ingress
namespace: homework
# annotations:
# nginx.ingress.kubernetes.io/rewrite-target: /homepage/
spec:
ingressClassName: nginx
rules:
- host: homework.otus
http:
paths:
# - path: /index.html
# pathType: ImplementationSpecific
# backend:
# service:
# name: nginx-service
# port:
# number: 80
- path: /
pathType: Prefix
backend:
service:
name: nginx-service
port:
number: 80
4 changes: 4 additions & 0 deletions kubernetes-volumes/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: homework
12 changes: 12 additions & 0 deletions kubernetes-volumes/pvc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: homework-pvc
namespace: homework
spec:
storageClassName: "custom"
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
16 changes: 16 additions & 0 deletions kubernetes-volumes/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Для проверки нужно:
- включить миникуб minikube start
- включить ингресс-контроллер minikube addons ingress
- включить туннель в миникуб minikube tunnel
- добавить в hosts запись 127.0.0.1 homework.otus
- выполнить kubectl label nodes minikube homework=true (для того точбы запустились поды, см. доп. задания из ДЗ №2)
- перейти в папку с ДЗ №4 cd kubernetes-volumes
- выполнить команды:
kubectl apply -f namespace.yaml - создание неймспейса homework
kubectl apply -f configmap-nginx.yaml - создание конфигурации nginx
kubectl apply -f cm.yaml - создание конфигмапа из задания 4 (с произвольным набором ключей)
kubectl apply -f storageClass.yaml - создание storageClass для выполнения доп.задания
kubectl apply -f pvc.yaml - создание pvc c кастомным storageClass
kubectl apply -f deployment.yaml - развертывание приложения
kubectl apply -f service.yaml - настройка сервиса
kubectl apply -f ingress.yaml - настройка ингресса
13 changes: 13 additions & 0 deletions kubernetes-volumes/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: nginx-service
namespace: homework
spec:
type: ClusterIP
selector:
app: nginx
ports:
- protocol: TCP
port: 80
targetPort: 8000
8 changes: 8 additions & 0 deletions kubernetes-volumes/storageClass.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: custom
namespace: homework
provisioner: k8s.io/minikube-hostpath
reclaimPolicy: Retain
volumeBindingMode: Immediate
Loading