# Deploying WhatsApp Business API using `Kubernetes Engine on Google Cloud Platform' #### :memo: This documentaion shows you how to setup the WhatsApp Business API on a Google Kubernetes Engine. ## Kubernetes cluster schema ![](https://i.imgur.com/9PzFkV0.png) ### Here we have following components: 1. Kubernetes Engine: It will host the cluster where the containers of the WhatsApp API service will run. It will have 3 Compute Engines. 2. Cloud SQL (MySQL): To configure the API, we need a MySQL database. 3. Persistent Disk: They will be used by the WhatsApp API to store any media/document/files it needs. 4. App Engine: It will host the webhook we will use to interact with the API, e.g with this hook, you will can "intercept" every message that will be sent through the API to decided what to do to respond to that message. ### Step 1. Create custom VPC and subnet as shown in picture: - Define name for your network and subnet, set region and IP range for subnet. Leave other parametres as default ![](https://i.imgur.com/lwZeIgn.png) - Click on created VPC network, allocate IP range in "Private Service Connection" and create connection in "Private Connections to Services". Result must looks like this (names in picture are optional) ![](https://i.imgur.com/9mx0TZQ.png) ![](https://i.imgur.com/Ia7fkuF.png) Go to Cloud Console ➜ VPC Network ➜ Create VPC Network ### Step 2. Create Google Kubernetes Engine with folowing parametres: Go to Cloud Console ➜ GKE ➜ Create - In "Cluster Basics" section define name for your cluster ![](https://i.imgur.com/dTWKS13.png) - Go to "Node Pool", define name for pool, set number of nodes to 3 and leave other parametres as default: ![](https://i.imgur.com/nPyUSYD.png) - In "Nodes" section select these parametres and leave others by default: ![](https://i.imgur.com/DLDHhR7.png) - Select custom VPC and subnet you created before. Set IP range for private cluster, enable "HTTP Load Balancing" and leave other values as default: ![](https://i.imgur.com/rMtTtKR.png) - In "Features" section set these parametres: ![](https://i.imgur.com/Vz0Dnur.png) ### Step 3. Create MySQL database: Go to Cloud Console ➜ SQL ➜ Create a MySQL instance - Define Instance ID - Generate new password - In "Machine type" section choose "Standard 2 vCPU, 7.5 GB", in "Storage" select "SSD" 20Gb, and "Enable automatic storage increases" ![](https://i.imgur.com/zOCQ3Gg.png) - In "Connections" set Private IP, choose your VPC network and allocated IP range you created before ![](https://i.imgur.com/5pGlGae.png) ### Step 4. Creating Whatsapp API Services in Kubernetes cluster - Connect to your cluster - Clone [Whatsapp-Business-API-Setup-Scripts](https://github.com/FaridPashayev1/WhatsApp-Business-API-Setup-Scripts.git) repository - Go to **installation/kubernetes** folder - Configure **db.env** file - Create a **whatsapp-config** Secret: ```kubectl create secret generic whatsapp-config --from-env-file=db.env``` - Create new **Storage Class**: ```kubectl apply -f filestore-class.yaml``` - Create a **Media Volume**: ```kubectl apply -f volume.yaml``` - Set the **$VERSION** Environment Variable: Replace the **$VERSION** environment variable with the latest [WhatsApp Business API client version](https://developers.facebook.com/docs/whatsapp/changelog) (e.g., 2.23.4) in the containers section of the **webapp.yaml**, **master.yaml**, and **coreapp.yaml** files. ![](https://i.imgur.com/tHlYd4W.png) ![](https://i.imgur.com/DFMBtLX.png) ![](https://i.imgur.com/W7oYAsO.png) - Deploy the Containers: Deploy the **Webapp**, **Master**, and **Coreapp** containers by running the following commands: ```kubectl apply -f webapp.yaml``` ```kubectl apply -f master.yaml``` ```kubectl apply -f coreapp.yaml``` - Check if the pods are running: ```kubectl get pods``` Output should be like this: ```NAME READY STATUS RESTARTS AGE whatsapp-coreapp-deployment-78c4d987b8-4cpz4 1/1 Running 0 2s whatsapp-coreapp-deployment-78c4d987b8-l5qjj 1/1 Running 0 2s whatsapp-master-deployment-8598d7bf6b-56fvn 1/1 Running 7 15m whatsapp-master-deployment-8598d7bf6b-9r6lc 1/1 Running 7 16m whatsapp-web-deployment-cd4c5785c-9vn6l 1/1 Running 0 16m whatsapp-web-deployment-cd4c5785c-mn7kf 1/1 Running 0 16m```
{"metaMigratedAt":"2023-06-16T14:39:33.954Z","metaMigratedFrom":"Content","title":"Deploying WhatsApp Business API using `Kubernetes Engine on Google Cloud Platform'","breaks":true,"contributors":"[{\"id\":\"b9e47ac2-8783-4b43-afc2-3d7e19c388b4\",\"add\":8458,\"del\":4021}]"}
Expand menu