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.
In this tutorial, we will connect and deploy Kubernetes resources through the Alibaba Cloud console. First, we'll see how we can connect a local machine to a Kubernetes cluster.
Install a Kubernetes Cluster on Alibaba Cloud.
To manage the Kubernetes cluster, you need to connect to your cluster in using Cloud Shell CLI 2.0. It will help you execute "kubectl" command from local machine to "Kubernetes Services" which is hosted on Alibaba Cloud.
Step 1: To install "kubectl" on local machine, go to Alibaba Cloud Console Portal Link. select you "cluster" and click on "Manage" of your Kubernetes cluster.
Step 2: Scroll down and navigate to "Cluster Resource" Section and copy the key (kube config code).
Note:
Step 3: Go to your local machine, If you do not already have kubectl installed in your CLI. Open PowerShell/ CMD (as administrator) and install Chocolatey. Run the following command:
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))
Note: I'm installing using Chocolatey method, you choose method your choice Link
Step 4: Install "kubectl" Run the below command:
choco install kubernetes-cli
To check "kubectl" version, type the command below:
kubectl version
Step 5: Change the path of to your directory and create a "config file" store connection Link, follow the commands below:
Below command will show your home and you need to keep the config fie there.
echo $HOME
cd C:\
mkdir C:\Kubelet\ .kube
cd C:\Kubelet\ .kube
New-Item config -type file
Step 6: Now go back to the cluster, browse for "KubeConfig", copy the value and paste it in on local "config" file.
Note: The config file on the mentioned path is used as the authentication for Kubernetes Service to communicate with your local machine.
Step 7: Now type the below command to check whether you are connected you Kubernetes cluster.
kubectl cluster-info
You can leverage Cloud Shell's functionality to create CusterRole, service, applications, pods, etc from local machine. In next topic will see how Cloud Shell help us create "secret" key which can store sensitive information. Like SQL Server "sa" Password etc.
You can configure a SQL Server instance on container using Kubernetes Service, with persistent storage for high availability (HA). The solution also provides high resilience. If the SQL Server instance fails, Kubernetes automatically re-creates it in a new pod. Kubernetes also provides resiliency against a node failure. In this demo we are going to deploy the resources though Kubernetes dashboard in Alibaba Cloud.
Step 1: Create an SA password.
Kubernetes can manage sensitive configuration information, like passwords as secrets.
The following command creates a password for the SA account:
kubectl create secret generic mssql --from-literal=SA_PASSWORD="Pass@123db"
Note: You can also create and verify from console under "secret" by opening "dashboard" of your "Kubernetes Cluster".
To createSecret on Kubernetes Services, open select dashboard of your Kubernetes cluster.
Step 2: Create a persistent storage:
Create a manifest/ docker deployment script to define the storage class and the persistent volume claim, which specifies the storage provisioner, parameters, and reclaim policy.
Note: Make sure you replace "storage class" in the below script. You can get your storage classes name as shown below
Below mentioned code represents an Alibaba disk with 30GB storage of type standard SSD.
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: mssql-data
spec:
storageClassName: alicloud-disk-ssd #Change the Storage Class value
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 30Gi
Step 3: To deploy the Persistent Volume Claim on Kubernetes Services, open select dashboard of your Kubernetes cluster.
Step 4: Click on "Create" and paste the script, or you can save the above script as yaml file and upload the script. Link 1
Step 5: Once the deployment is successful, navigate to "Persistent Volumes Claims" blade and you can see the disk which is being created.
Step 6: Create a SQL Server which uses the persistent storage to store the database:
Create a manifest/ docker deployment script which describe the container based on the SQL Server mssql-server-linux Docker image (make sure it fetches password from the secret created).
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: mssql-deployment
spec:
replicas: 1
template:
metadata:
labels:
app: mssql
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mssql
image: microsoft/mssql-server-linux
ports:
- containerPort: 1433
env:
- name: ACCEPT_EULA
value: "Y"
- name: SA_PASSWORD
valueFrom:
secretKeyRef:
name: mssql
key: SA_PASSWORD
volumeMounts:
- name: mssql-data
mountPath: /var/opt/mssql
volumes:
- name: mssql-data
persistentVolumeClaim:
claimName: mssql-data
---
apiVersion: v1
kind: Service
metadata:
name: mssql-deployment
spec:
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
type: LoadBalancer
Step 7: To deploy the SQL Services on a container of Kubernetes Services, go to your Kubernetes cluster and select "dashboard"
Step 8: click on "Create" and paste the script, or you can save the above script as yaml file and upload the script. Link 2
Step 9: To check the deployment status, go to "Deployments" blade and check for the deployment name, if deployment is successful you should see a green check as shown below.
Step 10: Go to Services blade to check your SQL Service and collect the Public IP.
Step 11: Now connect to SQL Server using SQL Server Management Tool (SSMS).
Now you have deployed SQL Server on kubernetes container with persistent storage and load balancer. SQL Server "SA" login password is stored in a secret vault, which makes it easy for you to swap whenever necessary. For monitoring purpose, navigate to "Overview" blade and check the status and heath of the nodes, services and pods.
How to Deploy MySQL Server in Alibaba Container Service using VSTS
2,599 posts | 758 followers
FollowAlibaba Clouder - June 9, 2020
Alibaba Clouder - August 31, 2018
Xi Ning Wang - August 16, 2018
H Ohara - September 1, 2023
Aliware - March 19, 2021
Alibaba Clouder - November 25, 2020
2,599 posts | 758 followers
FollowAlibaba Cloud Container Service for Kubernetes is a fully managed cloud container management service that supports native Kubernetes and integrates with other Alibaba Cloud products.
Learn MoreElastic and secure virtual cloud servers to cater all your cloud hosting needs.
Learn MoreLearn More
More Posts by Alibaba Clouder
Dikky Ryan Pratama June 23, 2023 at 8:46 am
awesome!