SlideShare a Scribd company logo
1 of 46
Download to read offline
GitlabCI and Kubernetes
#build #test and #deploy your projects like a #pro
Paolo Mainardi (@paolomainardi)
● CTO @sparkfabrik
● OSS developer, devops automation engineer
● Checkout my projects here: github.com/paolomainardi
Let’s start with
questions
● You know what Kubernetes is
● You ever used gitlab ci
● You already have a CI/CD pipeline workflow
Raise your hands if
Outlines
● What are Kubernetes and Gitlab
● How to create a cluster powered CI/CD pipeline
● Tips and tricks on real world usage.
Continuous integration is a tough job...
Credits: deis.com/blog/2016/kubernetes-illustrated-guide/
Containerize Everything
Cloud native applications
Cloud-native is an approach to building and running applications
that fully exploits the advantages of the cloud computing model.
https://12factor.net - https://pivotal.io/cloud-native
● Handle of application dependencies
● Dev/prod environments parity
● Orchestrate services
● Make easy to deploy to cloud clustered environments
Continuous integration is a tough job...
Continuous delivery is a software engineering approach to ensure
that the software can be reliably released at any time.
CD Continuous delivery
Continuous deployment is a software engineering approach to ensure
that the every change is automatically deployed to production.
CD Continuous deployment
Cloud orchestrators
9%43% 7%
Source: https://sysdig.com/blog/sysdig-docker-usage-report-2017
Kubernetes
● A system for container management in a clustered environment, open sourced by
Google and inspired by the Borg project.
● Multiple container engines (Docker, rkt, OCI), mainly based on Docker.
● Provides grouping, load balancing, scaling, monitoring and scheduling features
with an unified and declarative API.
● 100% open source and written in GO - https://github.com/kubernetes/kubernetes
Kubernetes the hard way: Custom installers
Kubernetes installation is fairly complex, pick up the right solution:
https://kubernetes.io/docs/setup/pick-right-solution
https://github.com/kubernetes/kubeadm - https://github.com/kubernetes/kops
Kubernetes the easier way: Google GKE
One-click Kubernetes clusters, managed by Google:
https://cloud.google.com/container-engine
Kubernetes the easy way: Google GKE
● Fully managed HA Kubernetes cluster (free up to 5 nodes)
● Logging and monitoring included (Stackdriver)
● Private container registry - https://cloud.google.com/container-registry/
● Automatic and configurable cluster scaling
Kubernetes the easy way: Google GKE
gcloud container clusters list
NAME ZONE MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS
My-testing-clust europe-west1-b 1.5.6 172.199.00.000 n1-standard-1 1.5.6 2 RUNNING
Gitlab
The platform for modern developers
GitLab unifies issues, code review, CI and CD into a single UI
https://about.gitlab.com
Gitlab Runner
The fully integrated solution to build test
and deploy your code.
https://about.gitlab.com/gitlab-ci/
Gitlab Runner
● It is the daemon that run the jobs and send the results back to Gitlab
● One single binary written in GO, very easy to deploy
● Allows to run multiple jobs concurrently
● Native supports for storing cache and artifacts
● It supports multiple build executors including Kubernetes
● Programmatic pipelines definition using a .gitlab-ci.yml file
Gitlab Kubernetes executor
The Kubernetes executor, connects to the Kubernetes API in the
cluster creating a Pod for each GitLab CI Job.
https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/executors/kubernetes.md
config.toml
concurrent = 4
[[runners]]
name = "Kubernetes Runner"
url = "https://gitlab.com/ci"
token = "......"
executor = "kubernetes"
[runners.kubernetes]
host = "https://45.67.34.123:4892"
cert_file = "/etc/ssl/kubernetes/api.crt"
namespace = "gitlab"
privileged = true
cpu_limit = "1"
memory_limit = "1Gi"
service_cpu_limit = "1"
service_memory_limit = "1Gi"
helper_cpu_limit = "500m"
helper_memory_limit = "100Mi"
[runners.kubernetes.node_selector]
"cloud.google.com/gke-nodepool" = "gitlab-ci"
Container limits and resources
Node selector
Kubernetes host
.gitlab-ci.yml
image: docker:latest
stages:
- build
- deploy
build:
stage: build
script:
- docker build -t containerday/my-cool-app:${GIT_COMMIT} .
- docker run containerday/my-cool-app:${GIT_COMMIT} go test -run ./
- docker push containerday/my-cool-app:${GIT_COMMIT} .
Pipelines dashboard
ArtifactsStages
History
Pipeline details
Jobs
Job details
Continuous deployment
With environments, you can control the Continuous Deployment of
your software all within GitLab.
https://about.gitlab.com/2016/08/05/continuous-integration-delivery-and-deployment-with-gitlab/
image: docker:latest .gitlab-ci.yml
stages:
- build
- deploy
build:
stage: build
script:
- docker build -t containerday/my-cool-app:${GIT_COMMIT} .
- docker run containerday/my-cool-app:${GIT_COMMIT} go test -run ./
- docker push containerday/my-cool-app:${GIT_COMMIT} .
deploy:
stage: deploy
environment:
name: production
url: http://foobar.example.com
variables:
- IMAGE_DEPLOY: containerday/image:${CI_BUILD_REF_NAME}
scripts:
# auth
- kubectl config set-cluster my-cluster --server="$KUBE_URL" $KUBE_CLUSTER_OPTIONS
- kubectl config set-credentials my-cluster --token="$KUBE_TOKEN" $KUBE_CLUSTER_OPTIONS
# deploy
- envsubst < k8s/deployment.template.yml > "k8s/deployment.yml"
- kubectl apply -f k8s/deployment.yml
Gitlab continuous deployment
Web terminal
Gitlab continuous deployment
Monitoring with Prometheus
https://docs.gitlab.com/ce/user/project/integrations/prometheus.html
Continuous deployment with Kubernetes
Continuous deployment with Kubernetes
Running Gitlab on Kubernetes
Self hosting Gitlab on Kubernetes
https://gitlab.com/gitlab-org/kubernetes-gitlab-demo
Running Gitlab on Kubernetes tips&tricks
● Segment your cluster by labelling the nodes and use the nodeSelector
● Make a correct use of namespacing for deploying
● Adjust correctly the limits/requests resources of Gitlab executor to help the pod
scheduling
● Keep the k8s templates on version control together with the codebase
● Make a smart use of caches, remember than each job is a clean build env
● Gitlab is an open source project, submit issues and share the fixes
Troubleshooting and debugging
Accessing to a pod internal port
> kubectl port-forward mysql-pod [-c container] 3306:3306
> mysql -hlocalhost -uroot -
Troubleshooting and debugging
Getting a shell to a running container
> kubectl exec -it mysql-pod [-c container] bash
Troubleshooting and debugging
Show gitlab executor pod metrics
> kubectl top pod runner-329d5212-project-255-concurrent-07rxsl -ngitlab --containers
POD NAME CPU(cores) MEMORY(bytes)
runner-329d5212-project-255-concurrent-07rxsl build 1m 35Mi
runner-329d5212-project-255-concurrent-07rxsl helper 0m 13Mi
runner-329d5212-project-255-concurrent-07rxsl svc-0 604m 248Mi
Troubleshooting and debugging
Get container logs
> kubectl logs -f mysql-pod [-c container] bash
Troubleshooting and debugging
https://kubernetes.io/docs/user-guide/kubectl-cheatsheet/
That’s all folks, thanks!

More Related Content

What's hot

What's hot (20)

Advanced Git Tutorial
Advanced Git TutorialAdvanced Git Tutorial
Advanced Git Tutorial
 
Gitlab CI/CD
Gitlab CI/CDGitlab CI/CD
Gitlab CI/CD
 
Gitlab ci-cd
Gitlab ci-cdGitlab ci-cd
Gitlab ci-cd
 
Devops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at GitlabDevops Porto - CI/CD at Gitlab
Devops Porto - CI/CD at Gitlab
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
 
Default GitLab CI Pipeline - Auto DevOps
Default GitLab CI Pipeline - Auto DevOpsDefault GitLab CI Pipeline - Auto DevOps
Default GitLab CI Pipeline - Auto DevOps
 
ArgoCD and Tekton: Match made in Kubernetes heaven | DevNation Tech Talk
ArgoCD and Tekton: Match made in Kubernetes heaven | DevNation Tech TalkArgoCD and Tekton: Match made in Kubernetes heaven | DevNation Tech Talk
ArgoCD and Tekton: Match made in Kubernetes heaven | DevNation Tech Talk
 
GitLab.pptx
GitLab.pptxGitLab.pptx
GitLab.pptx
 
Kubernetes security
Kubernetes securityKubernetes security
Kubernetes security
 
GitHub Actions in action
GitHub Actions in actionGitHub Actions in action
GitHub Actions in action
 
Continuous Integration/Deployment with Gitlab CI
Continuous Integration/Deployment with Gitlab CIContinuous Integration/Deployment with Gitlab CI
Continuous Integration/Deployment with Gitlab CI
 
Helm.pptx
Helm.pptxHelm.pptx
Helm.pptx
 
Grokking opensource with github
Grokking opensource with githubGrokking opensource with github
Grokking opensource with github
 
Git undo
Git undoGit undo
Git undo
 
Container based CI/CD on GitHub Actions
Container based CI/CD on GitHub ActionsContainer based CI/CD on GitHub Actions
Container based CI/CD on GitHub Actions
 
Gitlab ci, cncf.sk
Gitlab ci, cncf.skGitlab ci, cncf.sk
Gitlab ci, cncf.sk
 
Introduction to Git and Github
Introduction to Git and GithubIntroduction to Git and Github
Introduction to Git and Github
 
Git advanced
Git advancedGit advanced
Git advanced
 
Git Tutorial I
Git Tutorial IGit Tutorial I
Git Tutorial I
 
Intro to git and git hub
Intro to git and git hubIntro to git and git hub
Intro to git and git hub
 

Similar to Gitlab ci e kubernetes, build test and deploy your projects like a pro

gitopsthekubernetesway-201026090439.pdf
gitopsthekubernetesway-201026090439.pdfgitopsthekubernetesway-201026090439.pdf
gitopsthekubernetesway-201026090439.pdf
saraichiba2
 

Similar to Gitlab ci e kubernetes, build test and deploy your projects like a pro (20)

ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
ITCamp 2018 - Mete Atamel Ian Talarico - Google Home meets .NET containers on...
 
Environment management in a continuous delivery world (3)
Environment management in a continuous delivery world (3)Environment management in a continuous delivery world (3)
Environment management in a continuous delivery world (3)
 
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
GCP - Continuous Integration and Delivery into Kubernetes with GitHub, Travis...
 
gitopsthekubernetesway-201026090439.pdf
gitopsthekubernetesway-201026090439.pdfgitopsthekubernetesway-201026090439.pdf
gitopsthekubernetesway-201026090439.pdf
 
Gitops: the kubernetes way
Gitops: the kubernetes wayGitops: the kubernetes way
Gitops: the kubernetes way
 
Ci/CD - Stop wasting time, Automate your deployments
Ci/CD  - Stop wasting time, Automate your deploymentsCi/CD  - Stop wasting time, Automate your deployments
Ci/CD - Stop wasting time, Automate your deployments
 
Gocd – Kubernetes/Nomad Continuous Deployment
Gocd – Kubernetes/Nomad Continuous DeploymentGocd – Kubernetes/Nomad Continuous Deployment
Gocd – Kubernetes/Nomad Continuous Deployment
 
[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson Lin[20200720]cloud native develoment - Nelson Lin
[20200720]cloud native develoment - Nelson Lin
 
Enhance Your Kubernetes CI/CD Pipelines With GitLab & Open Source
Enhance Your Kubernetes CI/CD Pipelines With GitLab & Open SourceEnhance Your Kubernetes CI/CD Pipelines With GitLab & Open Source
Enhance Your Kubernetes CI/CD Pipelines With GitLab & Open Source
 
Docker and Jenkins [as code]
Docker and Jenkins [as code]Docker and Jenkins [as code]
Docker and Jenkins [as code]
 
Going Serverless with Kubeless In Google Container Engine (GKE)
Going Serverless with Kubeless In Google Container Engine (GKE)Going Serverless with Kubeless In Google Container Engine (GKE)
Going Serverless with Kubeless In Google Container Engine (GKE)
 
DevFest 2022 - Cloud Workstation Introduction TaiChung
DevFest 2022 - Cloud Workstation Introduction TaiChungDevFest 2022 - Cloud Workstation Introduction TaiChung
DevFest 2022 - Cloud Workstation Introduction TaiChung
 
The App Developer's Kubernetes Toolbox
The App Developer's Kubernetes ToolboxThe App Developer's Kubernetes Toolbox
The App Developer's Kubernetes Toolbox
 
Continuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CIContinuous Deployment with Kubernetes, Docker and GitLab CI
Continuous Deployment with Kubernetes, Docker and GitLab CI
 
The path to a serverless-native era with Kubernetes
The path to a serverless-native era with KubernetesThe path to a serverless-native era with Kubernetes
The path to a serverless-native era with Kubernetes
 
Mattia Gandolfi - Improving utilization and portability with Containers and C...
Mattia Gandolfi - Improving utilization and portability with Containers and C...Mattia Gandolfi - Improving utilization and portability with Containers and C...
Mattia Gandolfi - Improving utilization and portability with Containers and C...
 
CI/CD with Github Actions
CI/CD with Github ActionsCI/CD with Github Actions
CI/CD with Github Actions
 
Continuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applicationsContinuous Integration/ Continuous Delivery of web applications
Continuous Integration/ Continuous Delivery of web applications
 
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastrutturaGitOps: Git come unica fonte di verità per applicazioni e infrastruttura
GitOps: Git come unica fonte di verità per applicazioni e infrastruttura
 
Putting the Fun into Functioning CI/CD with JHipster
Putting the Fun into Functioning CI/CD with JHipsterPutting the Fun into Functioning CI/CD with JHipster
Putting the Fun into Functioning CI/CD with JHipster
 

More from sparkfabrik

More from sparkfabrik (20)

KCD Italy 2023 - Secure Software Supply chain for OCI Artifact on Kubernetes
KCD Italy 2023 - Secure Software Supply chain for OCI Artifact on KubernetesKCD Italy 2023 - Secure Software Supply chain for OCI Artifact on Kubernetes
KCD Italy 2023 - Secure Software Supply chain for OCI Artifact on Kubernetes
 
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
 
IAD 2023 - 22 Years of Agile and all I got is this lousy t-shirt
IAD 2023 - 22 Years of Agile and all I got is this lousy t-shirtIAD 2023 - 22 Years of Agile and all I got is this lousy t-shirt
IAD 2023 - 22 Years of Agile and all I got is this lousy t-shirt
 
2023 - Drupalcon - How Drupal builds your pages
2023 - Drupalcon - How Drupal builds your pages2023 - Drupalcon - How Drupal builds your pages
2023 - Drupalcon - How Drupal builds your pages
 
2023 - TAC23 - Agile HR - Racconti dal fronte
2023 - TAC23 - Agile HR - Racconti dal fronte2023 - TAC23 - Agile HR - Racconti dal fronte
2023 - TAC23 - Agile HR - Racconti dal fronte
 
CodeMotion 2023 - Deep dive nella supply chain della nostra infrastruttura cl...
CodeMotion 2023 - Deep dive nella supply chain della nostra infrastruttura cl...CodeMotion 2023 - Deep dive nella supply chain della nostra infrastruttura cl...
CodeMotion 2023 - Deep dive nella supply chain della nostra infrastruttura cl...
 
What is the Secure Supply Chain and the Current State of the PHP Ecosystem
What is the Secure Supply Chain and the Current State of the PHP EcosystemWhat is the Secure Supply Chain and the Current State of the PHP Ecosystem
What is the Secure Supply Chain and the Current State of the PHP Ecosystem
 
UX e Web sostenibile (UXday 2023).pdf
UX e Web sostenibile (UXday 2023).pdfUX e Web sostenibile (UXday 2023).pdf
UX e Web sostenibile (UXday 2023).pdf
 
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
Drupal Dev Days Vienna 2023 - What is the secure software supply chain and th...
 
Deep dive nella supply chain della nostra infrastruttura cloud
Deep dive nella supply chain della nostra infrastruttura cloudDeep dive nella supply chain della nostra infrastruttura cloud
Deep dive nella supply chain della nostra infrastruttura cloud
 
KCD Italy 2022 - Application driven infrastructure with Crossplane
KCD Italy 2022 - Application driven infrastructure with CrossplaneKCD Italy 2022 - Application driven infrastructure with Crossplane
KCD Italy 2022 - Application driven infrastructure with Crossplane
 
Come Drupal costruisce le tue pagine
Come Drupal costruisce le tue pagineCome Drupal costruisce le tue pagine
Come Drupal costruisce le tue pagine
 
Drupal 10: un framework PHP di sviluppo Cloud Native moderno
Drupal 10: un framework PHP di sviluppo Cloud Native modernoDrupal 10: un framework PHP di sviluppo Cloud Native moderno
Drupal 10: un framework PHP di sviluppo Cloud Native moderno
 
Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)
Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)
Do you know what your Drupal is doing Observe it! (DrupalCon Prague 2022)
 
Do you know what your Drupal is doing_ Observe it!
Do you know what your Drupal is doing_ Observe it!Do you know what your Drupal is doing_ Observe it!
Do you know what your Drupal is doing_ Observe it!
 
Progettare e sviluppare soluzioni serverless con AWS
Progettare e sviluppare soluzioni serverless con AWSProgettare e sviluppare soluzioni serverless con AWS
Progettare e sviluppare soluzioni serverless con AWS
 
From React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I startedFrom React to React Native - Things I wish I knew when I started
From React to React Native - Things I wish I knew when I started
 
Headless Drupal: A modern approach to (micro)services and APIs
Headless Drupal: A modern approach to (micro)services and APIsHeadless Drupal: A modern approach to (micro)services and APIs
Headless Drupal: A modern approach to (micro)services and APIs
 
Cloud-Native Drupal: a survival guide
Cloud-Native Drupal: a survival guideCloud-Native Drupal: a survival guide
Cloud-Native Drupal: a survival guide
 
Mobile Development: una introduzione per Web Developers
Mobile Development: una introduzione per Web DevelopersMobile Development: una introduzione per Web Developers
Mobile Development: una introduzione per Web Developers
 

Recently uploaded

Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Lisi Hocke
 

Recently uploaded (20)

A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
Abortion Clinic In Johannesburg ](+27832195400*)[ 🏥 Safe Abortion Pills in Jo...
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
^Clinic ^%[+27788225528*Abortion Pills For Sale In soweto
 
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit MilanWorkshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
Workshop: Enabling GenAI Breakthroughs with Knowledge Graphs - GraphSummit Milan
 
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdfStrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
StrimziCon 2024 - Transition to Apache Kafka on Kubernetes with Strimzi.pdf
 
How to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabberHow to install and activate eGrabber JobGrabber
How to install and activate eGrabber JobGrabber
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
Team Transformation Tactics for Holistic Testing and Quality (NewCrafts Paris...
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
^Clinic ^%[+27788225528*Abortion Pills For Sale In harare
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements Engineering
 

Gitlab ci e kubernetes, build test and deploy your projects like a pro

  • 1. GitlabCI and Kubernetes #build #test and #deploy your projects like a #pro
  • 2. Paolo Mainardi (@paolomainardi) ● CTO @sparkfabrik ● OSS developer, devops automation engineer ● Checkout my projects here: github.com/paolomainardi
  • 4. ● You know what Kubernetes is ● You ever used gitlab ci ● You already have a CI/CD pipeline workflow Raise your hands if
  • 5. Outlines ● What are Kubernetes and Gitlab ● How to create a cluster powered CI/CD pipeline ● Tips and tricks on real world usage.
  • 6. Continuous integration is a tough job... Credits: deis.com/blog/2016/kubernetes-illustrated-guide/
  • 9. Cloud-native is an approach to building and running applications that fully exploits the advantages of the cloud computing model. https://12factor.net - https://pivotal.io/cloud-native
  • 10. ● Handle of application dependencies ● Dev/prod environments parity ● Orchestrate services ● Make easy to deploy to cloud clustered environments Continuous integration is a tough job...
  • 11. Continuous delivery is a software engineering approach to ensure that the software can be reliably released at any time. CD Continuous delivery
  • 12. Continuous deployment is a software engineering approach to ensure that the every change is automatically deployed to production. CD Continuous deployment
  • 13.
  • 14. Cloud orchestrators 9%43% 7% Source: https://sysdig.com/blog/sysdig-docker-usage-report-2017
  • 15. Kubernetes ● A system for container management in a clustered environment, open sourced by Google and inspired by the Borg project. ● Multiple container engines (Docker, rkt, OCI), mainly based on Docker. ● Provides grouping, load balancing, scaling, monitoring and scheduling features with an unified and declarative API. ● 100% open source and written in GO - https://github.com/kubernetes/kubernetes
  • 16. Kubernetes the hard way: Custom installers Kubernetes installation is fairly complex, pick up the right solution: https://kubernetes.io/docs/setup/pick-right-solution https://github.com/kubernetes/kubeadm - https://github.com/kubernetes/kops
  • 17. Kubernetes the easier way: Google GKE One-click Kubernetes clusters, managed by Google: https://cloud.google.com/container-engine
  • 18. Kubernetes the easy way: Google GKE ● Fully managed HA Kubernetes cluster (free up to 5 nodes) ● Logging and monitoring included (Stackdriver) ● Private container registry - https://cloud.google.com/container-registry/ ● Automatic and configurable cluster scaling
  • 19. Kubernetes the easy way: Google GKE gcloud container clusters list NAME ZONE MASTER_VERSION MASTER_IP MACHINE_TYPE NODE_VERSION NUM_NODES STATUS My-testing-clust europe-west1-b 1.5.6 172.199.00.000 n1-standard-1 1.5.6 2 RUNNING
  • 20. Gitlab The platform for modern developers GitLab unifies issues, code review, CI and CD into a single UI https://about.gitlab.com
  • 21. Gitlab Runner The fully integrated solution to build test and deploy your code. https://about.gitlab.com/gitlab-ci/
  • 22. Gitlab Runner ● It is the daemon that run the jobs and send the results back to Gitlab ● One single binary written in GO, very easy to deploy ● Allows to run multiple jobs concurrently ● Native supports for storing cache and artifacts ● It supports multiple build executors including Kubernetes ● Programmatic pipelines definition using a .gitlab-ci.yml file
  • 23. Gitlab Kubernetes executor The Kubernetes executor, connects to the Kubernetes API in the cluster creating a Pod for each GitLab CI Job. https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/executors/kubernetes.md
  • 24. config.toml concurrent = 4 [[runners]] name = "Kubernetes Runner" url = "https://gitlab.com/ci" token = "......" executor = "kubernetes" [runners.kubernetes] host = "https://45.67.34.123:4892" cert_file = "/etc/ssl/kubernetes/api.crt" namespace = "gitlab" privileged = true cpu_limit = "1" memory_limit = "1Gi" service_cpu_limit = "1" service_memory_limit = "1Gi" helper_cpu_limit = "500m" helper_memory_limit = "100Mi" [runners.kubernetes.node_selector] "cloud.google.com/gke-nodepool" = "gitlab-ci" Container limits and resources Node selector Kubernetes host
  • 25. .gitlab-ci.yml image: docker:latest stages: - build - deploy build: stage: build script: - docker build -t containerday/my-cool-app:${GIT_COMMIT} . - docker run containerday/my-cool-app:${GIT_COMMIT} go test -run ./ - docker push containerday/my-cool-app:${GIT_COMMIT} .
  • 29. Continuous deployment With environments, you can control the Continuous Deployment of your software all within GitLab. https://about.gitlab.com/2016/08/05/continuous-integration-delivery-and-deployment-with-gitlab/
  • 30. image: docker:latest .gitlab-ci.yml stages: - build - deploy build: stage: build script: - docker build -t containerday/my-cool-app:${GIT_COMMIT} . - docker run containerday/my-cool-app:${GIT_COMMIT} go test -run ./ - docker push containerday/my-cool-app:${GIT_COMMIT} . deploy: stage: deploy environment: name: production url: http://foobar.example.com variables: - IMAGE_DEPLOY: containerday/image:${CI_BUILD_REF_NAME} scripts: # auth - kubectl config set-cluster my-cluster --server="$KUBE_URL" $KUBE_CLUSTER_OPTIONS - kubectl config set-credentials my-cluster --token="$KUBE_TOKEN" $KUBE_CLUSTER_OPTIONS # deploy - envsubst < k8s/deployment.template.yml > "k8s/deployment.yml" - kubectl apply -f k8s/deployment.yml
  • 32. Gitlab continuous deployment Monitoring with Prometheus https://docs.gitlab.com/ce/user/project/integrations/prometheus.html
  • 35. Running Gitlab on Kubernetes Self hosting Gitlab on Kubernetes https://gitlab.com/gitlab-org/kubernetes-gitlab-demo
  • 36.
  • 37.
  • 38.
  • 39.
  • 40. Running Gitlab on Kubernetes tips&tricks ● Segment your cluster by labelling the nodes and use the nodeSelector ● Make a correct use of namespacing for deploying ● Adjust correctly the limits/requests resources of Gitlab executor to help the pod scheduling ● Keep the k8s templates on version control together with the codebase ● Make a smart use of caches, remember than each job is a clean build env ● Gitlab is an open source project, submit issues and share the fixes
  • 41. Troubleshooting and debugging Accessing to a pod internal port > kubectl port-forward mysql-pod [-c container] 3306:3306 > mysql -hlocalhost -uroot -
  • 42. Troubleshooting and debugging Getting a shell to a running container > kubectl exec -it mysql-pod [-c container] bash
  • 43. Troubleshooting and debugging Show gitlab executor pod metrics > kubectl top pod runner-329d5212-project-255-concurrent-07rxsl -ngitlab --containers POD NAME CPU(cores) MEMORY(bytes) runner-329d5212-project-255-concurrent-07rxsl build 1m 35Mi runner-329d5212-project-255-concurrent-07rxsl helper 0m 13Mi runner-329d5212-project-255-concurrent-07rxsl svc-0 604m 248Mi
  • 44. Troubleshooting and debugging Get container logs > kubectl logs -f mysql-pod [-c container] bash