From 072f762a0d71970a715064a52c42de0f39ac61f0 Mon Sep 17 00:00:00 2001 From: Micke Nordin Date: Tue, 15 Aug 2023 14:01:08 +0200 Subject: [PATCH] Add healthcheck to proxysql --- proxysql/base/proxysql-configmap.yml | 7 +++++++ proxysql/base/proxysql-deployment.yml | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/proxysql/base/proxysql-configmap.yml b/proxysql/base/proxysql-configmap.yml index 24f81d8..4ed6d4a 100644 --- a/proxysql/base/proxysql-configmap.yml +++ b/proxysql/base/proxysql-configmap.yml @@ -406,3 +406,10 @@ data: { hostname = "proxysql-1.proxysqlcluster", port = 6032, weight = 1 }, { hostname = "proxysql-2.proxysqlcluster", port = 6032, weight = 1 } ) + healthcheck.sh: | + #!/bin/bash + num_servers=$(mysql -NB -u admin -h 127.0.0.1 -P 6032 -e "select count(*) from main.mysql_servers") + if [[ ${num_servers} -lt 1 ]]; then + exit 1 + fi + exit 0 diff --git a/proxysql/base/proxysql-deployment.yml b/proxysql/base/proxysql-deployment.yml index 425b6b6..48f135e 100644 --- a/proxysql/base/proxysql-deployment.yml +++ b/proxysql/base/proxysql-deployment.yml @@ -50,11 +50,27 @@ spec: - name: proxysql-etc mountPath: /etc subPath: etc + - name: proxysql-healthcheck + mountPath: /usr/local/bin/healthcheck.sh + subPath: healthcheck.sh ports: - containerPort: 6033 name: proxysql-mysql - containerPort: 6032 name: proxysql-admin + env: + - name: MYSQL_PWD + valueFrom: + secretKeyRef: + name: proxysql-secret + key: "proxysql_admin_password" + livenessProbe: + exec: + command: + - /bin/bash + - /usr/local/bin/healthcheck.sh + initialDelaySeconds: 5 + periodSeconds: 5 initContainers: - image: docker.sunet.se/sunet/docker-jinja:latest name: init-config @@ -309,3 +325,9 @@ spec: items: - key: "proxysql.cnf" path: "proxysql.cnf" + - name: proxysql-healthcheck + configMap: + name: proxysql-configmap + items: + - key: "healthcheck.sh" + path: "healthcheck.sh"