Create and Configure Kubernetes Components

Create and Configure Secret for MySQL Database

In this step, you create a Kubernetes secret component for the MySQL database. This is necessary because the configuration below is in the environment variables section of the mysql-deployment YAML file.

1env:
2 - name: MYSQL_ROOT_PASSWORD
3 valueFrom:
4 secretKeyRef:
5 name: mysql-pass
6 key: password

Before you proceed, choose a password and convert it into base64 format. You can use an online tool for this conversion. For this example, the password is password and its base64 encoding is cGFzc3dvcmQ=.

  1. Click on the Kubernetes icon on the dock, search for secret, and click on it or drag it to the canvas.

Blog content image

Figure: Create secret component

  1. Click on the Secret component to open the configuration window.

    • Set the name as mysql-pass
    • Set the Type as Opaque
    • Click + next to Data and add the secret as a key-value pair password:cGFzc3dvcmQ=

Blog content image

Figure: Configure secret

  1. Click outside the window to close the configuration tab.

Create Persistent Volumes

MySQL and WordPress each require a Persistent Volume (PV) to store their data.

For this tutorial, you will use the manual StorageClassName and set the Persistent Volume to use the hostPath type.

Please note that using hostPath for Persistent Volumes is generally not recommended for production environments because it ties the volume to the node's filesystem, which can lead to data loss if the node fails. However, you can use it in this tutorial for development purposes.

  1. Click on the Kubernetes icon on the dock, search for Persistent Volume, and select it. Create two PVs.

Blog content image

Figure: Create persistent volume

  1. Click on the wordpress PV to open the configuration window.

    • Change the "name" to wp-pv
    • Set the "StorageClassName" as manual
    • Click + next to "AccessMode" and enter ReadWriteOnce

Blog content image

Figure: Configure persistent volume

1- Scroll down to "Capacity" and enter the key pair `storage:20Gi`

Blog content image

Figure: Persistent volume capacity

1- Scroll down to "Hostpath" and input `mnt/data/wp-pv` for the _path_ and `DirectoryOrCreate` for the _type_.

Blog content image

Figure: Persistent volume hostpath

  1. Repeat similar steps for the MySQL Persistent Volume

    • Click on the MySQL PV to open the configuration window.
    • Change the "name" to mysql-pv
    • Set the "StorageClassName" to manual
    • Click + next to "AccessMode" and set it to ReadWriteOnce
    • Scroll down to "Capacity" and enter the key pair storage:20Gi
    • Scroll down to "Hostpath" and input mnt/data/mysql-pv for the path and DirectoryOrCreate for the type.
  2. Click on wp-pv-claim and mysql-pv-claim and set their "StorageClassName" as manual.

NEXT CHAPTER

Introduction

Layer5, the cloud native management company