How to Deploy MySQL Server in Alibaba Container Service using VSTS

By Nadaraj Prabhu, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Create Alibaba Container Service for Kubernetes

Step 1: Sign in to the Alibaba Cloud Console at Link.

Step 2: Go to Products and select “Container Service” under “Elastic Computing” category as containers and choose Kubernetes Service.

Image for post
Image for post

Step 3: Now select container service as “Kubernetes”, after that on the extreme right click on “Create Kubernetes Cluster”

Image for post
Image for post

Step 4: Provide Cluster Name, Region (Location), Zone, VPC (Virtual Private Connection, you can use an existing one or create a new one). Node type is your default subscription type hence for me “Pay-As-You-Go”

Image for post
Image for post

Note: Currently Alibaba Container Service for Kubernetes only support “Pay-As-You-Go” subscription.

Step 5: Next scroll down and go to “MASTER Configuration”, select master instance SKU size (CPU and RAM) and Disk Type and Disk Size.

Next for Worker configuration select instance SKU size (CPU and RAM), no of node/agents and Disk Type and Disk Size (Include Data disk also if necessary)

I have selected Password authentication, since I’m planning to use Password rather than key Pair, but you can select authentication of your choice.

Note: By default, Master instance will have 3 nodes, you cannot change the no of master node. Where as in Worker/ Agent instances can me reduces to 2 nodes.

Image for post
Image for post

Step 6: Currently Alibaba cloud does not provide you an option to change the “Docker Version” or “Kubernetes Version”

Configure SNAT if required, Use Public SLB if you are using frontend website or application hosted in the cluster.

Enable SSH access if you not Site-toSite or Point-to-Site VPN set up.

Enable Cloud Monitor. This helps you to monitor you cluster and see you metrics and create alerts based on the report.

Select “Log Service” to collect the telemetry for the cluster.

Select you “Network Plugin

Select the custom port ( or leave it default as 128) , Also if you have any custom CA (Signed certificated) you can enable and attach it over here.

Image for post
Image for post

Step 7: Click of create button on the right, and check for request validation and click on “Create”

Step 8: Now Wait for the deployment to complete.

Image for post
Image for post

After successful deployment you should have go the below mentioned message with green mark.

Image for post
Image for post

Now click on cluster on the left navigation panel and you should be able to see your “Kubernetes Cluster”

Image for post
Image for post

Deploy MySQL Server to Kubernetes Cluster using DevOps (VSTS)

To manage the cluster and create applications and pods efficiently, it’s better to do this using DevOps practices. VSTS (Azure DevOps) helps you connect and deploy to Kubernetes cluster using “kubectl” task.

Step 1: To connect Kubernetes Services from VSTS, you need kube config file. Go to your Alibaba Container Service, select your cluster and click on “Manage”.

Image for post
Image for post

Step 2: Scroll down and navigate to “Cluster Resource” Section and copy the key (kube config code).

Image for post
Image for post

Note:

  1. Copy Internet Access Code, since the service will be connected over https/TLS connection over internet
  2. If you have a on-premise VSTS and VPN setup for this cluster then you can use VPN Access

Step 3: Go to your Azure DevOps Link, if you do not already have project setup, create a new project.

Image for post
Image for post

Step 4: Provide a project name, description, version control as “Git” and Work Item.

Image for post
Image for post

Step 5: Next, let’s build the pipeline from the repository from Git Hub Link

Image for post
Image for post

Step 6: Now go you have 2 option either you can import the code to VSTS Repo and deploy from it or use the code directly from GitHub

Image for post
Image for post

Step 7: Authorize using OAuth by allowing the permission or install GitHub app from market place. For this demo I’m going to use OAuth.

Image for post
Image for post
Image for post
Image for post

Step 8: Select “Kb8-MySQL” repository. Click on continue.

Image for post
Image for post

Step 9: Select Empty job, Next select the Agent as “Hosted Ubuntu 1604”. Click on + symbol to add the task.

Image for post
Image for post
Image for post
Image for post

Step 10: Select “Copy task” and enter the values for “copy task” as mentioned below:

Parameters: -
Display name: Copy Files Secret (or Any Name as per your requirement)
Source Folder: (leave it empty since file is in root folder, else give the path)
Contents: **/Secret.yml
Target Folder: $(Build.ArtifactStagingDirectory)

Image for post
Image for post

Step 11: Add 3 more “Copy task” and enter the values for “copy task” as mentioned below for each task:

Parameters: -
Display name: Copy Files StorageClass (or Any Name as per your requirement)
Source Folder: (leave it empty since file is in root folder, else give the path)
Contents: **/StorageClass.yml
Target Folder: $(Build.ArtifactStagingDirectory)

Display name: Copy Files PersitantVolume and claim (or Any Name as per your requirement)
Source Folder: (leave it empty since file is in root folder, else give the path)
Contents: **/PersitantVolumeandclaim.yml
Target Folder: $(Build.ArtifactStagingDirectory)

Display name: Copy Files mysql (or Any Name as per your requirement)
Source Folder: (leave it empty since file is in root folder, else give the path)
Contents: **/MySQl.yml
Target Folder: $(Build.ArtifactStagingDirectory)

Step 11: Next add “Publish Build Artifacts task” and no need to make any changes in the task:

Image for post
Image for post

Step 12: Save and queue this build.

Image for post
Image for post

Step 13: Go to logs and check the build the status. It should be succeeded as shown below:

Image for post
Image for post

Step 14: Next, we need to deploy the build using “release” management in “pipeline”

Image for post
Image for post

Step 15: Create an empty job, create a name for the stage, release and add the “artifact”

Image for post
Image for post
Image for post
Image for post

Step 16: Select your build in “Source” and change “Default version” as Latest. Click on add to save the settings

Image for post
Image for post

Step 17: Click on “1 job 0 task” to create task for deployment.

Image for post
Image for post

Step 18: Select “Deploy to Kubernetes” task. Next change “Service connection Type” to Kubernetes Service Connection. Click manage to add the Kubernetes connection.

Image for post
Image for post

Note: Make sure you run this deployment in Linux agent, since its build in Linux environment.

Image for post
Image for post

Step 19: Select “Service Connection”, navigate to “New Service Connection” and select Kubernetes.

Image for post
Image for post

Step 20: Open the kubeconfig file, copy and paste the value as show below in Azure DevOps “kubeconfig” field.

Give a connection name and click on ok

Image for post
Image for post
Image for post
Image for post

Step 21: Navigate back to your release configuration and click on refresh. Select the created connection “Alibaba Kubernetes Cluster”.

Image for post
Image for post

Step 22: Now let’s configure the Kubectl task for deploying Secret:

Parameters: -
Version: 1.*
Display Name: kubectl secret create
Command: create
Arguments: -f Secret.yml
Advanced:
Working directory: $(System.DefaultWorkingDirectory)/_MySQL Server-CI/drop (your drop location)

Image for post
Image for post
Image for post
Image for post

Step 23: Same way configure the Kubectl task for rest 3 task (Storage Class, Persistent Volume Claim, MySQL):

Parameters: -
Version: 1.*
Display Name: kubectl storage class
Command: create
Arguments: -f StorageClass.yml
Advanced:
Working directory: $(System.DefaultWorkingDirectory)/_MySQL Server-CI/drop (your drop location)

Version: 1.*
Display Name: kubectl Persistent Vol and Claim
Command: create
Arguments: -f PersitantVolumeandclaim.yml
Advanced:
Working directory: $(System.DefaultWorkingDirectory)/_MySQL Server-CI/drop (your drop location)

Version: 1.*
Display Name: kubectl Mysql
Command: create
Arguments: -f MySQl.yml
Advanced:
Working directory: $(System.DefaultWorkingDirectory)/_MySQL Server-CI/drop (your drop location)

Click on save after setting the configuration

Image for post
Image for post

Step 24: Now create a release to deploy the environment to Alibaba Kubernetes Cluster.

Image for post
Image for post
Image for post
Image for post

Step 25: Go to Alibaba console to see the successful deployment of the MySQL Server.

Image for post
Image for post

Now we have deployed MySQL Server on Alibaba Cloud Kubernetes Container using VSTS (Azure DevOps). With the help VSTS, we can have continuous integration and continuous deployment (CICD) for any kind of environment.

Image for post
Image for post

Original Source

https://www.alibabacloud.com/blog/how-to-deploy-mysql-server-in-alibaba-container-service-using-vsts_594947?spm=a2c41.13076768.0.0

Written by

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store