SlideShare una empresa de Scribd logo
1 de 36
Descargar para leer sin conexión
1@Horgix@ContainerDayFRKIND: Next level inception
Alexis “Horgix” Chotard
4th
June 2019
Kubernetes in Docker
Next level inception
2@Horgix@ContainerDayFRKIND: Next level inception
SRE & Technical Officer
▼ Automation Addict
▼ Craftsman
▼ ❤ CNCF & Open Source
▼ 30% Development
▼ 40% Operations
▼ 30% Training, coaching, ...
@Horgix
HorgixAlexis “Horgix” Chotard
3@Horgix@ContainerDayFRKIND: Next level inception
Let’s talk about testing!
Kubernetes in Docker?
I lied. It was a bait.
4@Horgix@ContainerDayFRKIND: Next level inception
Craftsmanship applied to complex systems
Testing & Kubernetes
5@Horgix@ContainerDayFRKIND: Next level inception
Reminder: tests pyramid
6@Horgix@ContainerDayFRKIND: Next level inception
Reminder: tests pyramid
What does it
mean for
Kubernetes
applications?
7@Horgix@ContainerDayFRKIND: Next level inception
Kubernetes applications?
▼ Let’s not talk about your typical application. You write simple manifests to
create Deployments, Services, Ingresses, etc. and apply them. Fine.
▼ What about applications deeply interfacing with Kubernetes?
▽ Operators are popping everywhere and for everything
Reminder: Operator = Custom Resource Definition (CRD) + Controller
▽ Controllers & CRDs have to be tested
▼ … and what about Kubernetes itself?
8@Horgix@ContainerDayFRKIND: Next level inception
The overly simplified CRDs & Controllers 101
9@Horgix@ContainerDayFRKIND: Next level inception
The overly simplified CRDs & Controllers 101
10@Horgix@ContainerDayFRKIND: Next level inception
The overly simplified CRDs & Controllers 101
11@Horgix@ContainerDayFRKIND: Next level inception
The overly simplified CRDs & Controllers 101
12@Horgix@ContainerDayFRKIND: Next level inception
Unit tests
▼ client-go fake client [1][2]
▼ In-memory implementation of an apiserver/client
▼ Great for simple things but lots of caveats:
▽ Majority of the functionalities of apiserver’s does not exist
▽ Race & timing issues not surfaced
▽ No other controllers running
(i.e. creating a ReplicaSet does not mean Pods)
[1] https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/kubernetes/fake/clientset_generated.go
[2] Example usage: https://github.com/diazjf/fakeclient
13@Horgix@ContainerDayFRKIND: Next level inception
Integration tests
▼ Kubebuilder [1] & controller-runtime [2] use this approach a lot
▼ Run etcd + apiserver (+ optionnally controller-manager)
▼ Why?
▽ Admission control
▽ Timing issues
[1] https://github.com/kubernetes-sigs/kubebuilder
[2] https://github.com/kubernetes-sigs/controller-runtime
14@Horgix@ContainerDayFRKIND: Next level inception
End-to-end tests
▼ Start a full Kubernetes cluster
▼ Give us the ultimate flexibility
▼ Black box testing - we don’t assume implementation
▼ But this can be slow and/or expensive
▼ Why End-to-End (E2E) tests?
▽ Certain edge cases only picked up in a real environment
▽ Kubernetes has a lot of controllers
The way these inter-operate is really important
▽ “Fighting” can cause massive issues for a level based system
15@Horgix@ContainerDayFRKIND: Next level inception
End-to-end tests - What they usually run on
▼ Remote, managed cluster (GKE, EKS, …)
▼ Minikube
▼ Your own cluster
▼ … all with their own pitfalls:
▽ Often used as “persistent” clusters
▽ Lead to behaviors related to a previous state
▽ Might be slow and/or costly
▽ What about testing different Kubernetes versions easily?
▼ “When you’re developing tools against the Kubernetes APIs it’s often best to
be throwing things away fairly regularly” [1]
[1] https://garethr.dev/2019/05/ephemeral-kubernetes-clusters-with-kind-and-make/#167
16@Horgix@ContainerDayFRKIND: Next level inception
Let’s run temporary instances inside containers!
What if we did just like our other apps?
17@Horgix@ContainerDayFRKIND: Next level inception
https://kind.sigs.k8s.io/
https://github.com/kubernetes-sigs/kind
18@Horgix@ContainerDayFRKIND: Next level inception
What’s kind?
▼ Kubernetes IN Docker
▼ Uses containers to simulate nodes
▼ Multi-node
▼ Multi-cluster
▼ Works offline
▼ Boot a cluster in ~30sec
(well, a bit more since a recent kubelet systemd unit change [1]
... but soon down to 20sec [2])
[1] https://github.com/kubernetes-sigs/kind/issues/576
[2] https://github.com/kubernetes-sigs/kind/pull/585
19@Horgix@ContainerDayFRKIND: Next level inception
How kind works
▼ Leverage Existing Tooling [1] :
▽ kubeadm handles node configuration, certificates, etc.
▽ kustomize handles merging user-provided config patches
with generated kubeadm configs
▼ Node image
▽ You can build it yourself - useful when developing on K8s
▽ Embed everything that’s need
▽ Docker in Docker pattern
[1] https://kind.sigs.k8s.io/docs/design/principles/
20@Horgix@ContainerDayFRKIND: Next level inception
Architecture summary - what is spawned by kind
21@Horgix@ContainerDayFRKIND: Next level inception
Let’s spawn some clusters
Demo time ⚡
22@Horgix@ContainerDayFRKIND: Next level inception
Demo #1 - What did we just do?
▼ We created a cluster using kind create
▼ We learned that kind doesn’t persist any state and
instead use Docker labels in a smart way
▼ We saw a full Kubernetes cluster with real components
… running inside Docker
▼ In a really fast and efficient way!
23@Horgix@ContainerDayFRKIND: Next level inception
With end-to-end (conformance) tests
Using kind clusters for testing
24@Horgix@ContainerDayFRKIND: Next level inception
Conformance tests?
▼ Requirements:
▽ Ginkgo
▽ e2e.test
▽ kubectl
▼ Official test suite used to validate releases
25@Horgix@ContainerDayFRKIND: Next level inception
Kubernetes conformance tests
Demo time 🔧
26@Horgix@ContainerDayFRKIND: Next level inception
Demo #2 - What did we just do?
▼ We built the end-to-end test tooling of Kubernetes
▼ We used it against our test cluster from the outside as we may do with
any local cluster
▼ We found that kubetest is already integrated with kind
27@Horgix@ContainerDayFRKIND: Next level inception
Not everyone is developing on Kubernetes itself
What about controllers?
28@Horgix@ContainerDayFRKIND: Next level inception
Sample controller deployment/injection
Demo time 🚀
29@Horgix@ContainerDayFRKIND: Next level inception
Demo #3 - What did we just do?
▼ We built a sample controller
▼ We created CRD and a custom object
… and saw that the controller reacted to it
▼ Given more time for the demo, we also could have:
▽ Added an end-to-end test for this behavior and ran it against our cluster
▽ Loaded and deployed the controller into our cluster
30@Horgix@ContainerDayFRKIND: Next level inception
kind in a CI pipeline
Demo time ♻
31@Horgix@ContainerDayFRKIND: Next level inception
… Not enough time for it today.
See the repo at the end of these slides :)
kind in a CI pipeline
32@Horgix@ContainerDayFRKIND: Next level inception
...
Wrapping up 🎁
33@Horgix@ContainerDayFRKIND: Next level inception
kind vs The world
▼ https://github.com/kubernetes/minikube
▼ https://github.com/ubuntu/microk8s
▼ https://github.com/bsycorp/kind
▼ https://github.com/kinvolk/kube-spawn
▼ https://github.com/danderson/virtuakube
▼ https://github.com/kubernetes-sigs/kubeadm-dind-cluster
34@Horgix@ContainerDayFRKIND: Next level inception
So… Why kind?
▼ “kind is actually literally my favorite thing right now” -- Bryan Liles @ KCCNC
▼ It’s simple, yet complete
▽ Multi-node (including HA) clusters
▽ Supports building Kubernetes release builds from source
▽ Can be used as a library [1]
▽ Supports Windows in addition to MacOS and Linux
▼ kind is a CNCF certified conformant Kubernetes installer
▼ Developed by cool & smart people
▼ Integrated with official Kubernetes testing tools
▼ Being integrated with more and more stuff every day
[1] https://github.com/kubernetes/kubeadm/tree/master/kinder
35@Horgix@ContainerDayFRKIND: Next level inception
Take away
▼ kind allows you to spawn a real & lightweight Kubernetes clusterS
▼ This is awesome for debugging and testing:
▽ Kubernetes itself
▽ Applications interacting with Kubernetes directly such as controllers
▼ It’s really fast to create clusters: ~30sec
▼ Integrates well in a CI pipeline and other use-cases
Kubernetes is all about community: go contribute to kind :)
36@Horgix@ContainerDayFRKIND: Next level inception
Alexis “Horgix” Chotard
4th
June 2019
Kubernetes in Docker
Next level inception
Thank you!
Demo : https://github.com/Horgix/kind-demo
Slides : https://www.slideshare.net/Horgix
Thanks @BenTheElder

Más contenido relacionado

La actualidad más candente

Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
msohn
 
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
OpenCity Community
 
Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)
Giovanni Toraldo
 

La actualidad más candente (20)

Golang online course
Golang online courseGolang online course
Golang online course
 
Project52
Project52Project52
Project52
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
iTHome Gopher Day 2017: What can Golang do? (Using project 52 as examples)
iTHome Gopher Day 2017: What can Golang do?  (Using project 52 as examples)iTHome Gopher Day 2017: What can Golang do?  (Using project 52 as examples)
iTHome Gopher Day 2017: What can Golang do? (Using project 52 as examples)
 
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
Using Git in Eclipse - Eclipse Summit Europe 2010-11-03
 
EGit and Gerrit Code Review - Eclipse DemoCamp Bonn - 2010-11-16
EGit and Gerrit Code Review - Eclipse DemoCamp Bonn - 2010-11-16EGit and Gerrit Code Review - Eclipse DemoCamp Bonn - 2010-11-16
EGit and Gerrit Code Review - Eclipse DemoCamp Bonn - 2010-11-16
 
Golang taipei #45 10th birthday
Golang taipei #45 10th birthdayGolang taipei #45 10th birthday
Golang taipei #45 10th birthday
 
Back end User Group / Golang Intro
Back end User Group / Golang IntroBack end User Group / Golang Intro
Back end User Group / Golang Intro
 
iThome Chatbot Day: 透過 Golang 無痛建置機器學習聊天機器人
iThome Chatbot Day: 透過 Golang 無痛建置機器學習聊天機器人iThome Chatbot Day: 透過 Golang 無痛建置機器學習聊天機器人
iThome Chatbot Day: 透過 Golang 無痛建置機器學習聊天機器人
 
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
Assign, commit, and review - A developer’s guide to OpenStack contribution-20...
 
Gerrit Code Review
Gerrit Code ReviewGerrit Code Review
Gerrit Code Review
 
Pyfest Tunisia 2015 - Python & DevOps
Pyfest Tunisia 2015 - Python & DevOpsPyfest Tunisia 2015 - Python & DevOps
Pyfest Tunisia 2015 - Python & DevOps
 
Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)Continuous Delivery: 5 years later (Incontro DevOps 2018)
Continuous Delivery: 5 years later (Incontro DevOps 2018)
 
Assign, Commit, and Review
Assign, Commit, and ReviewAssign, Commit, and Review
Assign, Commit, and Review
 
Hacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginnersHacktoberfest 2020 - Open source for beginners
Hacktoberfest 2020 - Open source for beginners
 
OSGi Versioning & Testing
OSGi Versioning & TestingOSGi Versioning & Testing
OSGi Versioning & Testing
 
Introduction to GoLang
Introduction to GoLangIntroduction to GoLang
Introduction to GoLang
 
Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14
Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14
Code Review with Git and Gerrit - Devoxx 2011 - Tools in Action - 2011-11-14
 
How Git and Gerrit make you more productive
How Git and Gerrit make you more productiveHow Git and Gerrit make you more productive
How Git and Gerrit make you more productive
 
Tekton showcase - CDF Summit Kubecon Barcelona 2019
Tekton showcase - CDF Summit Kubecon Barcelona 2019Tekton showcase - CDF Summit Kubecon Barcelona 2019
Tekton showcase - CDF Summit Kubecon Barcelona 2019
 

Similar a Kubernetes IN Docker: Next level inception - Paris Container Day 2019

WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?
Weaveworks
 
Tekton_ArgoCD-_KCD_Taiwan-cicd-openshift
Tekton_ArgoCD-_KCD_Taiwan-cicd-openshiftTekton_ArgoCD-_KCD_Taiwan-cicd-openshift
Tekton_ArgoCD-_KCD_Taiwan-cicd-openshift
bashwen2022
 

Similar a Kubernetes IN Docker: Next level inception - Paris Container Day 2019 (20)

Kubernetes & Cloud Native Indonesia X BukaMeetup - Feb 2023
Kubernetes & Cloud Native Indonesia X BukaMeetup - Feb 2023Kubernetes & Cloud Native Indonesia X BukaMeetup - Feb 2023
Kubernetes & Cloud Native Indonesia X BukaMeetup - Feb 2023
 
WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?WTF is GitOps and Why You Should Care?
WTF is GitOps and Why You Should Care?
 
WTF is GitOps & Why Should You Care?
WTF is GitOps & Why Should You Care?WTF is GitOps & Why Should You Care?
WTF is GitOps & Why Should You Care?
 
GitOps Testing in Kubernetes with Flux and Testkube.pdf
GitOps Testing in Kubernetes with Flux and Testkube.pdfGitOps Testing in Kubernetes with Flux and Testkube.pdf
GitOps Testing in Kubernetes with Flux and Testkube.pdf
 
Introduction to GitHub Actions - How to easily automate and integrate with Gi...
Introduction to GitHub Actions - How to easily automate and integrate with Gi...Introduction to GitHub Actions - How to easily automate and integrate with Gi...
Introduction to GitHub Actions - How to easily automate and integrate with Gi...
 
Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD Webinar - Unbox GitLab CI/CD
Webinar - Unbox GitLab CI/CD
 
Rejekts 24 EU No GitOps Pain, No Platform Gain
Rejekts 24 EU No GitOps Pain, No Platform GainRejekts 24 EU No GitOps Pain, No Platform Gain
Rejekts 24 EU No GitOps Pain, No Platform Gain
 
Docker based-Pipelines with Codefresh
Docker based-Pipelines with CodefreshDocker based-Pipelines with Codefresh
Docker based-Pipelines with Codefresh
 
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
 
DevOps - A Purpose for an Institution.pdf
DevOps - A Purpose for an Institution.pdfDevOps - A Purpose for an Institution.pdf
DevOps - A Purpose for an Institution.pdf
 
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
 
Tekton_ArgoCD-_KCD_Taiwan-cicd-openshift
Tekton_ArgoCD-_KCD_Taiwan-cicd-openshiftTekton_ArgoCD-_KCD_Taiwan-cicd-openshift
Tekton_ArgoCD-_KCD_Taiwan-cicd-openshift
 
Настройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'aНастройка окружения для кросскомпиляции проектов на основе docker'a
Настройка окружения для кросскомпиляции проектов на основе docker'a
 
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptxorlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
orlando-codecamp-meet-copilot-24-Feb-2024_pub.pptx
 
CI/CD with Github Actions
CI/CD with Github ActionsCI/CD with Github Actions
CI/CD with Github Actions
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An Introduction
 
Docker e git lab
Docker e git labDocker e git lab
Docker e git lab
 
Build and run applications in a dockerless kubernetes world - DevConf India 18
Build and run applications in a dockerless kubernetes world - DevConf India 18Build and run applications in a dockerless kubernetes world - DevConf India 18
Build and run applications in a dockerless kubernetes world - DevConf India 18
 
FooConf23_Bringing the cloud back down to earth.pptx
FooConf23_Bringing the cloud back down to earth.pptxFooConf23_Bringing the cloud back down to earth.pptx
FooConf23_Bringing the cloud back down to earth.pptx
 
Docker based-pipelines
Docker based-pipelinesDocker based-pipelines
Docker based-pipelines
 

Último

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Último (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 

Kubernetes IN Docker: Next level inception - Paris Container Day 2019

  • 1. 1@Horgix@ContainerDayFRKIND: Next level inception Alexis “Horgix” Chotard 4th June 2019 Kubernetes in Docker Next level inception
  • 2. 2@Horgix@ContainerDayFRKIND: Next level inception SRE & Technical Officer ▼ Automation Addict ▼ Craftsman ▼ ❤ CNCF & Open Source ▼ 30% Development ▼ 40% Operations ▼ 30% Training, coaching, ... @Horgix HorgixAlexis “Horgix” Chotard
  • 3. 3@Horgix@ContainerDayFRKIND: Next level inception Let’s talk about testing! Kubernetes in Docker? I lied. It was a bait.
  • 4. 4@Horgix@ContainerDayFRKIND: Next level inception Craftsmanship applied to complex systems Testing & Kubernetes
  • 5. 5@Horgix@ContainerDayFRKIND: Next level inception Reminder: tests pyramid
  • 6. 6@Horgix@ContainerDayFRKIND: Next level inception Reminder: tests pyramid What does it mean for Kubernetes applications?
  • 7. 7@Horgix@ContainerDayFRKIND: Next level inception Kubernetes applications? ▼ Let’s not talk about your typical application. You write simple manifests to create Deployments, Services, Ingresses, etc. and apply them. Fine. ▼ What about applications deeply interfacing with Kubernetes? ▽ Operators are popping everywhere and for everything Reminder: Operator = Custom Resource Definition (CRD) + Controller ▽ Controllers & CRDs have to be tested ▼ … and what about Kubernetes itself?
  • 8. 8@Horgix@ContainerDayFRKIND: Next level inception The overly simplified CRDs & Controllers 101
  • 9. 9@Horgix@ContainerDayFRKIND: Next level inception The overly simplified CRDs & Controllers 101
  • 10. 10@Horgix@ContainerDayFRKIND: Next level inception The overly simplified CRDs & Controllers 101
  • 11. 11@Horgix@ContainerDayFRKIND: Next level inception The overly simplified CRDs & Controllers 101
  • 12. 12@Horgix@ContainerDayFRKIND: Next level inception Unit tests ▼ client-go fake client [1][2] ▼ In-memory implementation of an apiserver/client ▼ Great for simple things but lots of caveats: ▽ Majority of the functionalities of apiserver’s does not exist ▽ Race & timing issues not surfaced ▽ No other controllers running (i.e. creating a ReplicaSet does not mean Pods) [1] https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/kubernetes/fake/clientset_generated.go [2] Example usage: https://github.com/diazjf/fakeclient
  • 13. 13@Horgix@ContainerDayFRKIND: Next level inception Integration tests ▼ Kubebuilder [1] & controller-runtime [2] use this approach a lot ▼ Run etcd + apiserver (+ optionnally controller-manager) ▼ Why? ▽ Admission control ▽ Timing issues [1] https://github.com/kubernetes-sigs/kubebuilder [2] https://github.com/kubernetes-sigs/controller-runtime
  • 14. 14@Horgix@ContainerDayFRKIND: Next level inception End-to-end tests ▼ Start a full Kubernetes cluster ▼ Give us the ultimate flexibility ▼ Black box testing - we don’t assume implementation ▼ But this can be slow and/or expensive ▼ Why End-to-End (E2E) tests? ▽ Certain edge cases only picked up in a real environment ▽ Kubernetes has a lot of controllers The way these inter-operate is really important ▽ “Fighting” can cause massive issues for a level based system
  • 15. 15@Horgix@ContainerDayFRKIND: Next level inception End-to-end tests - What they usually run on ▼ Remote, managed cluster (GKE, EKS, …) ▼ Minikube ▼ Your own cluster ▼ … all with their own pitfalls: ▽ Often used as “persistent” clusters ▽ Lead to behaviors related to a previous state ▽ Might be slow and/or costly ▽ What about testing different Kubernetes versions easily? ▼ “When you’re developing tools against the Kubernetes APIs it’s often best to be throwing things away fairly regularly” [1] [1] https://garethr.dev/2019/05/ephemeral-kubernetes-clusters-with-kind-and-make/#167
  • 16. 16@Horgix@ContainerDayFRKIND: Next level inception Let’s run temporary instances inside containers! What if we did just like our other apps?
  • 17. 17@Horgix@ContainerDayFRKIND: Next level inception https://kind.sigs.k8s.io/ https://github.com/kubernetes-sigs/kind
  • 18. 18@Horgix@ContainerDayFRKIND: Next level inception What’s kind? ▼ Kubernetes IN Docker ▼ Uses containers to simulate nodes ▼ Multi-node ▼ Multi-cluster ▼ Works offline ▼ Boot a cluster in ~30sec (well, a bit more since a recent kubelet systemd unit change [1] ... but soon down to 20sec [2]) [1] https://github.com/kubernetes-sigs/kind/issues/576 [2] https://github.com/kubernetes-sigs/kind/pull/585
  • 19. 19@Horgix@ContainerDayFRKIND: Next level inception How kind works ▼ Leverage Existing Tooling [1] : ▽ kubeadm handles node configuration, certificates, etc. ▽ kustomize handles merging user-provided config patches with generated kubeadm configs ▼ Node image ▽ You can build it yourself - useful when developing on K8s ▽ Embed everything that’s need ▽ Docker in Docker pattern [1] https://kind.sigs.k8s.io/docs/design/principles/
  • 20. 20@Horgix@ContainerDayFRKIND: Next level inception Architecture summary - what is spawned by kind
  • 21. 21@Horgix@ContainerDayFRKIND: Next level inception Let’s spawn some clusters Demo time ⚡
  • 22. 22@Horgix@ContainerDayFRKIND: Next level inception Demo #1 - What did we just do? ▼ We created a cluster using kind create ▼ We learned that kind doesn’t persist any state and instead use Docker labels in a smart way ▼ We saw a full Kubernetes cluster with real components … running inside Docker ▼ In a really fast and efficient way!
  • 23. 23@Horgix@ContainerDayFRKIND: Next level inception With end-to-end (conformance) tests Using kind clusters for testing
  • 24. 24@Horgix@ContainerDayFRKIND: Next level inception Conformance tests? ▼ Requirements: ▽ Ginkgo ▽ e2e.test ▽ kubectl ▼ Official test suite used to validate releases
  • 25. 25@Horgix@ContainerDayFRKIND: Next level inception Kubernetes conformance tests Demo time 🔧
  • 26. 26@Horgix@ContainerDayFRKIND: Next level inception Demo #2 - What did we just do? ▼ We built the end-to-end test tooling of Kubernetes ▼ We used it against our test cluster from the outside as we may do with any local cluster ▼ We found that kubetest is already integrated with kind
  • 27. 27@Horgix@ContainerDayFRKIND: Next level inception Not everyone is developing on Kubernetes itself What about controllers?
  • 28. 28@Horgix@ContainerDayFRKIND: Next level inception Sample controller deployment/injection Demo time 🚀
  • 29. 29@Horgix@ContainerDayFRKIND: Next level inception Demo #3 - What did we just do? ▼ We built a sample controller ▼ We created CRD and a custom object … and saw that the controller reacted to it ▼ Given more time for the demo, we also could have: ▽ Added an end-to-end test for this behavior and ran it against our cluster ▽ Loaded and deployed the controller into our cluster
  • 30. 30@Horgix@ContainerDayFRKIND: Next level inception kind in a CI pipeline Demo time ♻
  • 31. 31@Horgix@ContainerDayFRKIND: Next level inception … Not enough time for it today. See the repo at the end of these slides :) kind in a CI pipeline
  • 32. 32@Horgix@ContainerDayFRKIND: Next level inception ... Wrapping up 🎁
  • 33. 33@Horgix@ContainerDayFRKIND: Next level inception kind vs The world ▼ https://github.com/kubernetes/minikube ▼ https://github.com/ubuntu/microk8s ▼ https://github.com/bsycorp/kind ▼ https://github.com/kinvolk/kube-spawn ▼ https://github.com/danderson/virtuakube ▼ https://github.com/kubernetes-sigs/kubeadm-dind-cluster
  • 34. 34@Horgix@ContainerDayFRKIND: Next level inception So… Why kind? ▼ “kind is actually literally my favorite thing right now” -- Bryan Liles @ KCCNC ▼ It’s simple, yet complete ▽ Multi-node (including HA) clusters ▽ Supports building Kubernetes release builds from source ▽ Can be used as a library [1] ▽ Supports Windows in addition to MacOS and Linux ▼ kind is a CNCF certified conformant Kubernetes installer ▼ Developed by cool & smart people ▼ Integrated with official Kubernetes testing tools ▼ Being integrated with more and more stuff every day [1] https://github.com/kubernetes/kubeadm/tree/master/kinder
  • 35. 35@Horgix@ContainerDayFRKIND: Next level inception Take away ▼ kind allows you to spawn a real & lightweight Kubernetes clusterS ▼ This is awesome for debugging and testing: ▽ Kubernetes itself ▽ Applications interacting with Kubernetes directly such as controllers ▼ It’s really fast to create clusters: ~30sec ▼ Integrates well in a CI pipeline and other use-cases Kubernetes is all about community: go contribute to kind :)
  • 36. 36@Horgix@ContainerDayFRKIND: Next level inception Alexis “Horgix” Chotard 4th June 2019 Kubernetes in Docker Next level inception Thank you! Demo : https://github.com/Horgix/kind-demo Slides : https://www.slideshare.net/Horgix Thanks @BenTheElder