SlideShare une entreprise Scribd logo
1  sur  24
Télécharger pour lire hors ligne
Kranthi Kumar- CI/CD Notes
1
Table of Contents
1. Source Control Management- = GIT .........................................................................................................2
2. Introducing Build Automation (GRADLE)..................................................................................................2
Commands used to install and run the Gradle Wrapper:.........................................................................3
Gradle Wrapper Command.......................................................................................................................3
Defining Tasks ...........................................................................................................................................3
Task Dependencies ...................................................................................................................................3
Plugins.......................................................................................................................................................4
Running Automated Test in Gradle...........................................................................................................4
3. Jenkins Pipelines .......................................................................................................................................4
Continuous Delivery..................................................................................................................................4
Automated Deployment in Pipeline .........................................................................................................5
4. Why Containers?.......................................................................................................................................5
Installing Docker .......................................................................................................................................6
Running with Docker in Production..........................................................................................................8
Installing Docker on Jenkins......................................................................................................................8
Jenkins Pipelines CD and a Dockerized App..............................................................................................9
Jenkins Pipelines CD and a Dockerized App..............................................................................................9
5. Orchestration..........................................................................................................................................10
Creating a Kubernetes Cluster ................................................................................................................11
Kubernetes Basics ...................................................................................................................................13
Deploying to Kubernetes with Jenkins....................................................................................................14
6. Monitoring ..............................................................................................................................................14
Cluster Monitoring..................................................................................................................................16
Application Monitoring...........................................................................................................................17
7. Kubernetes and Self-Healing..................................................................................................................17
Creating Liveness Probes in Kubernetes.................................................................................................18
8. Kubernetes and Autoscaling ...................................................................................................................20
Horizontal Pod Autoscalers in Kubernetes .............................................................................................20
9. What is Canary Testing?..........................................................................................................................21
Page 2 of 24
Implementing a Canary Test in Kubernetes............................................................................................23
Kubernetes Canary Testing with Jenkins Pipelines.................................................................................24
1. Source Control Management- = GIT
1. yum install git
2. git --version
3. git config --global user.name "kranthi"
4. git config --global user.email kk@kranthi.com
5. git clone repository URL
6. git status
7. git add <file name> or git add . or git add -A
8. git commit -m "< commit message >"
9. git push or git push -u < remote name, usually origin > < branch name >
10.git checkout <existing branch name>
11.git checkout -b <new branch name>
12.git branch
13.git tag <new tag name>
14.git tag
15.git pull
2. Introducing Build Automation (GRADLE)
You can find more information about installing Gradle at https://gradle.org/install/
Here are the commands used in the demo to install gradle:
Command 1 --> cd ~/
Command 2 --> wget -O ~/gradle-4.7-bin.zip https://services.gradle.org/distributions/gradle-
4.7-bin.zip
Command 3 --> sudo yum -y install unzip java-1.8.0-openjdk
Command 4 --> sudo mkdir /opt/gradle
Command 5 --> sudo unzip -d /opt/gradle/ ~/gradle-4.7-bin.zip
Command 6 --> sudo vi /etc/profile.d/gradle.sh
Command 7 --> Put this text into gradle.sh: export PATH=$PATH:/opt/gradle/gradle-4.7/bin
Command 8 --> Then set permissions on gradle.sh: sudo chmod 755 /etc/profile.d/gradle.sh
Page 3 of 24
Command 9 --> Finally, after logging out of the server and logging back in:gradle --version
2.1 Commands used to install and run the Gradle Wrapper:
Gradle wrapper allows gradle to install itself using just the files from your project's source
control.
Wrapper is useful because
1. it removes the need to have Gradle installed beforehand in order to run the build.
2. Ensure the project is always built with a specific version of Gradle
3. Lets you build multiple projects with different Gradle versions on one system.
4. Anyone can run the build quickly and easily
2.2 Gradle Wrapper Command
cd ~/
mkdir my-project
cd my-project
gradle wrapper
./gradlew build
2.3 Defining Tasks
The build.gradle file controls what tasks are available for your project.
You can define your own task with custom code in build.gradle:
task my Task {
Print ‘Hellow, World’}
Most of tasks you use will come built into either Gradle itself or plugins.
2.4 Task Dependencies
Gradle uses the concept of task dependencies to determine what tasks need to be run for a
particular build command:
 If you run a task, any other task depend on it will also be run
Task dependencies also determines the order in which tasks get run:
 A task’s dependencies will always run before that task
You can define a dependency relationship between tasks in build.gradle like this:
 Task A.dependson anotherTask B
Here is the final build.gradle from the demo:
plugins {
id 'com.moowork.node' version '1.2.0'
}
task sayHello {
doLast {
println 'Hello, World!'
Page 4 of 24
}
}
task anotherTask {
doLast {
println 'This is another task'
}
}
If you have the gradle wrapper installed in your project (for example, by using gradle
init), you can run the build defined in this build.gradle like so:
./gradlew sayHello
2.5 Plugins
Gradle has a huge variety of plugin available, many of them contributed by the community.
Plugins add all kinds of functionality to Gradle. They usually include pre-built tasks that you can
configure to do what you need.
You can include plugins in your build.gradle like this:
Plugins {
Id “<plugin-id>” version “<plugin version>”
}
2.6 Running Automated Test in Gradle
Generally, automated test will be run in Gradle as a task that gets executed as part of the build
process:
 Task build
 Task test
 Build.dependensOn test
Whenever ./gradlew build gets run, the test task also will run.
3. Jenkins Pipelines
Pipelines has a domain-specific-language (DSL) that is used to define the pipeline logic.
There are two types of pipeline syntax you can use
 Scripted A bit more like procedural code
 Declarative – Syntax describes the pipeline logic
3.1 Continuous Delivery
Page 5 of 24
Continuous delivery means ensuring that you are always able to deploy any version of your
code. It is necessary in Continuous deployment, where you are actually deploying your code
frequently.
In order to support continuous delivery/Deployment with a Jenkin pipelines, we need use the
Pipeline to automate the deployment process.
3.2 Automated Deployment in Pipeline
 Define stages for stages of the CD process that involves deploying.
 Deploy to UAT, Deploy to QA, Deploy to Staging and Deploy to
Production
 In each deployment stage, define Steps that perform necessary tasks to carry out
the deployment
 Copy files to a server, restart a service
 We can also prompt a user for approval before performing the actual production
deployment.
 sudo yum -y remove java
 sudo yum -y install java-1.8.0-openjdk
 sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat
-stable/jenkins.repo
 sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
 sudo yum -y install jenkins-2.164.2
 sudo systemctl enable jenkins
 sudo systemctl start jenkins
4. Why Containers?
Page 6 of 24
4.1 Installing Docker
Install  sudo yum -y install docker
 Sudo systemctl start docker
Page 7 of 24
Page 8 of 24
4.2 Running with Docker in Production
4.3 Installing Docker on Jenkins
Here are the commands used in the demo for this lesson:
sudo yum -y install docker
Page 9 of 24
sudo systemctl start docker
sudo systemctl enable docker
sudo groupadd docker
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
sudo systemctl restart docker
4.4 Jenkins Pipelines CD and a Dockerized App
You can find the source code of the train-schedule app
here: https://github.com/linuxacademy/cicd-pipeline-train-schedule-dockerdeploy
And you can find the final version of the Jenkinsfile from the demo on the example-
solution branch of that project here: https://github.com/linuxacademy/cicd-pipeline-
train-schedule-dockerdeploy/blob/example-solution/Jenkinsfile
4.5 Jenkins Pipelines CD and a Dockerized App
Page 10 of 24
5. Orchestration
Page 11 of 24
5.1 Creating a Kubernetes Cluster
Page 12 of 24
You can find instructions on various ways of installing Kubernetes
here: https://kubernetes.io/docs/setup/
Installation instructions specific to kubeadm can he found
here: https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/
You can initialize the master node in kubeadm by creating a config file called kube-
config.yml with these contents:
apiVersion: kubeadm.k8s.io/v1alpha3
kind: ClusterConfiguration
networking:
podSubnet: 10.244.0.0/16
apiServerExtraArgs:
service-node-port-range: 8000-31274
Then run this command referencing that file:
kubeadm init --config kube-config.yml
Use this command to set up a pod network after initializing the master with kubeadm
init:
kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ec
e4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
Page 13 of 24
5.2 Kubernetes Basics
You can find more detailed documentation on some of the concepts discussed
here: https://kubernetes.io/docs/concepts/#kubernetes-objects
Page 14 of 24
5.3 Deploying to Kubernetes with Jenkins
This demonstration uses the Kubernetes Continuous Deploy plugin to deploy to
Kubernetes from Jenkins. You can find additional documentation about that plugin
here: https://jenkins.io/doc/pipeline/steps/kubernetes-cd.
If you want to follow along, you can find the sample source code
here: https://github.com/linuxacademy/cicd-pipeline-train-schedule-kubernetes.
6. Monitoring
For more information about these monitoring tools, check out their official sites:
 Prometheus - https://prometheus.io/
 Grafana - https://grafana.com/
The first step toward using Prometheus and Grafana to gather metrics within
Kubernetes is to install them. walks you through the process of installing Prometheus
and Grafana in your Kubernetes cluster. After completing this lesson, you will know how
to quickly install Prometheus and Grafana using Helm.
Since there are quite a few commands involved in this installation, here is a reference
guide for the commands used to perform the installation in this lesson:
Page 15 of 24
curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > /tmp/get_
helm.sh
chmod 700 /tmp/get_helm.sh
DESIRED_VERSION=v2.8.2 /tmp/get_helm.sh
helm init --wait
kubectl --namespace=kube-system create clusterrolebinding add-on-cluster-admin --clus
terrole=cluster-admin --serviceaccount=kube-system:default
helm ls
cd ~/
git clone https://github.com/kubernetes/charts
cd charts
git checkout efdcffe0b6973111ec6e5e83136ea74cdbe6527d
cd ../
vi prometheus-values.yml
prometheus-values.yml:
alertmanager:
persistentVolume:
enabled: false
server:
persistentVolume:
enabled: false
Then run:
helm install -f prometheus-values.yml charts/stable/prometheus --name prometheus --na
mespace prometheus
vi grafana-values.yml
grafana-values.yml:
adminPassword: password
Then run:
helm install -f grafana-values.yml charts/stable/grafana/ --name grafana --namespace
grafana
vi grafana-ext.yml
grafana-ext.yml:
Page 16 of 24
kind: Service
apiVersion: v1
metadata:
namespace: grafana
name: grafana-ext
spec:
type: NodePort
selector:
app: grafana
ports:
- protocol: TCP
port: 3000
nodePort: 8080
Then run:
kubectl apply -f grafana-ext.yml
You can check on the status of the prometheus and grafana pods with these
commands:
kubectl get pods -n prometheus
kubectl get pods -n grafana
When setting up your dastasource in grafana, use this url:
http://prometheus-server.prometheus.svc.cluster.local
6.1 Cluster Monitoring
Page 17 of 24
6.2 Application Monitoring
Here is the sample source code for the train schedule app that was used in the
demo: https://github.com/linuxacademy/cicd-pipeline-train-schedule-monitoring
And here is a direct link to the Kubernetes template yml file that was used to deploy the
app: https://github.com/linuxacademy/cicd-pipeline-train-schedule-
monitoring/blob/master/train-schedule-kube.yml
7. Kubernetes and Self-Healing
For more information, check out the Kubernetes documentation on pod lifecycle and
restart policies: https://kubernetes.io/docs/concepts/workloads/pods/pod-
lifecycle/#restart-policy.
Page 18 of 24
7.1 Creating Liveness Probes in Kubernetes
For more information on Kubernetes liveness probes, check out their
documentation: https://kubernetes.io/docs/tasks/configure-pod-container/configure-
liveness-readiness-probes/.
Here is the final Kubernetes template file used in the demo (train-schedule-kube.yml):
kind: Service
apiVersion: v1
metadata:
name: train-schedule-service
annotations:
prometheus.io/scrape: 'true'
spec:
type: NodePort
selector:
app: train-schedule
ports:
Page 19 of 24
- protocol: TCP
port: 8080
nodePort: 8080
---
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: train-schedule-deployment
labels:
app: train-schedule
spec:
replicas: 2
selector:
matchLabels:
app: train-schedule
template:
metadata:
labels:
app: train-schedule
spec:
containers:
- name: train-schedule
image: linuxacademycontent/train-schedule:selfhealing
ports:
- containerPort: 8080
livenessProbe:
httpGet:
path: /
port: 8080
initialDelaySeconds: 15
timeoutSeconds: 1
Page 20 of 24
periodSeconds: 10
8. Kubernetes and Autoscaling
8.1 Horizontal Pod Autoscalers in Kubernetes
full HPA documentation: https://kubernetes.io/docs/tasks/run-application/horizontal-pod-
autoscale/
Here is the GitHub repo for the source code used in the demo. Check the example-
solution branch for the demo's final state: https://github.com/linuxacademy/cicd-
pipeline-train-schedule-autoscaling
Page 21 of 24
Here are the commands used to set up the autoscaler in the demo:
cd ~/
git clone https://github.com/kubernetes-incubator/metrics-server.git
cd metrics-server/
kubectl create -f deploy/1.8+/
kubectl get --raw /apis/metrics.k8s.io/
cd ~/
git clone
cd cicd-pipeline-train-schedule-autoscaling/
vi train-schedule-kube.yml
kubectl apply -f train-schedule-kube.yml
You can find the changes made to train-schedule-kube.yml in the example-
solution branch of the GitHub repo. Once you have deployed the app and the
HPA, you can generate CPU load to test it by spinning up a busybox shell:
kubectl run -i --tty load-generator --image=busybox /bin/sh
Then run this in the busybox shell to create load:
while true; do wget -q -O- http://:8080/generate-cpu-load; done
9. What is Canary Testing?
Page 22 of 24
Page 23 of 24
8.2 Implementing a Canary Test in Kubernetes
You can find the sample source code that was used in this demo
here: https://github.com/linuxacademy/cicd-pipeline-train-schedule-canary
Be sure to check out the example-solution branch to find the canary deployment
template in train-schedule-kube-canary.yml.
Here are the commands used to deploy the stable and canary pods in the demo:
cd ~/
git clone
cd cicd-pipeline-train-schedule-canary/
Page 24 of 24
kubectl apply -f train-schedule-kube.yml
vi train-schedule-kube-canary.yml
kubectl apply -f train-schedule-kube-canary.yml
8.3 Kubernetes Canary Testing with Jenkins Pipelines

Contenu connexe

Tendances

Day3 Quartus II Tutorial
Day3 Quartus II TutorialDay3 Quartus II Tutorial
Day3 Quartus II TutorialRon Liu
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresFrits Van Der Holst
 
Openstack Third-Party CI and the review of a few Openstack Infrastructure pro...
Openstack Third-Party CI and the review of a few Openstack Infrastructure pro...Openstack Third-Party CI and the review of a few Openstack Infrastructure pro...
Openstack Third-Party CI and the review of a few Openstack Infrastructure pro...Evgeny Antyshev
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionSchalk Cronjé
 
Custum GNU/Linux Kali distribution
Custum GNU/Linux Kali distribution Custum GNU/Linux Kali distribution
Custum GNU/Linux Kali distribution Mohamed BENCHENOUF
 
Fosdem'20_Past, present & future of DRLM project
Fosdem'20_Past, present & future of DRLM projectFosdem'20_Past, present & future of DRLM project
Fosdem'20_Past, present & future of DRLM projectDidac Oliveira
 
Modernize Your Drupal Development
Modernize Your Drupal DevelopmentModernize Your Drupal Development
Modernize Your Drupal DevelopmentChris Tankersley
 
2010 13.guide de_la_programmation_avec_qgis_1.5_extensions_et_applications_pr...
2010 13.guide de_la_programmation_avec_qgis_1.5_extensions_et_applications_pr...2010 13.guide de_la_programmation_avec_qgis_1.5_extensions_et_applications_pr...
2010 13.guide de_la_programmation_avec_qgis_1.5_extensions_et_applications_pr...Eduardo Nuno
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackKAI CHU CHUNG
 

Tendances (11)

Day3 Quartus II Tutorial
Day3 Quartus II TutorialDay3 Quartus II Tutorial
Day3 Quartus II Tutorial
 
Build server
Build serverBuild server
Build server
 
Moving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventuresMoving from Jenkins 1 to 2 declarative pipeline adventures
Moving from Jenkins 1 to 2 declarative pipeline adventures
 
Openstack Third-Party CI and the review of a few Openstack Infrastructure pro...
Openstack Third-Party CI and the review of a few Openstack Infrastructure pro...Openstack Third-Party CI and the review of a few Openstack Infrastructure pro...
Openstack Third-Party CI and the review of a few Openstack Infrastructure pro...
 
Gradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 versionGradle in 45min - JBCN2-16 version
Gradle in 45min - JBCN2-16 version
 
Custum GNU/Linux Kali distribution
Custum GNU/Linux Kali distribution Custum GNU/Linux Kali distribution
Custum GNU/Linux Kali distribution
 
Fosdem'20_Past, present & future of DRLM project
Fosdem'20_Past, present & future of DRLM projectFosdem'20_Past, present & future of DRLM project
Fosdem'20_Past, present & future of DRLM project
 
Modernize Your Drupal Development
Modernize Your Drupal DevelopmentModernize Your Drupal Development
Modernize Your Drupal Development
 
GWT_Framework
GWT_FrameworkGWT_Framework
GWT_Framework
 
2010 13.guide de_la_programmation_avec_qgis_1.5_extensions_et_applications_pr...
2010 13.guide de_la_programmation_avec_qgis_1.5_extensions_et_applications_pr...2010 13.guide de_la_programmation_avec_qgis_1.5_extensions_et_applications_pr...
2010 13.guide de_la_programmation_avec_qgis_1.5_extensions_et_applications_pr...
 
Gdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpackGdg cloud taipei ddt meetup #53 buildpack
Gdg cloud taipei ddt meetup #53 buildpack
 

Similaire à Kranthi kumar implement_ci_cd_my_notes

Radiomic Features.pdf
Radiomic Features.pdfRadiomic Features.pdf
Radiomic Features.pdfLallHussain
 
Os dev tool box
Os dev tool boxOs dev tool box
Os dev tool boxbpowell29a
 
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5 Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5 William Lee
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-TranslatorDashamir Hoxha
 
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
 Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2   Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2 Adil Khan
 
Struts2 tutorial
Struts2 tutorialStruts2 tutorial
Struts2 tutorializdihara
 
Docker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for DevelopersDocker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for DevelopersRapidValue
 
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...Puppet
 
FOSDEM 2017: GitLab CI
FOSDEM 2017:  GitLab CIFOSDEM 2017:  GitLab CI
FOSDEM 2017: GitLab CIOlinData
 
Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01rhemsolutions
 
Lightweight Developer Provisioning with Gradle
Lightweight Developer Provisioning with GradleLightweight Developer Provisioning with Gradle
Lightweight Developer Provisioning with GradleQAware GmbH
 
Lightweight Developer Provisioning with Gradle and SEU-as-code
Lightweight Developer Provisioning with Gradle and SEU-as-codeLightweight Developer Provisioning with Gradle and SEU-as-code
Lightweight Developer Provisioning with Gradle and SEU-as-codeMario-Leander Reimer
 
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...Acquia
 
Continuous Integration & Development with Gitlab
Continuous Integration & Development with GitlabContinuous Integration & Development with Gitlab
Continuous Integration & Development with GitlabAyush Sharma
 
Gitlab ci e kubernetes, build test and deploy your projects like a pro
Gitlab ci e kubernetes, build test and deploy your projects like a proGitlab ci e kubernetes, build test and deploy your projects like a pro
Gitlab ci e kubernetes, build test and deploy your projects like a prosparkfabrik
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation ToolIzzet Mustafaiev
 
Android build on windows
Android build on windowsAndroid build on windows
Android build on windowsAddweup
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushPantheon
 
How to improve gradle build speed
How to improve gradle build speedHow to improve gradle build speed
How to improve gradle build speedFate Chang
 

Similaire à Kranthi kumar implement_ci_cd_my_notes (20)

Radiomic Features.pdf
Radiomic Features.pdfRadiomic Features.pdf
Radiomic Features.pdf
 
Os dev tool box
Os dev tool boxOs dev tool box
Os dev tool box
 
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5 Upgrade GCC & Install Qt 5.4 on CentOS 6.5
Upgrade GCC & Install Qt 5.4 on CentOS 6.5
 
Development Setup of B-Translator
Development Setup of B-TranslatorDevelopment Setup of B-Translator
Development Setup of B-Translator
 
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
 Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2   Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
Recipe to build open splice dds 6.3.xxx Hello World example over Qt 5.2
 
Struts2 tutorial
Struts2 tutorialStruts2 tutorial
Struts2 tutorial
 
Docker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for DevelopersDocker - A lightweight Virtualization Platform for Developers
Docker - A lightweight Virtualization Platform for Developers
 
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
How Puppet Enables the Use of Lightweight Virtualized Containers - PuppetConf...
 
FOSDEM 2017: GitLab CI
FOSDEM 2017:  GitLab CIFOSDEM 2017:  GitLab CI
FOSDEM 2017: GitLab CI
 
Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01Introduction maven3 and gwt2.5 rc2 - Lesson 01
Introduction maven3 and gwt2.5 rc2 - Lesson 01
 
Lightweight Developer Provisioning with Gradle
Lightweight Developer Provisioning with GradleLightweight Developer Provisioning with Gradle
Lightweight Developer Provisioning with Gradle
 
Lightweight Developer Provisioning with Gradle and SEU-as-code
Lightweight Developer Provisioning with Gradle and SEU-as-codeLightweight Developer Provisioning with Gradle and SEU-as-code
Lightweight Developer Provisioning with Gradle and SEU-as-code
 
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
Fast Paced Drupal 8: Accelerating Development with Composer, Drupal Console a...
 
Continuous Integration & Development with Gitlab
Continuous Integration & Development with GitlabContinuous Integration & Development with Gitlab
Continuous Integration & Development with Gitlab
 
Gitlab ci e kubernetes, build test and deploy your projects like a pro
Gitlab ci e kubernetes, build test and deploy your projects like a proGitlab ci e kubernetes, build test and deploy your projects like a pro
Gitlab ci e kubernetes, build test and deploy your projects like a pro
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Android build on windows
Android build on windowsAndroid build on windows
Android build on windows
 
Lean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and DrushLean Drupal Repositories with Composer and Drush
Lean Drupal Repositories with Composer and Drush
 
How to improve gradle build speed
How to improve gradle build speedHow to improve gradle build speed
How to improve gradle build speed
 
Struts2 tutorial
Struts2 tutorialStruts2 tutorial
Struts2 tutorial
 

Dernier

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Kranthi kumar implement_ci_cd_my_notes

  • 1. Kranthi Kumar- CI/CD Notes 1 Table of Contents 1. Source Control Management- = GIT .........................................................................................................2 2. Introducing Build Automation (GRADLE)..................................................................................................2 Commands used to install and run the Gradle Wrapper:.........................................................................3 Gradle Wrapper Command.......................................................................................................................3 Defining Tasks ...........................................................................................................................................3 Task Dependencies ...................................................................................................................................3 Plugins.......................................................................................................................................................4 Running Automated Test in Gradle...........................................................................................................4 3. Jenkins Pipelines .......................................................................................................................................4 Continuous Delivery..................................................................................................................................4 Automated Deployment in Pipeline .........................................................................................................5 4. Why Containers?.......................................................................................................................................5 Installing Docker .......................................................................................................................................6 Running with Docker in Production..........................................................................................................8 Installing Docker on Jenkins......................................................................................................................8 Jenkins Pipelines CD and a Dockerized App..............................................................................................9 Jenkins Pipelines CD and a Dockerized App..............................................................................................9 5. Orchestration..........................................................................................................................................10 Creating a Kubernetes Cluster ................................................................................................................11 Kubernetes Basics ...................................................................................................................................13 Deploying to Kubernetes with Jenkins....................................................................................................14 6. Monitoring ..............................................................................................................................................14 Cluster Monitoring..................................................................................................................................16 Application Monitoring...........................................................................................................................17 7. Kubernetes and Self-Healing..................................................................................................................17 Creating Liveness Probes in Kubernetes.................................................................................................18 8. Kubernetes and Autoscaling ...................................................................................................................20 Horizontal Pod Autoscalers in Kubernetes .............................................................................................20 9. What is Canary Testing?..........................................................................................................................21
  • 2. Page 2 of 24 Implementing a Canary Test in Kubernetes............................................................................................23 Kubernetes Canary Testing with Jenkins Pipelines.................................................................................24 1. Source Control Management- = GIT 1. yum install git 2. git --version 3. git config --global user.name "kranthi" 4. git config --global user.email kk@kranthi.com 5. git clone repository URL 6. git status 7. git add <file name> or git add . or git add -A 8. git commit -m "< commit message >" 9. git push or git push -u < remote name, usually origin > < branch name > 10.git checkout <existing branch name> 11.git checkout -b <new branch name> 12.git branch 13.git tag <new tag name> 14.git tag 15.git pull 2. Introducing Build Automation (GRADLE) You can find more information about installing Gradle at https://gradle.org/install/ Here are the commands used in the demo to install gradle: Command 1 --> cd ~/ Command 2 --> wget -O ~/gradle-4.7-bin.zip https://services.gradle.org/distributions/gradle- 4.7-bin.zip Command 3 --> sudo yum -y install unzip java-1.8.0-openjdk Command 4 --> sudo mkdir /opt/gradle Command 5 --> sudo unzip -d /opt/gradle/ ~/gradle-4.7-bin.zip Command 6 --> sudo vi /etc/profile.d/gradle.sh Command 7 --> Put this text into gradle.sh: export PATH=$PATH:/opt/gradle/gradle-4.7/bin Command 8 --> Then set permissions on gradle.sh: sudo chmod 755 /etc/profile.d/gradle.sh
  • 3. Page 3 of 24 Command 9 --> Finally, after logging out of the server and logging back in:gradle --version 2.1 Commands used to install and run the Gradle Wrapper: Gradle wrapper allows gradle to install itself using just the files from your project's source control. Wrapper is useful because 1. it removes the need to have Gradle installed beforehand in order to run the build. 2. Ensure the project is always built with a specific version of Gradle 3. Lets you build multiple projects with different Gradle versions on one system. 4. Anyone can run the build quickly and easily 2.2 Gradle Wrapper Command cd ~/ mkdir my-project cd my-project gradle wrapper ./gradlew build 2.3 Defining Tasks The build.gradle file controls what tasks are available for your project. You can define your own task with custom code in build.gradle: task my Task { Print ‘Hellow, World’} Most of tasks you use will come built into either Gradle itself or plugins. 2.4 Task Dependencies Gradle uses the concept of task dependencies to determine what tasks need to be run for a particular build command:  If you run a task, any other task depend on it will also be run Task dependencies also determines the order in which tasks get run:  A task’s dependencies will always run before that task You can define a dependency relationship between tasks in build.gradle like this:  Task A.dependson anotherTask B Here is the final build.gradle from the demo: plugins { id 'com.moowork.node' version '1.2.0' } task sayHello { doLast { println 'Hello, World!'
  • 4. Page 4 of 24 } } task anotherTask { doLast { println 'This is another task' } } If you have the gradle wrapper installed in your project (for example, by using gradle init), you can run the build defined in this build.gradle like so: ./gradlew sayHello 2.5 Plugins Gradle has a huge variety of plugin available, many of them contributed by the community. Plugins add all kinds of functionality to Gradle. They usually include pre-built tasks that you can configure to do what you need. You can include plugins in your build.gradle like this: Plugins { Id “<plugin-id>” version “<plugin version>” } 2.6 Running Automated Test in Gradle Generally, automated test will be run in Gradle as a task that gets executed as part of the build process:  Task build  Task test  Build.dependensOn test Whenever ./gradlew build gets run, the test task also will run. 3. Jenkins Pipelines Pipelines has a domain-specific-language (DSL) that is used to define the pipeline logic. There are two types of pipeline syntax you can use  Scripted A bit more like procedural code  Declarative – Syntax describes the pipeline logic 3.1 Continuous Delivery
  • 5. Page 5 of 24 Continuous delivery means ensuring that you are always able to deploy any version of your code. It is necessary in Continuous deployment, where you are actually deploying your code frequently. In order to support continuous delivery/Deployment with a Jenkin pipelines, we need use the Pipeline to automate the deployment process. 3.2 Automated Deployment in Pipeline  Define stages for stages of the CD process that involves deploying.  Deploy to UAT, Deploy to QA, Deploy to Staging and Deploy to Production  In each deployment stage, define Steps that perform necessary tasks to carry out the deployment  Copy files to a server, restart a service  We can also prompt a user for approval before performing the actual production deployment.  sudo yum -y remove java  sudo yum -y install java-1.8.0-openjdk  sudo wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat -stable/jenkins.repo  sudo rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key  sudo yum -y install jenkins-2.164.2  sudo systemctl enable jenkins  sudo systemctl start jenkins 4. Why Containers?
  • 6. Page 6 of 24 4.1 Installing Docker Install  sudo yum -y install docker  Sudo systemctl start docker
  • 8. Page 8 of 24 4.2 Running with Docker in Production 4.3 Installing Docker on Jenkins Here are the commands used in the demo for this lesson: sudo yum -y install docker
  • 9. Page 9 of 24 sudo systemctl start docker sudo systemctl enable docker sudo groupadd docker sudo usermod -aG docker jenkins sudo systemctl restart jenkins sudo systemctl restart docker 4.4 Jenkins Pipelines CD and a Dockerized App You can find the source code of the train-schedule app here: https://github.com/linuxacademy/cicd-pipeline-train-schedule-dockerdeploy And you can find the final version of the Jenkinsfile from the demo on the example- solution branch of that project here: https://github.com/linuxacademy/cicd-pipeline- train-schedule-dockerdeploy/blob/example-solution/Jenkinsfile 4.5 Jenkins Pipelines CD and a Dockerized App
  • 10. Page 10 of 24 5. Orchestration
  • 11. Page 11 of 24 5.1 Creating a Kubernetes Cluster
  • 12. Page 12 of 24 You can find instructions on various ways of installing Kubernetes here: https://kubernetes.io/docs/setup/ Installation instructions specific to kubeadm can he found here: https://kubernetes.io/docs/setup/independent/create-cluster-kubeadm/ You can initialize the master node in kubeadm by creating a config file called kube- config.yml with these contents: apiVersion: kubeadm.k8s.io/v1alpha3 kind: ClusterConfiguration networking: podSubnet: 10.244.0.0/16 apiServerExtraArgs: service-node-port-range: 8000-31274 Then run this command referencing that file: kubeadm init --config kube-config.yml Use this command to set up a pod network after initializing the master with kubeadm init: kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/bc79dd1505b0c8681ec e4de4c0d86c5cd2643275/Documentation/kube-flannel.yml
  • 13. Page 13 of 24 5.2 Kubernetes Basics You can find more detailed documentation on some of the concepts discussed here: https://kubernetes.io/docs/concepts/#kubernetes-objects
  • 14. Page 14 of 24 5.3 Deploying to Kubernetes with Jenkins This demonstration uses the Kubernetes Continuous Deploy plugin to deploy to Kubernetes from Jenkins. You can find additional documentation about that plugin here: https://jenkins.io/doc/pipeline/steps/kubernetes-cd. If you want to follow along, you can find the sample source code here: https://github.com/linuxacademy/cicd-pipeline-train-schedule-kubernetes. 6. Monitoring For more information about these monitoring tools, check out their official sites:  Prometheus - https://prometheus.io/  Grafana - https://grafana.com/ The first step toward using Prometheus and Grafana to gather metrics within Kubernetes is to install them. walks you through the process of installing Prometheus and Grafana in your Kubernetes cluster. After completing this lesson, you will know how to quickly install Prometheus and Grafana using Helm. Since there are quite a few commands involved in this installation, here is a reference guide for the commands used to perform the installation in this lesson:
  • 15. Page 15 of 24 curl https://raw.githubusercontent.com/kubernetes/helm/master/scripts/get > /tmp/get_ helm.sh chmod 700 /tmp/get_helm.sh DESIRED_VERSION=v2.8.2 /tmp/get_helm.sh helm init --wait kubectl --namespace=kube-system create clusterrolebinding add-on-cluster-admin --clus terrole=cluster-admin --serviceaccount=kube-system:default helm ls cd ~/ git clone https://github.com/kubernetes/charts cd charts git checkout efdcffe0b6973111ec6e5e83136ea74cdbe6527d cd ../ vi prometheus-values.yml prometheus-values.yml: alertmanager: persistentVolume: enabled: false server: persistentVolume: enabled: false Then run: helm install -f prometheus-values.yml charts/stable/prometheus --name prometheus --na mespace prometheus vi grafana-values.yml grafana-values.yml: adminPassword: password Then run: helm install -f grafana-values.yml charts/stable/grafana/ --name grafana --namespace grafana vi grafana-ext.yml grafana-ext.yml:
  • 16. Page 16 of 24 kind: Service apiVersion: v1 metadata: namespace: grafana name: grafana-ext spec: type: NodePort selector: app: grafana ports: - protocol: TCP port: 3000 nodePort: 8080 Then run: kubectl apply -f grafana-ext.yml You can check on the status of the prometheus and grafana pods with these commands: kubectl get pods -n prometheus kubectl get pods -n grafana When setting up your dastasource in grafana, use this url: http://prometheus-server.prometheus.svc.cluster.local 6.1 Cluster Monitoring
  • 17. Page 17 of 24 6.2 Application Monitoring Here is the sample source code for the train schedule app that was used in the demo: https://github.com/linuxacademy/cicd-pipeline-train-schedule-monitoring And here is a direct link to the Kubernetes template yml file that was used to deploy the app: https://github.com/linuxacademy/cicd-pipeline-train-schedule- monitoring/blob/master/train-schedule-kube.yml 7. Kubernetes and Self-Healing For more information, check out the Kubernetes documentation on pod lifecycle and restart policies: https://kubernetes.io/docs/concepts/workloads/pods/pod- lifecycle/#restart-policy.
  • 18. Page 18 of 24 7.1 Creating Liveness Probes in Kubernetes For more information on Kubernetes liveness probes, check out their documentation: https://kubernetes.io/docs/tasks/configure-pod-container/configure- liveness-readiness-probes/. Here is the final Kubernetes template file used in the demo (train-schedule-kube.yml): kind: Service apiVersion: v1 metadata: name: train-schedule-service annotations: prometheus.io/scrape: 'true' spec: type: NodePort selector: app: train-schedule ports:
  • 19. Page 19 of 24 - protocol: TCP port: 8080 nodePort: 8080 --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: train-schedule-deployment labels: app: train-schedule spec: replicas: 2 selector: matchLabels: app: train-schedule template: metadata: labels: app: train-schedule spec: containers: - name: train-schedule image: linuxacademycontent/train-schedule:selfhealing ports: - containerPort: 8080 livenessProbe: httpGet: path: / port: 8080 initialDelaySeconds: 15 timeoutSeconds: 1
  • 20. Page 20 of 24 periodSeconds: 10 8. Kubernetes and Autoscaling 8.1 Horizontal Pod Autoscalers in Kubernetes full HPA documentation: https://kubernetes.io/docs/tasks/run-application/horizontal-pod- autoscale/ Here is the GitHub repo for the source code used in the demo. Check the example- solution branch for the demo's final state: https://github.com/linuxacademy/cicd- pipeline-train-schedule-autoscaling
  • 21. Page 21 of 24 Here are the commands used to set up the autoscaler in the demo: cd ~/ git clone https://github.com/kubernetes-incubator/metrics-server.git cd metrics-server/ kubectl create -f deploy/1.8+/ kubectl get --raw /apis/metrics.k8s.io/ cd ~/ git clone cd cicd-pipeline-train-schedule-autoscaling/ vi train-schedule-kube.yml kubectl apply -f train-schedule-kube.yml You can find the changes made to train-schedule-kube.yml in the example- solution branch of the GitHub repo. Once you have deployed the app and the HPA, you can generate CPU load to test it by spinning up a busybox shell: kubectl run -i --tty load-generator --image=busybox /bin/sh Then run this in the busybox shell to create load: while true; do wget -q -O- http://:8080/generate-cpu-load; done 9. What is Canary Testing?
  • 23. Page 23 of 24 8.2 Implementing a Canary Test in Kubernetes You can find the sample source code that was used in this demo here: https://github.com/linuxacademy/cicd-pipeline-train-schedule-canary Be sure to check out the example-solution branch to find the canary deployment template in train-schedule-kube-canary.yml. Here are the commands used to deploy the stable and canary pods in the demo: cd ~/ git clone cd cicd-pipeline-train-schedule-canary/
  • 24. Page 24 of 24 kubectl apply -f train-schedule-kube.yml vi train-schedule-kube-canary.yml kubectl apply -f train-schedule-kube-canary.yml 8.3 Kubernetes Canary Testing with Jenkins Pipelines