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.
This setup promises data persistence and efficient database management.
Let’s take a look at the steps to set up this environment.
- First, we have to configure gcloud. Let’s start by setting the region for the gcloud command-line tool:
gcloud config set compute/region region
Copy CodeRemember to replace region with your desired region.
- Then, clone the needed files from the GitHub repository:
git clone https://github.com/GoogleCloudPlatform/kubernetes-engine-samples
Copy Code - Next, switch to the directory with the WordPress persistent disk files:
cd kubernetes-engine-samples/wordpress-persistent-disks
Copy Code - Then, set the `WORKING_DIR` environment variable as seen here:
WORKING_DIR=$(pwd)
Copy Code
Creating a GKE Cluster
- First, define the GKE cluster name:
GKE_CLUSTER_NAME=persistent-disk-wordpress
Copy Code - Next, create an auto-provisioned GKE cluster:
gcloud container clusters create $GKE_CLUSTER_NAME --region region
Copy Code - Now, set up a connection to the new cluster:
gcloud container clusters get-credentials $GKE_CLUSTER_NAME --region region
Copy Code
Now, create a PersistentVolumeClaim by deploying the manifest file:
kubectl apply -f $WORKING_DIR/wordpress-volumeclaim.yaml
Copy Code
Setting Up Google Cloud SQL
- First, create a Cloud SQL instance:
SQL_INSTANCE_NAME=mysql-wd-instance gcloud sql instances create $SQL_INSTANCE_NAME
Copy Code - 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 - Now, create the WordPress database:
gcloud sql databases create wordpress --instance $SQL_INSTANCE_NAME
Copy Code - 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
- First, create a service account:
SA_NAME=cloudsql-proxy gcloud iam service-accounts create $SA_NAME --display-name $SA_NAME
Copy Code - Now, get the service account email:
SA_EMAIL=$(gcloud iam service-accounts list --filter=displayName:$SA_NAME --format='value(email)')
Copy Code - 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 - Next, generate a key for the service account:
gcloud iam service-accounts keys create $WORKING_DIR/key.json --iam-account $SA_EMAIL
Copy Code - 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 - 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
- First, prepare the `wordpress_cloudsql.yaml` file:
cat $WORKING_DIR/wordpress_cloudsql.yaml.template | envsubst > $WORKING_DIR/wordpress_cloudsql.yaml
Copy Code - Then, deploy WordPress using the manifest file:
kubectl apply -f $WORKING_DIR/wordpress_cloudsql.yaml
Copy Code - Now we can monitor the status of the deployment:
kubectl get pods -l app=wordpress –watch
Copy 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