diff --git a/setup.sh b/setup.sh new file mode 100644 index 0000000..460d70d --- /dev/null +++ b/setup.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +echo -e "Minikube Run ..." +echo -e "Might take a while to install everything and get the cluster ready." +minikube start --cpus=2 --vm-driver=docker --bootstrapper=kubeadm \ + --extra-config=kubelet.authentication-token-webhook=true \ + --extra-config=apiserver.service-node-port-range=3000-35000 + +# IF, you do not have Metallb addon in your minikube, you can download the manifest. +# and "comment" "enable metallb" line in Enabling Addons section. +# ------------------------------------- +# echo -e "Setting Load balancer ..." +# kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.8.1/manifests/namespace.yaml +# kubectl apply -f https://raw.githubusercontent.com/metallb/metallb/v0.8.1/manifests/metallb.yaml +# echo -e "If already exists a member list, It will show an Error Message, but it is okay..." +# kubectl create secret generic -n metallb-system memberlist --from-literal=secretkey="$(openssl rand -base64 128)" + +echo -e "Enabling Addons ..." +minikube addons enable metrics-server +minikube addons enable dashboard +minikube addons enable metallb + +echo -e "Loading MetalLB ..." +kubectl apply -f ./srcs/metallb-config.yaml + +echo -e "Launching Pods ..." +eval $(minikube docker-env) +docker build srcs/nginx -t nginx-img +docker build srcs/ftps -t ftps-img +docker build srcs/wordpress -t wordpress-img +docker build srcs/mysql -t mysql-img +docker build srcs/phpmyadmin -t phpmyadmin-img +docker build srcs/grafana -t grafana-img +docker build srcs/influxdb -t influxdb-img + +echo -e "Configure Minikube ..." +kubectl apply -f ./srcs/nginx/nginx.yaml +kubectl apply -f ./srcs/ftps/ftps.yaml +kubectl apply -f ./srcs/mysql/mysql.yaml +kubectl apply -f ./srcs/wordpress/wordpress.yaml +kubectl apply -f ./srcs/phpmyadmin/phpmyadmin.yaml +kubectl apply -f ./srcs/influxdb/influxdb.yaml +kubectl apply -f ./srcs/grafana/grafana.yaml + +echo -e "You can now proceed." diff --git a/srcs/ftps/Dockerfile b/srcs/ftps/Dockerfile new file mode 100644 index 0000000..fedb725 --- /dev/null +++ b/srcs/ftps/Dockerfile @@ -0,0 +1,14 @@ +FROM alpine:3.12 + +LABEL maintainer="fcoelho " \ + version="1.0.0" + +RUN apk upgrade && \ + apk add openssl vsftpd + +COPY setup.sh /tmp/ +RUN chmod +x /tmp/setup.sh + +EXPOSE 21 30000 + +ENTRYPOINT ["/tmp/setup.sh"] \ No newline at end of file diff --git a/srcs/ftps/ftps.yaml b/srcs/ftps/ftps.yaml new file mode 100644 index 0000000..572b0ee --- /dev/null +++ b/srcs/ftps/ftps.yaml @@ -0,0 +1,92 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: ftps +spec: + selector: + matchLabels: + app: ftps + strategy: + type: Recreate + template: + metadata: + name: ftps + labels: + app: ftps + spec: + containers: + - name: ftps + image: ftps-img + imagePullPolicy: Never + ports: + - name: ftps-connection + containerPort: 21 + - name: passv-mode + containerPort: 30000 + env: + - name: USERNAME + valueFrom: + secretKeyRef: + name: wordpress-secret + key: username + - name: PASSWORD + valueFrom: + secretKeyRef: + name: wordpress-secret + key: password + volumeMounts: + - name: ftps-config + mountPath: /etc/vsftpd + volumes: + - name: ftps-config + configMap: + name: ftps-config + +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + metallb.universe.tf/allow-shared-ip: shared + name: ftps +spec: + ports: + - name: ftps-connection + port: 21 + - name: passv-mode + port: 30000 + selector: + app: ftps + type: LoadBalancer +--- + apiVersion: v1 + kind: ConfigMap + metadata: + name: ftps-config + data: + vsftpd.conf: | + anonymous_enable=NO + local_enable=YES + write_enable=YES + local_umask=022 + dirmessage_enable=YES + xferlog_enable=YES + xferlog_std_format=YES + chroot_local_user=YES + allow_writeable_chroot=YES + connect_from_port_20=YES + pam_service_name=vsftpd + seccomp_sandbox=NO + ssl_enable=YES + allow_anon_ssl=NO + force_local_data_ssl=NO + force_local_logins_ssl=NO + require_ssl_reuse=YES + ssl_ciphers=HIGH + pasv_enable=YES + pasv_promiscuous=YES + pasv_address=192.168.49.3 + pasv_min_port=30000 + pasv_max_port=30000 + rsa_cert_file=/etc/ssl/certs/vsftpd.crt + rsa_private_key_file=/etc/ssl/private/vsftpd.key \ No newline at end of file diff --git a/srcs/ftps/setup.sh b/srcs/ftps/setup.sh new file mode 100644 index 0000000..7e506b0 --- /dev/null +++ b/srcs/ftps/setup.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +openssl req -newkey rsa:2048 -x509 -days 365 -nodes \ + -keyout /etc/ssl/private/vsftpd.key \ + -out /etc/ssl/certs/vsftpd.crt -subj \ + "/C=BR/ST=Sao Paulo/L=Sao Paulo/O=42SP, Inc./OU=IT/CN=ft_services" + +#In this case, the User and Password are related to the VM used to correct the project. +mkdir -p /var/ftp +adduser -D -h /var/ftp $USERNAME +echo "$USERNAME:$PASSWORD" | chpasswd + +vsftpd /etc/vsftpd/vsftpd.conf \ No newline at end of file diff --git a/srcs/grafana/Dockerfile b/srcs/grafana/Dockerfile new file mode 100644 index 0000000..67f8930 --- /dev/null +++ b/srcs/grafana/Dockerfile @@ -0,0 +1,13 @@ +FROM alpine:3.11.6 + +WORKDIR /usr/share/grafana + +RUN apk update +RUN apk add grafana \ + --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/ + +COPY dashboards/ /usr/share/grafana/public/dashboards/ + +EXPOSE 3000 + +ENTRYPOINT ["/usr/sbin/grafana-server", "web"] \ No newline at end of file diff --git a/srcs/grafana/dashboards/ftps.json b/srcs/grafana/dashboards/ftps.json new file mode 100644 index 0000000..ee0599c --- /dev/null +++ b/srcs/grafana/dashboards/ftps.json @@ -0,0 +1,130 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 5, + "links": [], + "panels": [ + { + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "7.3.0", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "kubernetes_pod_container", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "restarts_total" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "container_name", + "operator": "=", + "value": "ftps" + } + ] + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Restarts Total", + "type": "stat" + } + ], + "schemaVersion": 26, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "ftps", + "uid": "3j9b2k2Gk", + "version": 4 +} \ No newline at end of file diff --git a/srcs/grafana/dashboards/grafana.json b/srcs/grafana/dashboards/grafana.json new file mode 100644 index 0000000..4ec0109 --- /dev/null +++ b/srcs/grafana/dashboards/grafana.json @@ -0,0 +1,162 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 1, + "links": [], + "panels": [ + { + "datasource": "InfluxDB", + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 7, + "w": 24, + "x": 0, + "y": 0 + }, + "id": 4, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "7.3.0", + "targets": [ + { + "column": "value", + "function": "mean", + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "kubernetes_pod_container", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "restarts_total" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "container_name", + "operator": "=", + "value": "grafana" + } + ], + "target": "randomWalk('random walk')" + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Restart Total", + "type": "stat" + } + ], + "schemaVersion": 26, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": { + "collapse": false, + "enable": true, + "now": true, + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ], + "status": "Stable", + "time_options": [ + "5m", + "15m", + "1h", + "6h", + "12h", + "24h", + "2d", + "7d", + "30d" + ], + "type": "timepicker" + }, + "timezone": "browser", + "title": "Grafana", + "uid": "la4GYkhGz", + "version": 1 +} \ No newline at end of file diff --git a/srcs/grafana/dashboards/home.json b/srcs/grafana/dashboards/home.json new file mode 100644 index 0000000..e566b5b --- /dev/null +++ b/srcs/grafana/dashboards/home.json @@ -0,0 +1,401 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 11, + "links": [], + "panels": [ + { + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "rothz" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 0, + "y": 0 + }, + "id": 3, + "links": [], + "options": { + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "7.3.0", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "cpu", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "usage_system" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [] + } + ], + "title": "CPU", + "type": "gauge" + }, + { + "aliasColors": {}, + "bars": false, + "dashLength": 10, + "dashes": false, + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "decbytes" + }, + "overrides": [] + }, + "fill": 1, + "fillGradient": 0, + "gridPos": { + "h": 12, + "w": 14, + "x": 4, + "y": 0 + }, + "hiddenSeries": false, + "id": 6, + "legend": { + "avg": false, + "current": false, + "max": false, + "min": false, + "show": true, + "total": false, + "values": false + }, + "lines": true, + "linewidth": 1, + "links": [], + "nullPointMode": "null", + "options": { + "alertThreshold": true + }, + "percentage": false, + "pluginVersion": "7.3.0", + "pointradius": 2, + "points": false, + "renderer": "flot", + "seriesOverrides": [], + "spaceLength": 10, + "stack": false, + "steppedLine": false, + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "kubernetes_deployment", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "replicas_available" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [] + } + ], + "thresholds": [], + "timeFrom": null, + "timeRegions": [], + "timeShift": null, + "title": "Deployment_availability", + "tooltip": { + "shared": true, + "sort": 0, + "value_type": "individual" + }, + "type": "graph", + "xaxis": { + "buckets": null, + "mode": "time", + "name": null, + "show": true, + "values": [] + }, + "yaxes": [ + { + "$$hashKey": "object:282", + "format": "decbytes", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + }, + { + "$$hashKey": "object:283", + "format": "short", + "label": null, + "logBase": 1, + "max": null, + "min": null, + "show": true + } + ], + "yaxis": { + "align": false, + "alignLevel": null + } + }, + { + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {} + }, + "overrides": [] + }, + "folderId": 0, + "gridPos": { + "h": 12, + "w": 6, + "x": 18, + "y": 0 + }, + "headings": true, + "id": 4, + "limit": 30, + "links": [], + "query": "", + "recent": true, + "search": false, + "starred": true, + "tags": [], + "title": "Dashboards", + "type": "dashlist" + }, + { + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + }, + "unit": "percent" + }, + "overrides": [] + }, + "gridPos": { + "h": 6, + "w": 4, + "x": 0, + "y": 6 + }, + "id": 5, + "links": [], + "options": { + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "showThresholdLabels": false, + "showThresholdMarkers": true + }, + "pluginVersion": "7.3.0", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "cpu", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "usage_user" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [] + } + ], + "title": "Disk Used", + "type": "gauge" + } + ], + "schemaVersion": 26, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": { + "hidden": true, + "refresh_intervals": [ + "5s", + "10s", + "30s", + "1m", + "5m", + "15m", + "30m", + "1h", + "2h", + "1d" + ], + "time_options": [ + "5m", + "15m", + "1h", + "6h", + "12h", + "24h", + "2d", + "7d", + "30d" + ], + "type": "timepicker" + }, + "timezone": "browser", + "title": "Home Copy", + "uid": "PTOS3k2Gz", + "version": 1 +} \ No newline at end of file diff --git a/srcs/grafana/dashboards/influxdb.json b/srcs/grafana/dashboards/influxdb.json new file mode 100644 index 0000000..782746a --- /dev/null +++ b/srcs/grafana/dashboards/influxdb.json @@ -0,0 +1,130 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 10, + "links": [], + "panels": [ + { + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "7.3.0", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "kubernetes_pod_container", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "restarts_total" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "container_name", + "operator": "=", + "value": "influxdb" + } + ] + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Restarts Total", + "type": "stat" + } + ], + "schemaVersion": 26, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "InfluxDB", + "uid": "BH3J0k2Gz", + "version": 1 +} \ No newline at end of file diff --git a/srcs/grafana/dashboards/mysql.json b/srcs/grafana/dashboards/mysql.json new file mode 100644 index 0000000..8d3fd9a --- /dev/null +++ b/srcs/grafana/dashboards/mysql.json @@ -0,0 +1,130 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 8, + "links": [], + "panels": [ + { + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "7.3.0", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "kubernetes_pod_container", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "restarts_total" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "container_name", + "operator": "=", + "value": "mysql" + } + ] + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Restarts Total", + "type": "stat" + } + ], + "schemaVersion": 26, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "MySql", + "uid": "UuU7Az2Gk", + "version": 1 +} \ No newline at end of file diff --git a/srcs/grafana/dashboards/nginx.json b/srcs/grafana/dashboards/nginx.json new file mode 100644 index 0000000..2d98604 --- /dev/null +++ b/srcs/grafana/dashboards/nginx.json @@ -0,0 +1,130 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 6, + "links": [], + "panels": [ + { + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "7.3.0", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "kubernetes_pod_container", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "restarts_total" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "container_name", + "operator": "=", + "value": "nginx" + } + ] + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Restart Total", + "type": "stat" + } + ], + "schemaVersion": 26, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Nginx", + "uid": "XI0QozhMk", + "version": 1 +} \ No newline at end of file diff --git a/srcs/grafana/dashboards/phpmyadmin.json b/srcs/grafana/dashboards/phpmyadmin.json new file mode 100644 index 0000000..66cadc3 --- /dev/null +++ b/srcs/grafana/dashboards/phpmyadmin.json @@ -0,0 +1,130 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 9, + "links": [], + "panels": [ + { + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "7.3.0", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "kubernetes_pod_container", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "restarts_total" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "container_name", + "operator": "=", + "value": "phpmyadmin" + } + ] + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Restarts Total", + "type": "stat" + } + ], + "schemaVersion": 26, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "phpmyadmin", + "uid": "Jk7h0z2Mk", + "version": 1 +} \ No newline at end of file diff --git a/srcs/grafana/dashboards/wordpress.json b/srcs/grafana/dashboards/wordpress.json new file mode 100644 index 0000000..c7244ff --- /dev/null +++ b/srcs/grafana/dashboards/wordpress.json @@ -0,0 +1,130 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": "-- Grafana --", + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "gnetId": null, + "graphTooltip": 0, + "id": 7, + "links": [], + "panels": [ + { + "datasource": null, + "fieldConfig": { + "defaults": { + "custom": {}, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 9, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "area", + "justifyMode": "auto", + "orientation": "auto", + "reduceOptions": { + "calcs": [ + "mean" + ], + "fields": "", + "values": false + }, + "textMode": "auto" + }, + "pluginVersion": "7.3.0", + "targets": [ + { + "groupBy": [ + { + "params": [ + "$__interval" + ], + "type": "time" + }, + { + "params": [ + "null" + ], + "type": "fill" + } + ], + "measurement": "kubernetes_pod_container", + "orderByTime": "ASC", + "policy": "default", + "refId": "A", + "resultFormat": "time_series", + "select": [ + [ + { + "params": [ + "restarts_total" + ], + "type": "field" + }, + { + "params": [], + "type": "mean" + } + ] + ], + "tags": [ + { + "key": "container_name", + "operator": "=", + "value": "wordpress" + } + ] + } + ], + "timeFrom": null, + "timeShift": null, + "title": "Restart Total", + "type": "stat" + } + ], + "schemaVersion": 26, + "style": "dark", + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "", + "title": "Wordpress", + "uid": "0sPeTzhMz", + "version": 1 +} \ No newline at end of file diff --git a/srcs/grafana/grafana.yaml b/srcs/grafana/grafana.yaml new file mode 100644 index 0000000..3c69e9d --- /dev/null +++ b/srcs/grafana/grafana.yaml @@ -0,0 +1,101 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: grafana + labels: + app: grafana +spec: + selector: + matchLabels: + app: grafana + strategy: + type: Recreate + template: + metadata: + labels: + app: grafana + spec: + containers: + - name: grafana + image: grafana-img + imagePullPolicy: Never + volumeMounts: + - name: grafana-config + mountPath: /usr/share/grafana/conf/custom.ini + subPath: custom.ini + - name: provisioning + mountPath: /usr/share/grafana/conf/provisioning + volumes: + - name: grafana-config + configMap: + name: grafana-config + items: + - key: custom.ini + path: custom.ini + - name: provisioning + configMap: + name: grafana-config + items: + - key: dashboards.yml + path: dashboards/dashboards.yml + - key: datasources.yml + path: datasources/datasources.yml +--- +apiVersion: v1 +kind: Service +metadata: + name: grafana + labels: + app: grafana + annotations: + metallb.universe.tf/allow-shared-ip: shared +spec: + type: LoadBalancer + selector: + app: grafana + ports: + - port: 3000 + targetPort: 3000 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: grafana-config +data: + custom.ini: | + [server] + root_url = %(protocol)s://%(domain)s/ + [auth.proxy] + enabled = true + header_name = X-WEBAUTH-USER + header_property = username + auto_sign_up = true + sync_ttl = 60 + whitelist = + headers = + enable_login_token = false + datasources.yml: | + apiVersion: 1 + datasources: + - name: InfluxDB + type: influxdb + access: proxy + database: telegraf + isDefault: true + user: root + password: password + url: http://influxdb:8086 + dashboards.yml: | + apiVersion: 1 + providers: + - name: 'influxdb' + orgId: 1 + folder: '' + folderUid: '' + type: file + disableDeletion: false + editable: true + updateIntervalSeconds: 10 + allowUiUpdates: true + options: + path: /usr/share/grafana/public/dashboards diff --git a/srcs/influxdb/Dockerfile b/srcs/influxdb/Dockerfile new file mode 100644 index 0000000..9fa719d --- /dev/null +++ b/srcs/influxdb/Dockerfile @@ -0,0 +1,16 @@ +FROM alpine:3.12 + +RUN apk update +RUN apk add influxdb curl jq libc6-compat +# RUN apk add telegraf --repository http://dl-cdn.alpinelinux.org/alpine/edge/testing/ +RUN curl -LO https://dl.influxdata.com/telegraf/releases/telegraf-1.16.1_linux_amd64.tar.gz && \ + tar xf telegraf-1.16.1_linux_amd64.tar.gz --strip 2 + +COPY setup.sh /tmp/ +RUN rm -f /etc/telegraf/telegraf.conf +COPY ./telegraf.conf /etc/telegraf/ +RUN chmod +x /tmp/setup.sh + +EXPOSE 8086 +ENTRYPOINT ["/tmp/setup.sh"] +# ENTRYPOINT ["tail", "-f", "/dev/null"] diff --git a/srcs/influxdb/influxdb.yaml b/srcs/influxdb/influxdb.yaml new file mode 100644 index 0000000..168de89 --- /dev/null +++ b/srcs/influxdb/influxdb.yaml @@ -0,0 +1,114 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: influxdb + labels: + app: influxdb +spec: + strategy: + type: Recreate + selector: + matchLabels: + app: influxdb + template: + metadata: + labels: + app: influxdb + spec: + serviceAccountName: telegraf + containers: + - name: influxdb + image: influxdb-img + imagePullPolicy: Never + volumeMounts: + - name: influxdb-config + mountPath: /etc/influxdb.conf + subPath: influxdb.conf + - name: telegraf-config + mountPath: /etc/telegraf/telegraf.d/ + - name: influxdb-persistent-storage + mountPath: /influxdata + volumes: + - name: influxdb-config + configMap: + name: influxdb-config + - name: telegraf-config + configMap: + name: telegraf-config + - name: influxdb-persistent-storage + persistentVolumeClaim: + claimName: influxdb-pv-claim +--- +apiVersion: v1 +kind: Service +metadata: + name: influxdb + labels: + app: influxdb +spec: + type: ClusterIP + selector: + app: influxdb + ports: + - port: 8086 + targetPort: 8086 +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: influxdb-config + namespace: default +data: + influxdb.conf: | + [meta] + dir = "/influxdata/meta" + [data] + dir = "/influxdata/data" + wal-dir = "/influxdata/wal" + [http] + enabled = true +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: telegraf-config + namespace: default +data: + kube_inventory.conf: | + [[inputs.kube_inventory]] + url = "https://kubernetes" + namespace = "default" + insecure_skip_verify = true +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: influxdb-pv-claim + labels: + app: influxdb +spec: + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: telegraf +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +subjects: +- kind: ServiceAccount + name: telegraf + namespace: default +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: telegraf + labels: + app: influxdb \ No newline at end of file diff --git a/srcs/influxdb/setup.sh b/srcs/influxdb/setup.sh new file mode 100644 index 0000000..61b42e6 --- /dev/null +++ b/srcs/influxdb/setup.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +influxd & +telegraf --config /etc/telegraf/telegraf.conf --config-directory /etc/telegraf/telegraf.d \ No newline at end of file diff --git a/srcs/influxdb/telegraf.conf b/srcs/influxdb/telegraf.conf new file mode 100644 index 0000000..a164d29 --- /dev/null +++ b/srcs/influxdb/telegraf.conf @@ -0,0 +1,22 @@ +[agent] + interval = "10s" + round_interval = true + metric_batch_size = 1000 + metric_buffer_limit = 1000 + collection_jitter = "0s" + flush_jitter = "0s" + hostname = "" + omit_hostname = false + +# OUTPUTS +[[outputs.influxdb]] + urls = ["http://127.0.0.1:8086"] + database = "telegraf" + precision = "s" + +# INPUTS +[[inputs.cpu]] + percpu = true + totalcpu = false + # filter all fields beginning with 'time_' + fielddrop = ["time_*"] \ No newline at end of file diff --git a/srcs/metallb-config.yaml b/srcs/metallb-config.yaml new file mode 100644 index 0000000..df3d049 --- /dev/null +++ b/srcs/metallb-config.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: metallb-system + name: config +data: + config: | + address-pools: + - name: default + protocol: layer2 + addresses: + - 192.168.49.3-192.168.49.254 diff --git a/srcs/mysql/Dockerfile b/srcs/mysql/Dockerfile new file mode 100644 index 0000000..153af6c --- /dev/null +++ b/srcs/mysql/Dockerfile @@ -0,0 +1,15 @@ +FROM alpine:3.12 + +LABEL maintainer="fcoelho " \ + version="1.0.0" + +RUN apk update && \ + apk add mysql && \ + mkdir /run/mysqld + +COPY config.sql . +COPY start.sh . + +EXPOSE 3306 + +ENTRYPOINT ["sh", "start.sh"] \ No newline at end of file diff --git a/srcs/mysql/config.sql b/srcs/mysql/config.sql new file mode 100644 index 0000000..7a4bd26 --- /dev/null +++ b/srcs/mysql/config.sql @@ -0,0 +1,7 @@ +DELETE FROM mysql.user WHERE User=''; +DELETE FROM mysql.user WHERE User='root' AND HOST NOT IN ('localhost', '127.0.0.1', '::1'); +DROP DATABASE IF EXISTS test; +DELETE FROM mysql.db WHERE Db='test' or Db='test\\_%'; +CREATE DATABASE wordpress; +GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%' IDENTIFIED BY 'admin'; +GRANT ALL PRIVILEGES ON *.* TO 'admin'@'%' IDENTIFIED BY 'admin'; \ No newline at end of file diff --git a/srcs/mysql/mysql.yaml b/srcs/mysql/mysql.yaml new file mode 100644 index 0000000..05368dc --- /dev/null +++ b/srcs/mysql/mysql.yaml @@ -0,0 +1,84 @@ +apiVersion: v1 +kind: PersistentVolume +metadata: + name: mysql-pv-volume + labels: + type: local +spec: + storageClassName: manual + capacity: + storage: 1Gi + accessModes: + - ReadWriteOnce + hostPath: + path: "/mnt/mysql" +--- +apiVersion: v1 +kind: PersistentVolumeClaim +metadata: + name: mysql-pv-claim +spec: + storageClassName: manual + accessModes: + - ReadWriteOnce + resources: + requests: + storage: 1Gi +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: mysql +spec: + replicas: 1 + selector: + matchLabels: + app: mysql + template: + metadata: + name: mysql + labels: + app: mysql + spec: + securityContext: + fsGroup: 101 + containers: + - name: mysql + image: mysql-img + imagePullPolicy: Never + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-secret + key: password + ports: + - name: http + containerPort: 3306 + volumeMounts: + - name: mysql-data + mountPath: /var/lib/mysql + volumes: + - name: mysql-data + persistentVolumeClaim: + claimName: mysql-pv-claim +--- +apiVersion: v1 +kind: Service +metadata: + name: mysql +spec: + ports: + - port: 3306 + targetPort: http + selector: + app: mysql + type: ClusterIP +--- + apiVersion: v1 + kind: Secret + metadata: + name: mysql-secret + type: Opaque + stringData: + password: admin \ No newline at end of file diff --git a/srcs/mysql/start.sh b/srcs/mysql/start.sh new file mode 100644 index 0000000..e525987 --- /dev/null +++ b/srcs/mysql/start.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +mysql_install_db --user=root --basedir=/usr --datadir=/var/lib/mysql +mysqld --user=root --skip_networking=0 --init-file=/config.sql \ No newline at end of file diff --git a/srcs/nginx/Dockerfile b/srcs/nginx/Dockerfile new file mode 100644 index 0000000..438cee8 --- /dev/null +++ b/srcs/nginx/Dockerfile @@ -0,0 +1,28 @@ +FROM alpine:3.12 + +LABEL maintainer="fcoelho " \ + version="1.0.0" + +RUN apk update && \ + apk add nginx && \ + mkdir -p /var/run/nginx && \ + apk add openssl openssh && \ + rm -rf /var/cache/apk/* + +RUN mkdir /www +COPY ./index.html /www + +RUN mkdir -p /etc/nginx/ssl && \ + openssl req -newkey rsa:2048 -x509 -days 365 -nodes -keyout /etc/nginx/ssl/services.key -out /etc/nginx/ssl/services.pem -subj "/C=BR/ST=Sao Paulo/L=Sao Paulo/O=42SP, Inc./OU=IT/CN=ft_services" + +RUN /usr/bin/ssh-keygen -A +COPY sshd_config /etc/ssh/ + +RUN rm /etc/nginx/conf.d/default.conf +COPY ./nginx.conf /etc/nginx/conf.d/default.conf + +COPY ./setup.sh . +RUN chmod +x ./setup.sh + +EXPOSE 80 443 22 +CMD ./setup.sh \ No newline at end of file diff --git a/srcs/nginx/index.html b/srcs/nginx/index.html new file mode 100644 index 0000000..67b342f --- /dev/null +++ b/srcs/nginx/index.html @@ -0,0 +1,20 @@ + + + +Nginx servers + + + +

Servicos Disponiveis

+ + + \ No newline at end of file diff --git a/srcs/nginx/nginx.conf b/srcs/nginx/nginx.conf new file mode 100644 index 0000000..ba236a8 --- /dev/null +++ b/srcs/nginx/nginx.conf @@ -0,0 +1,37 @@ +server { + listen 80 default_server; + listen [::]:80 default_server; + return 301 https://$host$request_uri; +} + +upstream backend { + server phpmyadmin:5000; +} + +server { + listen 443 ssl ; + listen [::]:443 ssl ; + ssl_certificate /etc/nginx/ssl/services.pem; + ssl_certificate_key /etc/nginx/ssl/services.key; + + root /www; + index index.html; + server_name _; + + location / { + try_files $uri $uri/ =404; + } + + location /wordpress/ { + return 307 http://$host:5050/; + } + location /phpmyadmin/ { + proxy_pass http://phpmyadmin:5000/; + proxy_redirect off; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Host $server_name; + proxy_set_header X-Forwarded-Proto https; + } +} diff --git a/srcs/nginx/nginx.yaml b/srcs/nginx/nginx.yaml new file mode 100644 index 0000000..5216bfa --- /dev/null +++ b/srcs/nginx/nginx.yaml @@ -0,0 +1,60 @@ +apiVersion: v1 +kind: Service +metadata: + name: nginx + labels: + app: nginx-app + annotations: + metallb.universe.tf/allow-shared-ip: shared +spec: + type: LoadBalancer + ports: + - name: http + port: 80 + targetPort: 80 + protocol: TCP + - name: https + port: 443 + targetPort: 443 + protocol: TCP + - name: ssh + port: 22 + targetPort: 22 + protocol: TCP + selector: + app: nginx-app +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginx-deployment + labels: + app: nginx-app +spec: + replicas: 1 + strategy: + type: Recreate + selector: + matchLabels: + app: nginx-app + template: + metadata: + labels: + app: nginx-app + spec: + containers: + - name: nginx + image: nginx-img + ports: + - containerPort: 80 + name: http + - containerPort: 443 + name: https + - containerPort: 22 + name: ssh + imagePullPolicy: Never + env: + - name: SSH_USER + value: admin + - name: SSH_PASSWORD + value: admim \ No newline at end of file diff --git a/srcs/nginx/setup.sh b/srcs/nginx/setup.sh new file mode 100644 index 0000000..08a5092 --- /dev/null +++ b/srcs/nginx/setup.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +adduser --disabled-password ${SSH_USERNAME} +adduser -D "$SSH_USER" +echo "$SSH_USER:$SSH_PASSWORD" | chpasswd + +/usr/sbin/sshd +/usr/sbin/nginx -g 'daemon off;' \ No newline at end of file diff --git a/srcs/nginx/sshd_config b/srcs/nginx/sshd_config new file mode 100644 index 0000000..b3f9e96 --- /dev/null +++ b/srcs/nginx/sshd_config @@ -0,0 +1,7 @@ + +Port 22 +HostKey /etc/ssh/ssh_host_rsa_key +PermitRootLogin yes +PasswordAuthentication yes +PermitEmptyPasswords yes +Subsystem sftp /usr/lib/ssh/sftp-server \ No newline at end of file diff --git a/srcs/phpmyadmin/Dockerfile b/srcs/phpmyadmin/Dockerfile new file mode 100644 index 0000000..81254fd --- /dev/null +++ b/srcs/phpmyadmin/Dockerfile @@ -0,0 +1,26 @@ +FROM alpine:3.12 + +LABEL maintainer="fcoelho " \ + version="1.0.0" + +RUN apk update && \ + apk add curl nginx lighttpd php7-common php7-iconv php7-json php7-gd php7-curl php7-xml \ + php7-mysqli php7-imap php7-cgi fcgi php7-pdo php7-pdo_mysql php7-soap php7-xmlrpc \ + php7-posix php7-mcrypt php7-mbstring php7-gettext php7-ldap php7-ctype php7-dom php7-session wget && \ + mkdir /var/run/lighttpd && \ + chown -R lighttpd:lighttpd /var/run/lighttpd && \ + wget --quiet https://files.phpmyadmin.net/phpMyAdmin/4.9.5/phpMyAdmin-4.9.5-english.tar.gz && \ + tar -xf phpMyAdmin-4.9.5-english.tar.gz -C /var/www/localhost/ && \ + rm -rf phpMyAdmin-4.9.5-english.tar.gz && \ + chown -R lighttpd /var/www/localhost/phpMyAdmin-4.9.5-english + +COPY ./config.inc.php /var/www/localhost/phpMyAdmin-4.9.5-english/ + +WORKDIR /etc/lighttpd + +COPY ./lighttpd.conf . +COPY ./mod_fastcgi.conf . + +EXPOSE 5000 80 + +ENTRYPOINT ["lighttpd","-D", "-f", "lighttpd.conf"] \ No newline at end of file diff --git a/srcs/phpmyadmin/config.inc.php b/srcs/phpmyadmin/config.inc.php new file mode 100644 index 0000000..fcbeae5 --- /dev/null +++ b/srcs/phpmyadmin/config.inc.php @@ -0,0 +1,7 @@ + ( + "localhost" => ( + "socket" => "/run/lighttpd/lighttpd-fastcgi-php-" + PID + ".socket", + "bin-path" => "/usr/bin/php-cgi7" + ) + ) +) \ No newline at end of file diff --git a/srcs/phpmyadmin/phpmyadmin.yaml b/srcs/phpmyadmin/phpmyadmin.yaml new file mode 100644 index 0000000..7fc4b5a --- /dev/null +++ b/srcs/phpmyadmin/phpmyadmin.yaml @@ -0,0 +1,62 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: phpmyadmin +spec: + replicas: 1 + selector: + matchLabels: + app: phpmyadmin + template: + metadata: + name: phpmyadmin + labels: + app: phpmyadmin + spec: + containers: + - name: phpmyadmin + image: phpmyadmin-img + imagePullPolicy: Never + ports: + - containerPort: 5000 + volumeMounts: + - name: default-conf + mountPath: /etc/nginx/conf.d + volumes: + - name: default-conf + configMap: + name: phpmyadmin-config + items: + - key: default.conf + path: default.conf +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + metallb.universe.tf/allow-shared-ip: shared + name: phpmyadmin +spec: + ports: + - name: http + protocol: TCP + port: 5000 + targetPort: 5000 + selector: + app: phpmyadmin + type: LoadBalancer +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: phpmyadmin-config +data: + default.conf: | + server { + listen 80; + listen [::]:80; + server_name _; + root /var/www/phpmyadmin; + index index.php index.html; + try_files $uri $uri/ =404; + } \ No newline at end of file diff --git a/srcs/reset.sh b/srcs/reset.sh new file mode 100644 index 0000000..73854a3 --- /dev/null +++ b/srcs/reset.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# kubectl delete -f ./srcs/wordpress/wordpress.yaml +# eval $(minikube docker-env) +# docker build srcs/wordpress -t wordpress-img +# kubectl apply -f ./srcs/wordpress/wordpress.yaml + +# kubectl delete -f ./srcs/phpmyadmin/phpmyadmin.yaml +# eval $(minikube docker-env) +# docker build srcs/phpmyadmin -t phpmyadmin-img +# kubectl apply -f ./srcs/phpmyadmin/phpmyadmin.yaml + +# kubectl delete -f ./srcs/ftps/ftps.yaml +# eval $(minikube docker-env) +# docker build srcs/ftps -t ftps-img +# kubectl apply -f ./srcs/ftps/ftps.yaml + +# kubectl delete -f ./srcs/grafana/grafana.yaml +# kubectl delete -f ./srcs/influxdb/influxdb.yaml +# eval $(minikube docker-env) +# docker build srcs/grafana -t grafana-img +# docker build srcs/influxdb -t influxdb-img +# kubectl apply -f ./srcs/grafana/grafana.yaml +# kubectl apply -f ./srcs/influxdb/influxdb.yaml \ No newline at end of file diff --git a/srcs/update.sh b/srcs/update.sh new file mode 100644 index 0000000..99c3969 --- /dev/null +++ b/srcs/update.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +#Setup to be done, Before runing setup.sh with VM Virtua-box +# +# Firsto of all, Set Docker to run Without Sudo. +# - sudo groupadd docker +# - sudo gpasswd -a $USER docker +# - sudo service docker restart or sudo service docker.io restart +# - Also, restart the VM t set PATH correctly. + +# After that, make sure that your VM has the following configurations: +# - 2 or More CPUS core; +# - System Acceleration VT-x/AMD-V enabled; +# - Nested virtualization enabled - Optional; +# - Internet Connection; +# - Minikube version: 1.14.2; +# - Optional: Filezilla to test FTP. + +curl -LO https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 +sudo install minikube-linux-amd64 /usr/local/bin/minikube +rm -f ./minikube-linux-amd64 +sudo apt-get install filezilla \ No newline at end of file diff --git a/srcs/wordpress/Dockerfile b/srcs/wordpress/Dockerfile new file mode 100644 index 0000000..26c33ca --- /dev/null +++ b/srcs/wordpress/Dockerfile @@ -0,0 +1,28 @@ +FROM alpine:3.12 + +LABEL maintainer="fcoelho " \ + version="1.0.0" + +RUN apk update && \ + apk add curl nginx lighttpd php7-common php7-iconv php7-json \ + php7-gd php7-curl php7-xml php7-mysqli php7-imap \ + php7-cgi fcgi php7-pdo php7-pdo_mysql php7-soap \ + php7-xmlrpc php7-posix php7-mcrypt php7-gettext \ + php7-ldap php7-ctype php7-dom mysql-client wget && \ + mkdir /var/run/lighttpd && \ + chown -R lighttpd:lighttpd /var/run/lighttpd && \ + wget https://wordpress.org/wordpress-5.4.2.tar.gz && \ + tar -xf wordpress-5.4.2.tar.gz -C /var/www/localhost/ && \ + rm -rf wordpress-5.4.2.tar.gz && \ + chown -R lighttpd /var/www/localhost/wordpress + +COPY wp-config.php /var/www/localhost/wordpress + +WORKDIR /etc/lighttpd + +COPY lighttpd.conf ./ +COPY mod_fastcgi.conf ./ + +EXPOSE 5050 80 + +ENTRYPOINT ["lighttpd", "-D", "-f", "lighttpd.conf"] \ No newline at end of file diff --git a/srcs/wordpress/lighttpd.conf b/srcs/wordpress/lighttpd.conf new file mode 100644 index 0000000..9db93a9 --- /dev/null +++ b/srcs/wordpress/lighttpd.conf @@ -0,0 +1,19 @@ +server.modules = ( + "mod_access", + "mod_accesslog" +) + +include "mime-types.conf" +include "mod_fastcgi.conf" + +server.username = "lighttpd" +server.groupname = "lighttpd" +server.document-root = "/var/www/localhost/wordpress" +server.pid-file = "/run/lighttpd.pid" +server.errorlog = "/var/log/lighttpd/error.log" +server.indexfiles = ("index.php", "index.html", "index.htm", "default.htm") +server.follow-symlink = "enable" +server.port = 5050 +static-file.exclude-extensions = (".php", ".pl", ".cgi", ".fcgi") +accesslog.filename = "/var/log/lighttpd/access.log" +url.access-deny = ("~", ".inc") \ No newline at end of file diff --git a/srcs/wordpress/mod_fastcgi.conf b/srcs/wordpress/mod_fastcgi.conf new file mode 100644 index 0000000..df12d56 --- /dev/null +++ b/srcs/wordpress/mod_fastcgi.conf @@ -0,0 +1,9 @@ +server.modules += ( "mod_fastcgi" ) +fastcgi.server = ( + ".php" => ( + "localhost" => ( + "socket" => "/run/lighttpd/lighttpd-fastcgi-php-" + PID + ".socket", + "bin-path" => "/usr/bin/php-cgi7" + ) + ) +) \ No newline at end of file diff --git a/srcs/wordpress/wordpress.yaml b/srcs/wordpress/wordpress.yaml new file mode 100644 index 0000000..219497c --- /dev/null +++ b/srcs/wordpress/wordpress.yaml @@ -0,0 +1,90 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: wordpress +spec: + replicas: 1 + selector: + matchLabels: + app: wordpress + strategy: + type: Recreate + template: + metadata: + labels: + app: wordpress + spec: + containers: + - name: wordpress + image: wordpress-img + imagePullPolicy: Never + ports: + - containerPort: 5050 + env: + - name: MYSQL_ROOT_PASSWORD + valueFrom: + secretKeyRef: + name: mysql-secret + key: password + - name: USERNAME + valueFrom: + secretKeyRef: + name: wordpress-secret + key: username + - name: PASSWORD + valueFrom: + secretKeyRef: + name: wordpress-secret + key: password + volumeMounts: + - name: wp-nginx-conf + mountPath: /etc/nginx/conf.d/ + volumes: + - name: wp-nginx-conf + configMap: + name: wordpress-config + items: + - key: default.conf + path: default.conf + +--- +apiVersion: v1 +kind: Service +metadata: + annotations: + metallb.universe.tf/allow-shared-ip: shared + name: wordpress +spec: + ports: + - name: http + protocol: TCP + port: 5050 + targetPort: 5050 + selector: + app: wordpress + type: LoadBalancer + +--- +apiVersion: v1 +kind: Secret +metadata: + name: wordpress-secret +stringData: + username: admin + password: admin + +--- +apiVersion: v1 +kind: ConfigMap +metadata: + name: wordpress-config +data: + default.conf: | + server { + server_name _; + root /var/www/wordpress; + index index.php + location / { + try_files $uri $uri/ =404; + } + } \ No newline at end of file diff --git a/srcs/wordpress/wp-config.php b/srcs/wordpress/wp-config.php new file mode 100644 index 0000000..58c3e34 --- /dev/null +++ b/srcs/wordpress/wp-config.php @@ -0,0 +1,24 @@ +S+O-mbZ#IW-:p;bWY95 3nTu|d=Y3/db>n=r}2I59s|*-[l'); + define('SECURE_AUTH_KEY', 'l]Et Sz|L7yPzBHq2T%Uq3IcWPp08;GN:l2>lsOCUXd~tJKIB$~?6/^$*M-U~7_<'); + define('LOGGED_IN_KEY', 'fT2[ATB0b/$}2Mnts73-V=iN-e-*FpFB%P-||a/9|=CF>UhZ(kdtJzKaQCPfW|sw'); + define('NONCE_KEY', 'cbj+^)Yq&_ 8vP`Bhf7pgYDB7}l*L(}^*$RdwTFiRK4^[@Yh@|a|uu0LGUu)>ne2'); + define('AUTH_SALT', '6~f~6++*XDe|`elvncg3,{vYN*9Dd%k+b:8HGOe+rv6ul/3yn{Et {z^XVJr8(ti[fii9*cjPJ|b4{TSuGwCk%K~nQ@qNbo3y-f|cp$ay~2M+qrJN-_n#-!7( +IW!j<'); + + $table_prefix = 'wp_'; + + define( 'WP_DEBUG', false ); + if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', __DIR__ . '/' ); + } + require_once ABSPATH . 'wp-settings.php'; \ No newline at end of file