High Level Architecture Diagram:
Data Flow :
- Developer Checkin Code to Github
- Create a AzureDevOps Pipeline trigger and stages
- CI Pipeline will build the images and push to container registry either Azure Container Registry or Docker Hub
- CD Pipeline will deploy the images from container registry to Azure Kubernetes
- Connect to SQL Linux container and check where the data is stored.
- Provision Azure Windows 10 EnterpriseN, Verion 1809 , VM Size: DS2_V3
- Install HyPer-V and Containers Role
- Install Docker for Windows
https://docs.docker.com/docker-for-windows/install/
- Install VS2019 Community Edition
https://visualstudio.microsoft.com/vs/compare/
- Install SQL Express 2017
https://www.microsoft.com/en-us/download/details.aspx?id=55994
- Install SSMS
https://docs.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms?redirectedfrom=MSDN&view=sql-server-ver15
- Install NodeJS
https://nodejs.org/en/download/
docker-compose -f "C:\_1\Web01\docker-compose.yml" -f "C:\_1\Web01\docker-compose.override.yml" up -d
docker ps
docker images
docker-compose down
az login
az group create --name devRG --location eastus
az acr create --resource-group devRG --name dev2acr --sku Basic --admin-enabled true
az acr login --name dev02acr
az acr show --name dev02acr --query loginServer --output table
docker tag web01 dev02acr.azurecr.io/web01aspnetcore-app:v1
docker tag microsoft/mssql-server-linux dev02acr.azurecr.io/sqllinux:v1
docker push dev02acr.azurecr.io/web01aspnetcore-app:v1
docker push dev02acr.azurecr.io/sqllinux:v1
az acr repository list --name dev02acr --output table
az acr repository show-tags --name dev02acr --repository web01aspnetcore-app --output table
docker login
docker container list -a
docker tag web01 gbbuenaflor/web01aspnetcore-app:v1
docker tag microsoft/mssql-server-linux gbbuenaflor/sqllinux:v1
docker images
docker push gbbuenaflor/web01aspnetcore-app:v1
docker push gbbuenaflor/sqllinux:v1
az aks get-credentials --resource-group $resourcegroup --name $clusterName
kubectl version
kubectl get nodes
kubectl get ns
kubectl get services
kubectl get services --namespace=kube-system
kubectl get config get-clusters
$resourcegroup='devRG'
$clusterName='DevAKSCluster'
kubectl get proxy
az aks browse --resource-group $resourcegroup --name $clusterName
az aks browse --resource-group Dev02 --name DevAKSCluster
echo -n 'admin' | base64
echo -n 'Server=mssql-service;Database=Web01DB;User=SA;Password=VM12345!@#12345;' | base64 > ./web01ConnectionString.txt
Get-Content ./web01ConnectionString.txt
U2VydmVyPW1zc3FsLXNlcnZpY2U7RGF0YWJhc2U9V2ViMDFEQjtVc2VyPVNBO1Bhc3N3b3JkPVZNMTIzNDUhQCMxMjM0NTsK
View : https://kubernetes.io/docs/concepts/configuration/secret/
gbbuenaflor/web01aspnetcore-app:v1
gbbuenaflor/sqllinux:v1
microsoft/mssql-server-linux
kubectl apply -f 01mssql-secret.yaml --record
kubectl apply -f 02mssql-config-map.yaml --record
kubectl apply -f 03mssql-pv.azure.yaml --record
kubectl apply -f 04mssql-deployment.yaml --record
kubectl apply -f 04mssql-deployment-ext.yaml --record
kubectl apply -f 05mvc-deployment.azure.yaml --record
kubectl get ns
kubectl get pods --namespace=default
kubectl get service --namespace=default
kubectl get pvc --namespace=default
kubectl get replicaset
kubectl rollout status deployment mvc-deployment
kubectl rollout status deployment mssql-deployment
$resourcegroup='devRG'
$clusterName='DevAKSCluster'
az aks browse --resource-group $resourcegroup --name $clusterName
- Login to Dev Machine
- Get SQl Load Balancer IP
kubectl get svc
- Connect to SQL Linux via SSMS
ServerName : 52.188.75.41,1433
Authentication : SQL Server Authentication
Login : sa
Password : [Password provided in the config file]
cd /usr/csuser/clouddrive/Web01.kubernetes.Helm/
helm init
helm version
helm package helm-web01
helm install helm-web01 --name helm-web01
kubectl get ns
helm status helm-web01
kubectl get services --namespace=helm-web01
kubectl get pods --namespace=helm-web01
kubectl get rs --namespace=helm-web01
helm history helm-web01
helm rollback helm-web01 1
helm del --purge helm-web01;
helm delete --purge helm-web01;
trigger:
- master
resources:
- repo: self
variables:
tag: '$(Build.BuildId)'
- stage: Build
....
- stage: Deploy
....
3. CI Pipeline will build the images and push to container registry either Azure Container Registry or Docker Hub
# -----------------------------------------------------
# Build Docker Image and Publish the K8S Files
# -----------------------------------------------------
- stage: Build
displayName: Build image
jobs:
- job: Build
displayName: Build
pool:
vmImage: 'ubuntu-latest'
steps:
- task: Docker@2
inputs:
containerRegistry: 'dockerhubconnection'
repository: 'gbbuenaflor/Web01Aks'
command: 'buildAndPush'
Dockerfile: '$(Build.SourcesDirectory)/Web01/Dockerfile'
tags: '$(tag)'
- task: CopyFiles@2
inputs:
SourceFolder: '$(System.DefaultWorkingDirectory)/Web01.kubernetes.Azure'
Contents: '$(System.DefaultWorkingDirectory)/Web01.kubernetes.Azure/*.yaml'
TargetFolder: '$(Build.ArtifactStagingDirectory)/Web01.kubernetes.Azure'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'manifests'
publishLocation: 'Container'
# -----------------------------------------------------
# Download the K8S Files and deploy Docker Image to AKS Cluster
# -----------------------------------------------------
- stage: Deploy
displayName: Deploy image
jobs:
- job: Deploy
displayName: Deploy
pool:
vmImage: 'ubuntu-latest'
steps:
- task: DownloadPipelineArtifact@2
inputs:
buildType: 'current'
artifactName: 'manifests'
itemPattern: '**/*.yaml'
targetPath: '$(System.ArtifactsDirectory)'
- task: KubernetesManifest@0
inputs:
action: 'deploy'
kubernetesServiceConnection: 'AzureKubernetesConnection'
namespace: 'default'
manifests: '$(System.DefaultWorkingDirectory)/Web01.kubernetes.Azure/06webandsqldeployment.yaml'
containers: 'gbbuenaflor/Web01Aks:$(tag)'
#-----------------------------------------------------------------
# Kubernetes - Service for SQL Linux - Internal
#-----------------------------------------------------------------
---
apiVersion: v1
kind: Service
metadata:
name: mssql-service-int
namespace: default
spec:
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
nodePort: 30200
type: NodePort
---
apiVersion: v1
kind: Service
metadata:
name: mssql-service-ext
namespace: default
spec:
selector:
app: mssql
ports:
- protocol: TCP
port: 1433
targetPort: 1433
type: LoadBalancer
#-----------------------------------------------------------------
# Kubernetes - Deployment for SQL Linux
#-----------------------------------------------------------------
---
apiVersion: apps/v1beta1
kind: Deployment
metadata:
name: mssql-deployment
namespace: default
spec:
replicas: 1
template:
metadata:
labels:
app: mssql
spec:
terminationGracePeriodSeconds: 10
containers:
- name: mssql
image: microsoft/mssql-server-linux
resources:
limits:
cpu: "2"
memory: "2Gi"
requests:
cpu: "0.5"
ports:
- containerPort: 1433
env:
- name: ACCEPT_EULA
value: "Y"
- name: SA_PASSWORD
value: "<Password Here>"
volumeMounts:
- name: mssql-persistent-storage
mountPath: /var/opt/mssql
volumes:
- name: mssql-persistent-storage
persistentVolumeClaim:
claimName: mssql-pv-claim
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: mssql-pv-claim
annotations:
volume.beta.kubernetes.io/storage-class: azure-disk
spec:
storageClassName: default
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 1Gi
Microsoft Azure Container Ecosystem - "nugget series" > Click this Link
Note: My Favorite -> Microsoft :D