This article assumes that user already has a Kubernetes cluster created with GKE-engine up and running. If that is not the case, the user can read Kubernetes cluster on Google Container Engine article which explains how to do so or read the official document.

Let’s Migrate Local Container to Google Container Engine.

 

Prerequisites

Considering that the user already has WordPress application with Mysql 5.7 running on local Docker deployment.

  • List containers running in the local Docker deployment

A user can list running Docker containers using the ‘docker ps’ command.

Fig. (1) Docker list containers

 

  • Set up persistent disk into Google cloud
  1. Create two persistent disks. The user will need to create the disks in the same GCE zone as the Kubernetes cluster. Replace <zone> below with the appropriate zone. The names wordpress-1 and wordpress-2 must match the pdName fields we have specified in gce-volumes.yaml
gcloud compute disks create –size=10GB –zone=<zone> wordpress-1
gcloud compute disks create –size=10GB –zone=<zone> wordpress-2

 

2. Create the persistent volume objects in Kubernetes for those disks:

    gce-volume.yaml

apiVersion: v1kind: PersistentVolume

metadata:

name: wordpress-pv-1

spec:

capacity:

storage: 10Gi

accessModes:

– ReadWriteOnce

gcePersistentDisk:

pdName: wordpress-1

fsType: ext4

apiVersion: v1

kind: PersistentVolume

metadata:

name: wordpress-pv-2

spec:

capacity:

storage: 10Gi

accessModes:

– ReadWriteOnce

gcePersistentDisk:

pdName: wordpress-2

fsType: ext4

 

3. Use the following command to create the persistent volumes

kubectl create -f gce-volumes.yaml

 

  • Deploy Mysql 5.7
  1. Deploy Mysql using mysql-deployment.yaml

    mysql-deployment.yaml

apiVersion: v1kind: Service

metadata:

name: wordpress-mysql

labels:

app: wordpress

spec:

ports:

– port: 3306

selector:

app: wordpress

tier: mysql

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

name: mysql-pv-claim

labels:

app: wordpress

spec:

accessModes:

– ReadWriteOnce

resources:

requests:

storage: 10Gi

apiVersion: extensions/v1beta1

kind: Deployment

metadata:

name: wordpress-mysql

labels:

app: wordpress

spec:

strategy:

type: Recreate

template:

metadata:

labels:

app: wordpress

tier: mysql

spec:

containers:

– image: mysql:5.7

name: mysql

args:

– “–ignore-db-dir=lost+found”

env:

– name: MYSQL_ROOT_PASSWORD

value: password

ports:

– containerPort: 3306

name: mysql

volumeMounts:

– name: mysql-persistent-storage

mountPath: /var/lib/mysql

volumes:

– name: mysql-persistent-storage

persistentVolumeClaim:

claimName: mysql-pv-claimUse following command to deploy Mysql

 

2. Use the following command to deploy Mysql

kubectl create -f mysql-deployment.yaml

 

  • Deploy WordPress
  1. Next, deploy WordPress using wordpress-deployment.yaml

     wordpress-deployment.yaml

apiVersion: v1kind: Service

metadata:

name: wordpress

labels:

app: wordpress

spec:

ports:

– port: 80

selector:

app: wordpress

tier: frontend

type: LoadBalancer

apiVersion: v1

kind: PersistentVolumeClaim

metadata:

name: wp-pv-claim

labels:

app: wordpress

spec:

accessModes:

– ReadWriteOnce

resources:

requests:

storage: 10Gi

apiVersion: extensions/v1beta1

kind: Deployment

metadata:

name: wordpress

labels:

app: wordpress

spec:

strategy:

type: Recreate

template:

metadata:

labels:

app: wordpress

tier: frontend

spec:

containers:

– image: wordpress:4.7.3-apache

name: wordpress

env:

– name: WORDPRESS_DB_HOST

value: wordpress-mysql

– name: WORDPRESS_DB_PASSWORD

value: password

ports:

– containerPort: 80

name: wordpress

volumeMounts:

– name: wordpress-persistent-storage

mountPath: /var/www/html

volumes:

– name: wordpress-persistent-storage

persistentVolumeClaim:

claimName: wp-pv-claim

 

2. Use the following command to deploy WordPress

kubectl create -f wordpress-deployment.yaml

 

  • Export Mysql database from local Mysql container
  1. Use ‘docker ps’ command to list all running containers.
Fig. (2) Container list

 

2. Use following command to export local Mysql database

docker exec root_db_1 sh -c ‘exec mysqldump -uroot -ppassword wordpress > databases.sql

 

  • Import the dump into the GKE Mysql
  1. Use ‘kubectl get po’ command to list all running pods.
Fig. (3) List pods

 

2. Import data into the Mysql database using the following command

kubectl exec -i wordpress-mysql-4121831684-d3cgd — mysql -uroot -ppassword wordpress < databases.sql

 

  • Change DNS entry

After performing above steps, user has to login to DNS service provider and change ‘A’ record(s) for pointing it to new created load balancer’s IP which was created while WordPress deployment.

Conclusion:

To manage running Docker containers, Google Container Engine is a very powerful cluster manager. It’s built on the open-source Kubernetes system, giving the flexibility to take an advantage of on-premises, hybrid or public cloud infrastructure.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>


CAPTCHA Image
Reload Image