Setting up a Standalone MYSQL Instance on Kubernetes & exposing it using Nginx Ingress Controller.
A simple straightforward guide to setup a standalone MySQL instance in Kubernetes an expose it using Nginx Ingress Controller.
In this guide, we would have a simple deployment, in which the data is persisted using the Persistent Volume and then service is exposed to the rest of the world using ClusterIP Service along with an Ingress definition.
Let’s create a namespace named mysql along with a secret which will contain the root user’s password for MYSQL
kubectl create ns mysql kubectl create secret generic mysql-creds --from-literal=ROOT_PASSWORD=changeme -n mysql
Below we have the configmap, deployment, service, Ingress, PVC configuration which we can apply.
Exposing MYSQL or TCP/UDP service often requires a bit of the change in the Nginx-ingress-controller configuration. As mentioned in the official documentation.
- Ensure that Nginx-Ingress-Controller deployment specifies the name of the configmaps to configure tcp/udp configuration.
— tcp-services-configmap — udp-services-configmap
containers:
- args:
- /nginx-ingress-controller
- --v=1
- --configmap=$(POD_NAMESPACE)/nginx-configuration
- --tcp-services-configmap=$(POD_NAMESPACE)/tcp-services
- --udp-services-configmap=$(POD_NAMESPACE)/udp-services
- Adding details in the configmap which involves the port number to be exposed in our case it’s 3306(MYSQL) along with the namespace followed by the name of the service and the port number.
If everything goes well we can try connecting to MYSQL Instance using the cli
mysql -u root -h mysql.<DOMAIN>.com -p
In context to the same, there is a similar blog which discusses how to easily provision MYSQL cluster using Presslabs MYSQL Operator
https://medium.com/@chrisedrego/mysql-operator-a-mysql-affair-with-kubernetes-dc21e19e93b7
if you found this article useful, feel free to 👏 clap many times or share it with your friends.