From 90f9145e28af470fd1f500b7e9014fb63999caa8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 8 May 2024 15:52:15 +0300 Subject: [PATCH] homework 2 --- kubernetes-controllers/configmap-nginx.yaml | 34 +++++++++++++ kubernetes-controllers/deployment.yaml | 56 +++++++++++++++++++++ kubernetes-controllers/namespace.yaml | 4 ++ 3 files changed, 94 insertions(+) create mode 100644 kubernetes-controllers/configmap-nginx.yaml create mode 100644 kubernetes-controllers/deployment.yaml create mode 100644 kubernetes-controllers/namespace.yaml diff --git a/kubernetes-controllers/configmap-nginx.yaml b/kubernetes-controllers/configmap-nginx.yaml new file mode 100644 index 0000000..390b243 --- /dev/null +++ b/kubernetes-controllers/configmap-nginx.yaml @@ -0,0 +1,34 @@ +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; + } + + # 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-controllers/deployment.yaml b/kubernetes-controllers/deployment.yaml new file mode 100644 index 0000000..80cada8 --- /dev/null +++ b/kubernetes-controllers/deployment.yaml @@ -0,0 +1,56 @@ +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"] + volumeMounts: + - name: shared-data + mountPath: /init + containers: + - name: nginx + image: nginx:1.14.2 + ports: + - containerPort: 8000 + readinessProbe: + exec: + command: + - sh + - -c + - cat /homework/index.html + volumeMounts: + - name: shared-data + mountPath: /homework + - name: nginx-conf + mountPath: /etc/nginx/conf.d + lifecycle: + preStop: + exec: + command: ["rm", "-f", "/homework/index.html"] + volumes: + - name: shared-data + emptyDir: {} + - name: nginx-conf + configMap: + name: nginx-conf \ No newline at end of file diff --git a/kubernetes-controllers/namespace.yaml b/kubernetes-controllers/namespace.yaml new file mode 100644 index 0000000..8fed436 --- /dev/null +++ b/kubernetes-controllers/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: homework \ No newline at end of file