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.
- Set up persistent disk into Google cloud
- Create two persistent disks. The user will need to create the disks in the same GCE zone as the Kubernetes cluster. Replace
below with the appropriate zone. The names wordpress-1 and wordpress-2 must match the pdName fields we have specified in gce-volumes.yaml
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
- Deploy Mysql 5.7
- 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
- Deploy WordPress
- 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
- Export Mysql database from local Mysql container
- Use ‘docker ps’ command to list all running containers.
2. Use following command to export local Mysql database
- Import the dump into the GKE Mysql
- Use ‘kubectl get po’ command to list all running pods.
2. Import data into the Mysql database using the following command
- 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.
The post Migrating local container workload to Google Container Engine appeared first on DevOpsTech Solutions.
This post first appeared on Migrating XEN Virtual Machines To The AWS Cloud, please read the originial post: here