A bit backwards, but in Part 2 of the series we created and deployed an application. In this post we will be deploying a MySQL database for the application to communicate with, and in Part 4 we will hook this database up to the previously-deployed application.
Series
This is Part 3 of the 9-part series:
- Kubernetes Part 1: Core Concepts and Installation (Minikube)
- Kubernetes Part 2: Python Flask Application Deployment
- Kubernetes Part 3: MySQL Database Deployment
- Kubernetes Part 4: Application Deployments (The Smart Way - YAML Files)
- Kubernetes Part 5: Linking Application with Database (Discovery)
- Kubernetes Part 6: Rolling Updates
- Kubernetes Part 7: Secrets
- Kubernetes Part 8: Persistent Volumes
- Kubernetes Part 9: ConfigMaps
MySQL
We will now use an off-the-shelf container image of a MySQL installation to deploy to Kubernetes. There is one important point in this post which is that we are not going to experiment with PersistentVolumes and PersistentVolumeClaims. These concepts are required if you wish to maintain the history of the MySQL instance when the container shuts down, but for simplicity, we are going to simply deploy the MySQL instance with the assumption that we lose the data within once the instance shuts down.
First, let’s deploy the container - we are going to use an off the shelf instance of MySQL which
can be found here and pull down an image into our Docker image
repository. You could also simply ignore the --image-pull-policy=Never
switch in the deployment
command to follow which would automatically obtain the image from the public Docker image
repository:
Next, we will deploy the Docker image to a Pod and expose the instance via a Service. We will also specify an environment variable for the Container to set the root password in order to enable access/initialize the instance:
The last command above will print the IP and Port for the Service that was created and can be used in the next section for validation of the instance.
Validation
You can now use your favorite utility/development tool to connect to the MySQL instance, or a simple command-line client application, and connect to the IP/Port combination listed in the Service that was created. If you wish to use a command-line based MySQL client you can install it via the following:
You can then connect to the MySQL instance using the IP/Port combination given along with the password specified when we created the instance:
Next Steps
We now have a fully-functioning MySQL instance without persistent storage. The next post will cover how to create configuration files that define the components of your deployment (much more manageable)..
Credit
The above tutorial was pieced together with some information from the following sites/resources: