From fa8afadf92ba3ae041130a03a2052071de482455 Mon Sep 17 00:00:00 2001 From: Csabi | BackendDev | Wanari Date: Mon, 12 Oct 2020 06:01:54 +0200 Subject: [PATCH 1/3] Extend README.md with db initialization commands --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e4df68a..7c6ac07 100644 --- a/README.md +++ b/README.md @@ -38,10 +38,12 @@ microk8s.kubectl get pv,pvc microk8s.kubectl apply -f db.yml microk8s.kubectl logs -f pod/dbapp ``` -5. Test the database connection +5. Init and test the database connection ```bash microk8s.kubectl get all -mysql -u root -p -h dbservice.ip.address golf +echo "show tables;" | mysql -u root -p -h dbservice.ip.address golf +mysql -u root -p -h dbservice.ip.address gold < database/golf.sql +echo "show tables;" | mysql -u root -p -h dbservice.ip.address golf ``` 6. Fine-tune the ```DBHOST``` environment variable with the IP of the dbservvice and deploy your web application ```bash From bc40f7edb69a38485ba6cdf6b4f552438b6d9fbb Mon Sep 17 00:00:00 2001 From: Csabi | BackendDev | Wanari Date: Mon, 12 Oct 2020 06:02:45 +0200 Subject: [PATCH 2/3] Use 5.7 version of mysql --- kubernetes/db.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kubernetes/db.yml b/kubernetes/db.yml index 326659c..70a63dc 100644 --- a/kubernetes/db.yml +++ b/kubernetes/db.yml @@ -21,7 +21,7 @@ spec: - name: mysql-db image: mysql ports: - - name: mysql + - name: mysql:5.7 containerPort: 3306 env: - name: MYSQL_ROOT_PASSWORD From 4d65dd7cb03cde561502dcba6f01e6a019bd93a3 Mon Sep 17 00:00:00 2001 From: Csabi | BackendDev | Wanari Date: Mon, 12 Oct 2020 06:20:04 +0200 Subject: [PATCH 3/3] Add haproxy --- haproxy/Dockerfile | 17 +++++++++++++++++ haproxy/docker-entrypoint.sh | 22 ++++++++++++++++++++++ haproxy/haproxy.conf.ctmpl | 22 ++++++++++++++++++++++ haproxy/rsyslog.conf | 22 ++++++++++++++++++++++ haproxy/service.json | 6 ++++++ 5 files changed, 89 insertions(+) create mode 100644 haproxy/Dockerfile create mode 100644 haproxy/docker-entrypoint.sh create mode 100644 haproxy/haproxy.conf.ctmpl create mode 100644 haproxy/rsyslog.conf create mode 100644 haproxy/service.json diff --git a/haproxy/Dockerfile b/haproxy/Dockerfile new file mode 100644 index 0000000..4b3afe3 --- /dev/null +++ b/haproxy/Dockerfile @@ -0,0 +1,17 @@ +FROM haproxy + +RUN apt-get update && apt-get install -y unzip wget rsyslog + +RUN wget https://releases.hashicorp.com/consul/1.6.1/consul_1.6.1_linux_amd64.zip && \ + unzip consul_1.6.1_linux_amd64.zip +RUN wget https://releases.hashicorp.com/consul-template/0.22.0/consul-template_0.22.0_linux_amd64.zip &&\ + unzip consul-template_0.22.0_linux_amd64.zip + +ADD service.json / +ADD docker-entrypoint.sh / +RUN chmod +x /docker-entrypoint.sh + +ADD rsyslog.conf /etc/ + +ADD haproxy.conf.ctmpl /tmp/haproxy.conf.ctmpl + diff --git a/haproxy/docker-entrypoint.sh b/haproxy/docker-entrypoint.sh new file mode 100644 index 0000000..a8ce610 --- /dev/null +++ b/haproxy/docker-entrypoint.sh @@ -0,0 +1,22 @@ +#!/bin/sh +set -e + +# first arg is `-f` or `--some-option` +if [ "${1#-}" != "$1" ]; then + set -- haproxy "$@" +fi + +if [ "$1" = 'haproxy' ]; then + shift # "haproxy" + # if the user wants "haproxy", let's add a couple useful flags + # -W -- "master-worker mode" (similar to the old "haproxy-systemd-wrapper"; allows for reload via "SIGUSR2") + # -db -- disables background mode + set -- haproxy -W -db "$@" +fi + +#/consul agent -join=consul --data-dir=/tmp/x --config-file=/service.json &> /dev/stdout + +/consul-template -consul-addr=consul:8500 -template="/tmp/haproxy.conf.ctmpl:/usr/local/etc/haproxy/haproxy.cfg:bash -c 'killall -9 haproxy; haproxy -f /usr/local/etc/haproxy/haproxy.cfg || true'" + +exec "$@" + diff --git a/haproxy/haproxy.conf.ctmpl b/haproxy/haproxy.conf.ctmpl new file mode 100644 index 0000000..c1a7bb8 --- /dev/null +++ b/haproxy/haproxy.conf.ctmpl @@ -0,0 +1,22 @@ +global + daemon + user nobody + group nogroup + maxconn 4096 + +defaults + mode http + timeout client 10s + timeout connect 10s + timeout server 10s + +listen http-in + bind *:9999 + stats enable + stats auth admin:devops + stats uri /haproxy + balance roundrobin + option httpchk HEAD /pi/3 HTTP/1.0 + + {{range service "pi"}} + server {{.Node}} {{.Address}}:{{.Port}} check inter 10s fastinter 1s rise 2 fall 2 weight 8{{end}} diff --git a/haproxy/rsyslog.conf b/haproxy/rsyslog.conf new file mode 100644 index 0000000..6cd0766 --- /dev/null +++ b/haproxy/rsyslog.conf @@ -0,0 +1,22 @@ +# Loads the imudp into rsyslog address space +# and activates it. +# IMUDP provides the ability to receive syslog +# messages via UDP. +$ModLoad imudp + +# Address to listen for syslog messages to be +# received. +$UDPServerAddress 0.0.0.0 + +# Port to listen for the messages +$UDPServerRun 514 + +# Take the messages of any priority sent to the +# local0 facility (which we reference in the haproxy +# configuration) and send to the haproxy.log +# file. +local0.* -/var/log/haproxy.log + +# Discard the rest +& ~ + diff --git a/haproxy/service.json b/haproxy/service.json new file mode 100644 index 0000000..860b6fd --- /dev/null +++ b/haproxy/service.json @@ -0,0 +1,6 @@ +{ + "service": { + "name": "haproxy", + "port": 9999 + } +}