Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions haproxy/Dockerfile
Original file line number Diff line number Diff line change
@@ -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

22 changes: 22 additions & 0 deletions haproxy/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

22 changes: 22 additions & 0 deletions haproxy/haproxy.conf.ctmpl
Original file line number Diff line number Diff line change
@@ -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}}
22 changes: 22 additions & 0 deletions haproxy/rsyslog.conf
Original file line number Diff line number Diff line change
@@ -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
& ~

6 changes: 6 additions & 0 deletions haproxy/service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"service": {
"name": "haproxy",
"port": 9999
}
}
2 changes: 1 addition & 1 deletion kubernetes/db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ spec:
- name: mysql-db
image: mysql
ports:
- name: mysql
- name: mysql:5.7
containerPort: 3306
env:
- name: MYSQL_ROOT_PASSWORD
Expand Down