Cloud Computing, DevOps, Google Cloud (GCP)

5 Mins Read

Deploying WordPress on Google Kubernetes Engine (GKE)

Voiced by Amazon Polly

Introduction

In today’s rapidly evolving landscape of containerized applications, deploying WordPress on Google Kubernetes Engine (GKE) offers unparalleled scalability and resilience. This guide serves as a comprehensive resource, detailing the steps involved in setting up a robust WordPress deployment paired with a MySQL database, utilizing Persistent Disk for storage, and leveraging Google Cloud SQL for efficient database management.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

WordPress and Its Data Storage

WordPress relies heavily on relational databases for storing articles and metadata, as well as on local file systems for asset management. Given the transient nature of containers, storing persistent data within them is impractical. Persistent Disk provides a reliable solution, ensuring that data remains intact even in the event of container deletion.

Setting up your environment

To kickstart the setup process, configure Google Cloud Shell by setting the desired region and downloading the necessary application manifest files from the GitHub repository

Download the manifest files

Creating a GKE cluster

Leverage Google Cloud Shell to create a GKE cluster tailored to host your WordPress application containers. Once created, establish a connection to the newly provisioned cluster to facilitate further configuration.

Provicining PV and a PVC :

In order to achieve persistent data storage for the WordPress deployment, it’s imperative to create a Persistent Volume (PV) and a Persistent Volume Claim (PVC). Google Kubernetes Engine (GKE) simplifies this process by offering a default StorageClass resource, enabling dynamic provisioning of PVs backed by Persistent Disk.

PVC Creation Manifest:

We utilize the wordpress-volumeclaim.yaml file to describe our PVC. This manifest requests 200 GB of storage. Note that we haven’t explicitly defined a StorageClass resource in the file, implying the use of the default StorageClass for provisioning a PV backed by Persistent Disk.Command to deploy the manifest

Setting up Google Cloud SQL instance

Generate credentials for a database user named “wordpress” and assign a password for WordPress authentication to the instance:

Deploying WordPress

Configure Service Account and Create Kubernetes Secrets:
Before proceeding with the deployment of WordPress, it’s essential to set up a service account and create Kubernetes secrets to manage both the service account and database credentials. This ensures secure communication between our WordPress application and the MySQL instance through a Google Cloud SQL proxy.

Create Service Account:
We begin by creating a service account named <cloudsql-proxy> using the Google Cloud CLI:

This command establishes a dedicated service account for our deployment.

Extract Service Account Email:
We extract the service account’s email address and set it as an environment variable for later use:

Assign Required Role:
To enable the service account to interact with Google Cloud SQL, we add the cloudsql.client role:This step ensures the necessary permissions for the service account.

Generate Key for Service Account:
Generate a key file named “key.json” for the service account to facilitate authentication and authorization access.

Create Kubernetes Secrets:
We create two Kubernetes secrets to store MySQL and service account credentials securely:
For MySQL credentials:

For service account credentials:

These confidential pieces of information are vital for securely handling the sensitive data necessary to facilitate the communication between WordPress and the underlying MySQL database.

Deploy WordPress on GKE

It’s time to deploy our WordPress container in the Google Kubernetes Engine (GKE) cluster. This involves utilizing the wordpress_cloudsql.yaml manifest file, which defines a Deployment creating a Pod with the WordPress container.

Manifest File Description:
The wordpress_cloudsql.yaml manifest file encapsulates the deployment configuration. It specifies a single Pod running a container with the WordPress instance. Here are the key components:

  • The container reads the WORDPRESS_DB_PASSWORD environment variable, which contains the cloudsql-db-credentials secret created earlier.
  • Configuration for communication with MySQL is facilitated through the Google Cloud SQL proxy running in a sidecar container. The WORDPRESS_DB_HOST environment variable is crucial in this setup.

Prepare and Deploy:
Before deployment, it’s essential to prepare the manifest file by replacing the <INSTANCE_CONNECTION_NAME> environment variable. This is achieved using the following commands:

We’re prepared to initiate the deployment of the WordPress container utilizing the manifest file.

Monitor Deployment Status:
The deployment process takes a few minutes as the manifest file orchestrates the attachment of a Persistent Disk to the compute node. To monitor the deployment status and ensure everything is running smoothly, use the following command.

Expose WordPress Service for External Access

In the preceding step, we successfully deployed the WordPress container; however, it’s currently secluded within your cluster without an external IP address. To make your WordPress app accessible from the internet, we’ll create and configure a Kubernetes Service with an attached external load balancer.

Service Exposure Configuration:

Utilizing the wordpress-service.yaml file, this configuration ensures external accessibility for your WordPress app. The Service is explicitly defined with the type LoadBalancer, indicating the need for an external load balancer.

Command to Create Service:

Monitor Service Creation:

The process of creating the load balancer takes a few minutes. Keep an eye on the deployment progress and wait for the Service to be assigned an external IP address. Utilize the following command:

When the output displays an external IP address, as illustrated below, you’re ready to move forward. Note that your external IP will differ from the example:
Sample Output:

Setting up your WordPress blog

Now that your WordPress service is externally accessible, it’s time to configure and set up your WordPress blog.

Navigate to WordPress Installation Page

Using your preferred web browser, visit the following URL, replacing external-ip-address with the actual EXTERNAL_IP address assigned to your WordPress service,

Begin WordPress Installation:

Upon reaching the WordPress installation page, you’ll have the opportunity to choose your desired language. Simply select your preferred language and proceed by clicking on the “Continue” button.

Provide Essential Information:

Proceed to the “Information Needed” page. Here, we will be required to input crucial details for your WordPress blog, including the site title, username, password, and email address. Fill in the necessary information.

fig1

Finalize WordPress Installation:

Once you’ve filled in the necessary information, proceed by clicking the “Install WordPress” button to begin the installation process.

Log In to our WordPress Dashboard:

Access your WordPress dashboard by clicking on “Log In” after the installation is finished. Then, enter the username and password you set up earlier during the installation process.

fig2

Conclusion

Congratulations on successfully deploying WordPress on Google Kubernetes Engine (GKE) with Persistent Disk and Google Cloud SQL! This setup ensures data durability and availability, with Persistent Disk providing reliable storage outside the containers and Google Cloud SQL offering a managed MySQL database solution.

Drop a query if you have any questions regarding GKE and we will get back to you quickly.

Experience Effortless Cloud Migration with Our Expert Solutions

  • Stronger security  
  • Accessible backup      
  • Reduced expenses
Get Started

About CloudThat

CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As a Microsoft Solutions Partner, AWS Advanced Tier Training Partner, and Google Cloud Platform Partner, CloudThat has empowered over 850,000 professionals through 600+ cloud certifications winning global recognition for its training excellence including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 12 awards in the last 8 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, IoT, and cutting-edge technologies like Gen AI & AI/ML. It has delivered over 500 consulting projects for 250+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

FAQs

1. Why use Persistent Disk for WordPress on GKE?

ANS: – Persistent Disk ensures that your WordPress data persists even if containers are deleted or moved. It provides a reliable storage solution outside the containers, enhancing data durability.

2. What is the role of Google Cloud SQL in this deployment?

ANS: – Google Cloud SQL serves as the managed MySQL database for WordPress. It replaces the traditional installation of MySQL, offering a scalable and fully managed database solution for your WordPress application.

WRITTEN BY Deepakraj A L

Deepakraj is a dedicated DevOps Engineer passionate about building and managing resilient, scalable systems with Kubernetes at the core. With hands-on experience in containerization (Docker), CI/CD pipelines (Jenkins), and cloud platforms (AWS), he specializes in modernizing infrastructure and accelerating software delivery. His strength lies in transitioning legacy systems into microservices, driving agility and performance. He is also a strong advocate for Infrastructure as Code and version-controlled workflows using Git.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!