add kuber

This commit is contained in:
Matthos Denys 2021-03-02 16:18:28 +03:00
commit ccb971cf5f
24 changed files with 2283 additions and 0 deletions

8
deletesh.sh Executable file
View File

@ -0,0 +1,8 @@
#!/bin/bash
kubectl delete svc nginx-service
kubectl delete svc mysql-service
kubectl delete svc phpmyadmin-service
kubectl delete deployment nginx-deployment
kubectl delete deployment mysql-deployment
kubectl delete deployment phpmyadmin-deployment
kubectl delete pods --all

12
loadbalancer.yaml Executable file
View File

@ -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.99.100-192.168.99.200

12
metallb_configmap.yml Executable file
View File

@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: config
namespace: metallb-system
data:
config: |
address-pools:
- name: default
protocol: layer2
addresses:
- 192.168.99.100-192.168.99.200

48
mysql.yaml Executable file
View File

@ -0,0 +1,48 @@
apiVersion: v1
kind: Service
metadata:
name: mysql-service
labels:
app: mysql
spec:
type: ClusterIP
ports:
- port: 3306
targetPort: 3306
protocol: TCP
name: mysql
selector:
app: mysql
clusterIP: None
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mysql-deployment
spec:
selector:
matchLabels:
app: mysql-deployment
template:
metadata:
labels:
app: mysql-deployment
spec:
containers:
- name: mysql-deployment
imagePullPolicy: Never
image: mysqlserver
resources:
limits:
memory: "128Mi"
cpu: "500m"
ports:
- containerPort: 3306
name: mysql
volumeMounts:
- name: mysql-storage
mountPath: /var/lib/mysql
volumes:
- name: mysql-storage
persistentVolumeClaim:
claimName: mysql-volume

9
mysql/Dockerfile Executable file
View File

@ -0,0 +1,9 @@
FROM alpine:3.12
RUN echo "root:root" | chpasswd
RUN apk update
RUN apk add mariadb mariadb-common mariadb-client
COPY my.cnf /etc/my.cnf
EXPOSE 3306
COPY start.sh /start.sh
RUN chmod +x /start.sh
CMD ["/start.sh"]

6
mysql/my.cnf Executable file
View File

@ -0,0 +1,6 @@
[mysqld]
user = root
datadir = /var/lib/mysql
port = 3306
bind-address = 0.0.0.0
skip-networking = false

47
mysql/start.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/sh
if [ ! -d "/run/mysqld" ]; then
mkdir -p /run/mysqld
# chown -R mysql:mysql /run/mysqld
fi
if [ -d /var/lib/mysql/mysql ]; then
echo '[i] MySQL directory already present, skipping creation'
else
echo "[i] MySQL data directory not found, creating initial DBs"
# chown -R mysql:mysql /var/lib/mysql
# init database
echo 'Initializing database'
mysql_install_db --user=mysql > /dev/null
echo 'Database initialized'
echo "[i] MySql root password: root"
# create temp file
tfile=`mktemp`
if [ ! -f "$tfile" ]; then
return 1
fi
# save sql
echo "[i] Create temp file: $tfile"
cat << EOF > $tfile
CREATE DATABASE wordpress;
CREATE USER 'pma'@'%' IDENTIFIED BY 'pma'; GRANT ALL PRIVILEGES ON *.* TO 'pma'@'%' WITH GRANT OPTION; USE wordpress; FLUSH PRIVILEGES;
EOF
echo 'FLUSH PRIVILEGES;' >> $tfile
# run sql in tempfile
echo "[i] run tempfile: $tfile"
/usr/bin/mysqld --user=mysql --bootstrap --verbose=0 < $tfile
rm -f $tfile
fi
echo "[i] Sleeping 5 sec"
sleep 5
echo '[i] start running mysqld'
exec /usr/bin/mysqld_safe

4
mysql/supervisord.conf Executable file
View File

@ -0,0 +1,4 @@
[supervisord]
nodaemon=true
[program:mysql]
command= rc-service mariadb start && kill -s SIGTERM $(cat supervisord.pid)

714
mysql/wordpress.sql Executable file

File diff suppressed because one or more lines are too long

19
nginx/Dockerfile Executable file
View File

@ -0,0 +1,19 @@
FROM alpine:3.12
ENV TZ Europe/Moscow
LABEL maintainer="mdenys"
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
RUN apk update && apk upgrade
RUN apk add openrc mc nano supervisor openssh nginx openssl && rm -f /var/cache/apk/*
COPY index.html nginx.conf ./
RUN mkdir -p /run/nginx www && \
mv index.html /var/www/localhost/htdocs
COPY nginx.conf /etc/nginx/nginx.conf
RUN mkdir /etc/nginx/ssl
RUN openssl req -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out /etc/nginx/ssl/html.pem -keyout /etc/nginx/ssl/html.key -subj "/C=RU/ST=Kazan/L=Kazan/O=21 School/OU=mdenys/CN=html"
COPY supervisord.conf /etc/supervisord.conf
RUN sed -i s/#PermitRootLogin.*/PermitRootLogin\ yes/ /etc/ssh/sshd_config \
&& echo "root:root" | chpasswd \
&& /usr/bin/ssh-keygen -A \
&& ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_key
EXPOSE 22 80 443
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

13
nginx/index.html Executable file
View File

@ -0,0 +1,13 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
</head>
<body>
<div class="container-sm"><h1 class="display-1">Welcome to Mdenys ft_services</h1></div>
</body>
</html>

22
nginx/nginx.conf Executable file
View File

@ -0,0 +1,22 @@
events {}
http {
server {
listen 80 default_server;
error_log logs/error.log debug;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
server_name www;
root /var/www/localhost/htdocs/;
index index.html;
ssl_certificate /etc/nginx/ssl/html.pem;
ssl_certificate_key /etc/nginx/ssl/html.key;
}
}

6
nginx/supervisord.conf Executable file
View File

@ -0,0 +1,6 @@
[supervisord]
nodaemon=true
[program:sshd]
command= sh -c "/usr/sbin/sshd -D && kill -s SIGTERM $(cat supervisord.pid)"
[program:nginx]
command=sh -c "nginx -g 'daemon off;' && kill -s SIGTERM $(cat supervisord.pid)"

52
nginx_service.yaml Executable file
View File

@ -0,0 +1,52 @@
apiVersion: v1
kind: Service
metadata:
name: nginx-service
annotations:
metallb.universe.tf/allow-shared-ip: minikube
spec:
selector:
app: nginx
ports:
- name: http
protocol: TCP
port: 80
targetPort: 80
- name: https
protocol: TCP
port: 443
targetPort: 443
- name: ssh
protocol: TCP
port: 22
targetPort: 22
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
spec:
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx_image
resources:
limits:
memory: "128Mi"
cpu: "50m"
imagePullPolicy: Never
ports:
- containerPort: 80
name: http
- containerPort: 443
name: https
- containerPort: 22
name: ssh

23
persistencevolume.yaml Executable file
View File

@ -0,0 +1,23 @@
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mysql-volume
labels:
app: mysql
spec:
resources:
requests:
storage: 2Gi
accessModes:
- ReadWriteOnce
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mypvcinflux
spec:
resources:
requests:
storage: 2Gi
accessModes:
- ReadWriteOnce

BIN
phpmyadmin/.DS_Store vendored Executable file

Binary file not shown.

14
phpmyadmin/Dockerfile Executable file
View File

@ -0,0 +1,14 @@
FROM alpine:3.12
LABEL maintainer="mdenys"
RUN apk update
RUN apk add supervisor nginx php7 php7-fpm php7-opcache php7-gd php7-mysqli php7-zlib php7-curl php7-mbstring php7-json php7-session
RUN mkdir -p /var/www/localhost/htdocs/
RUN mkdir -p /run/php7
RUN mkdir -p /run/nginx
RUN wget http://files.directadmin.com/services/all/phpMyAdmin/phpMyAdmin-5.0.1-all-languages.tar.gz
RUN tar -xvf phpMyAdmin-5.0.1-all-languages.tar.gz --strip-components 1 -C /var/www/localhost/htdocs/
COPY phpmyadmin.inc.php /var/www/localhost/htdocs/config.inc.php
COPY nginx.conf /etc/nginx/conf.d/default.conf
COPY supervisord.conf /etc/supervisord.conf
EXPOSE 5000
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisord.conf"]

14
phpmyadmin/index.html Executable file
View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
</head>
<body>
<div class="container-sm"><h1 class="display-1">phpmyadmin</h1></div>
<?php echo phpinfo();?>
</body>
</html>

13
phpmyadmin/nginx.conf Executable file
View File

@ -0,0 +1,13 @@
server {
listen 0.0.0.0:5000;
root /var/www/localhost/htdocs/;
autoindex on;
index index.php;
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_index index.php;
}
}

1173
phpmyadmin/php.ini Executable file

File diff suppressed because it is too large Load Diff

14
phpmyadmin/phpmyadmin.inc.php Executable file
View File

@ -0,0 +1,14 @@
<?php
$cfg['blowfish_secret'] = 'ZX8lwV2k,PSlDhg40E=38i7Rm1pczKVr';
$i = 0;
$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = 'mysql-service';
$cfg['Servers'][$i]['port'] = 3306;
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';
?>

38
phpmyadmin/phpsvc.yaml Executable file
View File

@ -0,0 +1,38 @@
apiVersion: v1
kind: Service
metadata:
name: phpmyadmin-service
annotations:
metallb.universe.tf/allow-shared-ip: minikube
spec:
selector:
app: phpmyadmin
ports:
- name: https
protocol: TCP
port: 5000
type: LoadBalancer
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: phpmyadmin-deployment
spec:
selector:
matchLabels:
app: phpmyadmin
template:
metadata:
labels:
app: phpmyadmin
spec:
containers:
- name: phpmyadmin
imagePullPolicy: Never
image: phpmyadmin_image
resources:
limits:
memory: "128Mi"
cpu: "50m"
ports:
- containerPort: 5000

6
phpmyadmin/supervisord.conf Executable file
View File

@ -0,0 +1,6 @@
[supervisord]
nodaemon=true
[program:php]
command= /usr/sbin/php-fpm7
[program:nginx]
command=sh -c "nginx -g 'daemon off;' && kill -s SIGTERM $(cat supervisord.pid)"

16
run.sh Executable file
View File

@ -0,0 +1,16 @@
#!/bin/bash
minikube addons enable dashboard
minikube addons enable metallb
minikube addons enable metrics-server
eval $(minikube docker-env)
kubectl apply -f metallb_configmap.yml
docker build -t nginx_image nginx
docker build -t phpmyadmin_image phpmyadmin
kubectl apply -f persistencevolume.yaml
kubectl apply -f nginx_service.yaml
docker build -t mysqlserver mysql
kubectl apply -f mysql.yaml
kubectl apply -f phpmyadmin/phpsvc.yaml
kubectl get pods
IP=$(kubectl get node -o=custom-columns='DATA:status.addresses[0].address' | sed -n 2p)
echo "Minikube IP: ${IP}"