diff --git a/kubernetes-volumes/cm.yaml b/kubernetes-volumes/cm.yaml new file mode 100644 index 0000000..d6641a5 --- /dev/null +++ b/kubernetes-volumes/cm.yaml @@ -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" \ No newline at end of file diff --git a/kubernetes-volumes/configmap-nginx.yaml b/kubernetes-volumes/configmap-nginx.yaml new file mode 100644 index 0000000..aca27f6 --- /dev/null +++ b/kubernetes-volumes/configmap-nginx.yaml @@ -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; + } + } \ No newline at end of file diff --git a/kubernetes-volumes/deployment.yaml b/kubernetes-volumes/deployment.yaml new file mode 100644 index 0000000..89cfc9a --- /dev/null +++ b/kubernetes-volumes/deployment.yaml @@ -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 \ No newline at end of file diff --git a/kubernetes-volumes/ingress.yaml b/kubernetes-volumes/ingress.yaml new file mode 100644 index 0000000..7465eb1 --- /dev/null +++ b/kubernetes-volumes/ingress.yaml @@ -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 \ No newline at end of file diff --git a/kubernetes-volumes/namespace.yaml b/kubernetes-volumes/namespace.yaml new file mode 100644 index 0000000..8fed436 --- /dev/null +++ b/kubernetes-volumes/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: homework \ No newline at end of file diff --git a/kubernetes-volumes/pvc.yaml b/kubernetes-volumes/pvc.yaml new file mode 100644 index 0000000..40da5f4 --- /dev/null +++ b/kubernetes-volumes/pvc.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: homework-pvc + namespace: homework +spec: + storageClassName: "custom" + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi \ No newline at end of file diff --git a/kubernetes-volumes/readme.md b/kubernetes-volumes/readme.md new file mode 100644 index 0000000..f2c7f87 --- /dev/null +++ b/kubernetes-volumes/readme.md @@ -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 - настройка ингресса \ No newline at end of file diff --git a/kubernetes-volumes/service.yaml b/kubernetes-volumes/service.yaml new file mode 100644 index 0000000..4460f94 --- /dev/null +++ b/kubernetes-volumes/service.yaml @@ -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 \ No newline at end of file diff --git a/kubernetes-volumes/storageClass.yaml b/kubernetes-volumes/storageClass.yaml new file mode 100644 index 0000000..da724e7 --- /dev/null +++ b/kubernetes-volumes/storageClass.yaml @@ -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 \ No newline at end of file