Built-in CI/CD
with Docker, K8s, Jenkins and AKS
Who am I?
Pau
@netcorebcn
@netcorebcn
netcorebcn.group
Who is doing
Continuous Integration?
@netcorebcn
Who is doing Continuous
Delivery/Deployment?
@netcorebcn
Big Team, Legacy, Manual Tests
@netcorebcn
CI/CD Smells
Devops or CI/CD Department
@netcorebcn
CI/CD Smells
Hard to run CI/CD Pipelines locally
@netcorebcn
CI/CD Smells
@netcorebcn
https://technologyconversations.com/2017/03/06/the-ten-commandments-of-continuous-delivery/
How to start CI/CD?
@netcorebcn
LOCAL DEVELOPMENT ENVIRONMENT
FIRST
@netcorebcn
Choose your tools
• Docker
• Minikube - local K8s
• AKS - Azure managed K8s
• Jenkins
• Bash
@netcorebcn
Example: Quiz Application
@netcorebcn
quiz-ui
quiz-commands quiz-queries
MessageBroker
@netcorebcn
db
Using a local k8s cluster
$ minikube start
$ minikube dashboard
$ minikube stop
@netcorebcn
minikube local node: namespaces
@netcorebcn
CI Staging Production
Create namespaces
$ kubectl create namespace ci
$ kubectl create namespace staging
$ kubectl create namespace production
@netcorebcn
minikube local node: secrets
@netcorebcn
CI Staging Production
${JENKINS_PASS}
${REGISTRY_PASS}
${GITHUB_TOKEN}
${DB_CONNECTION}
${MESSAGE_BROKER}
${DB_CONNECTION}
${MESSAGE_BROKER}
Create secrets
$ kubectl create secret quiz-secrets 
—from-literal= 
dbconnection=${DB_CONNECTION} 
—namespace staging
@netcorebcn
minikube local node: ci pods
@netcorebcn
CI Staging Production
registry
jenkins
Deploy private registry
$ kubectl apply -f registry.yml —namespace ci
@netcorebcn
Jenkins Dockerfile
@netcorebcn
FROM Jenkins:lts
INSTALL DOCKER CLI
INSTALL KUBERNETES CLI
JENKINS PLUGINS
GROOVY SCRIPTS
build, push and deploy jenkins
$ docker-compose build
$ docker-compose push
$ ./deploy.sh ci jenkins-ci
@netcorebcn
Jenkinsfile CI/CD Pipeline
@netcorebcn
Checkout
TAG=commit-sha
Build.sh Push.sh
${TAG} ${REGISTRY} ${ENVIRONMENT}
Deploy.sh
ENVIRONMENT=Staging
Integration-tests.sh
Deploy.sh
ENVIRONMENT=Production
@netcorebcn
Jenkinsfile
minikube local node: build and push
@netcorebcn
CI Staging Production
registry
jenkins
3.Push1.Checkout
2.Build
Build Process
@netcorebcn
Jenkinsfile Docker-compose.yml
Dockerfile
Dockerfile
Dockerfile
quiz-commands
quiz-queries
quiz-ui
Build with docker compose
@netcorebcn
Quiz Commands
Dockerfile
Quiz Queries
Dockerfile
Quiz UI
Dockerfile
${MainProject}
${Libraries}
${UnitTests}
${MainProject}
${Libraries}
${UnitTests} ${MainProject}
Quiz UI
Image
Quiz Queries
Image
Quiz Commands
Image
@netcorebcn
docker-compose.yml
Dockerfile multistage builds
FROM dotnet:sdk 1,4 GB
@netcorebcn
FROM dotnet:runtime 170 MB
STAGE 2
COPY Published App
COPY Source Code
dotnet restore
dotnet test
dotnet publish
STAGE 1
quiz-commands
200 MB
RESULT
@netcorebcn
STAGE 1
STAGE 2
Dockerfile
minikube local node: integration tests
@netcorebcn
CI Staging Production
registry
jenkins
quiz-queries
quiz-ui
quiz-commands
broker
integration
tests
4.Deploy
minikube local node: deploy
@netcorebcn
CI Staging Production
registry
jenkins
quiz-queries
quiz-ui
quiz-commands
broker
quiz-queries
quiz-ui
quiz-commands
broker
integration
tests5.Deploy
AKS
Azure Managed Kubernetes
@netcorebcn
Using aks k8s cluster
$ az aks get-credentials —resource-group —name
$ az aks browse
$ az aks show
$ az aks upgrade
@netcorebcn
How to deploy to AKS?
@netcorebcn
broker
quiz-result
quiz-ui
quiz-voting
jenkins
Quiz app with built-in CI/CD architecture in Azure
@netcorebcn
broker
quiz-result
quiz-ui
quiz-voting
Staging
Production
CI
integration
tests
quiz.westeurope.cloudapp.azure.com
github.com/netcorebcn/quiz
@netcorebcn
Thanks!
Questions?
netcorebcn.group
@netcorebcn

Build in continuous integration, delivery and deploy