Bobcares

How to Deploy WordPress on GKE

by | May 17, 2024

Learn how to deploy WordPress on GKE with Persistent Disk and Google Cloud SQL. Our WordPress Support team is here to help you with your questions and concerns.

How to Deploy WordPress on GKE

Deploying WordPress on GKE with Persistent Disk and Google Cloud SQL offers us a reliable solution for our WordPress application.

How to Deploy WordPress on GKE

This setup promises data persistence and efficient database management.

Let’s take a look at the steps to set up this environment.

  1. First, we have to configure gcloud. Let’s start by setting the region for the gcloud command-line tool:
    gcloud config set compute/region regionCopy Code

    Remember to replace region with your desired region.

  2. Then, clone the needed files from the GitHub repository:
    git clone https://github.com/GoogleCloudPlatform/kubernetes-engine-samples
    Copy Code
  3. Next, switch to the directory with the WordPress persistent disk files:
    cd kubernetes-engine-samples/wordpress-persistent-disksCopy Code
  4. Then, set the `WORKING_DIR` environment variable as seen here:
    WORKING_DIR=$(pwd)Copy Code

Creating a GKE Cluster

  1. First, define the GKE cluster name:
    GKE_CLUSTER_NAME=persistent-disk-wordpressCopy Code
  2. Next, create an auto-provisioned GKE cluster:
    gcloud container clusters create $GKE_CLUSTER_NAME --region regionCopy Code
  3. Now, set up a connection to the new cluster:
    gcloud container clusters get-credentials $GKE_CLUSTER_NAME --region regionCopy Code

Now, create a PersistentVolumeClaim by deploying the manifest file:

kubectl apply -f $WORKING_DIR/wordpress-volumeclaim.yamlCopy Code

Setting Up Google Cloud SQL

  1. First, create a Cloud SQL instance:
    SQL_INSTANCE_NAME=mysql-wd-instance
    gcloud sql instances create $SQL_INSTANCE_NAME
    Copy Code
  2. Then, get the instance connection name as seen here:
    export INSTANCE_CONNECTION_NAME=$(gcloud sql instances describe $SQL_INSTANCE_NAME --format='value(connectionName)')
    Copy Code
  3. Now, create the WordPress database:
    gcloud sql databases create wordpress --instance $SQL_INSTANCE_NAME
    Copy Code
  4. Finally, generate credentials for the `WordPress` user:
    CLOUD_SQL_PASSWORD=$(openssl rand -base64 18)
    gcloud sql users create wordpress --host=% --instance $SQL_INSTANCE_NAME --password $CLOUD_SQL_PASSWORD
    Copy Code

Deploying WordPress on GKE

  1. First, create a service account:
    SA_NAME=cloudsql-proxy
    gcloud iam service-accounts create $SA_NAME --display-name $SA_NAME
    Copy Code
  2. Now, get the service account email:
    SA_EMAIL=$(gcloud iam service-accounts list --filter=displayName:$SA_NAME --format='value(email)')
    Copy Code
  3. Then, add the `cloudsql.client` role to the service account:
    gcloud projects add-iam-policy-binding $PROJECT_ID --role roles/cloudsql.client --member serviceAccount:$SA_EMAIL
    Copy Code
  4. Next, generate a key for the service account:
    gcloud iam service-accounts keys create $WORKING_DIR/key.json --iam-account $SA_EMAIL
    Copy Code
  5. Now, create a secret for the MySQL credentials:
    kubectl create secret generic cloudsql-db-credentials --from-literal=username=wordpress --from-literal=password=$CLOUD_SQL_PASSWORD
    Copy Code
  6. Also, create a secret for the service account credentials:
    kubectl create secret generic cloudsql-instance-credentials --from-file=$WORKING_DIR/key.json
    Copy Code

Deploying WordPress

  1. First, prepare the `wordpress_cloudsql.yaml` file:
    cat $WORKING_DIR/wordpress_cloudsql.yaml.template | envsubst > $WORKING_DIR/wordpress_cloudsql.yaml
    Copy Code
  2. Then, deploy WordPress using the manifest file:
    kubectl apply -f $WORKING_DIR/wordpress_cloudsql.yamlCopy Code
  3. Now we can monitor the status of the deployment:
    kubectl get pods -l app=wordpress –watchCopy Code

With the above steps, we can easily deploy WordPress on GKE with Google Cloud SQL. This setup offers a highly available, scalable, and managed environment for our WordPress application.

[Need assistance with a different issue? Our team is available 24/7.]

Conclusion

In brief, our Support Experts demonstrated how to deploy WordPress on GKE with Persistent Disk and Google Cloud SQL.

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Speed issues driving customers away?
We’ve got your back!