Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Supercharging Your Docker Builds with Skaffold ...

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Supercharging Your Docker Builds with Skaffold & Kaniko

Using Kubernetes for a CI/CD system is a perfect fit, but it’s common to bump up against problems when building container images. Most often, we still rely on Docker for image building inside the cluster, which can be inefficient and doesn’t scale well. To improve the security, performance and stability of our CI/CD tool, Jenkins X, we opted to use Skaffold and Kaniko to build our images in a more Kubernetes-native way.

In this session, we will first help you understand the reasons for choosing Skaffold and Kaniko. Getting into the guts of our own implementation in Jenkins X, we’ll talk about using Skaffold as our build proxy, delegating Docker builds to Kaniko and the ability to switch out Kaniko for a cloud provider native builder such as Google Cloud Builder. Finally, you’ll learn how to be up and running with Skaffold and Kaniko in no time, either with Jenkins X or on your own.

Avatar for Gareth Evans

Gareth Evans

December 04, 2019

Other Decks in Technology

Transcript

  1. © 2019 All Rights Reserved. 2 Who am I? Gareth

    Evans Engineer on Jenkins X github.com/garethjevans @garethbryncyn
  2. © 2019 All Rights Reserved. 3 Skaffold • Local Kubernetes

    Development • Provides a workflow to: • Build • Tag • Test • Run • https://skaffold.dev • https://github.com/GoogleContainerTools/skaffold
  3. © 2019 All Rights Reserved. 4 Skaffold - Build •

    Used to perform a local build (& push) • skaffold init • uses the local docker daemon // skaffold.yaml 1 apiVersion: skaffold/v1 2 kind: Config 3 build: 4 artifacts: 5 - image: gcr.io/project/myimage 6 context: . 7 docker: {} 8 local: {}
  4. © 2019 All Rights Reserved. 5 Skaffold - Tag •

    Control how your container is tagged • Env Variables / Sha // skaffold.yaml 8 tagPolicy: 9 envTemplate: 10 template: '{{.IMAGE_NAME}}:{{.VERSION}}' // VERSION=wip1 skaffold build Generating tags... - gcr.io/project/myiamge -> gcr.io/project/myimage:wip1
  5. © 2019 All Rights Reserved. 6 Skaffold - Test •

    Runs container-structure-tests against a built container • **only if the container has changed // skaffold.yaml 14 test: 15 - image: gcr.io/project/myimage 16 structureTests: 17 - tests/*.yaml // tests/no-go-binary.yaml 1 schemaVersion: 2.0.0 2 3 fileExistenceTests: 4 - name: 'no go binary' 5 path: '/usr/bin/go' 6 shouldExist: false
  6. © 2019 All Rights Reserved. 7 Skaffold - Run (Dev)

    • Deploys a container to a k8s cluster • k8s manifests • helm (v2 & tiller currently) • kustomize Will also watch your source code for changes and redeploy… …lets see it in action!
  7. © 2019 All Rights Reserved. 9 How does this work?

    - Local Development Development Environment Skaffold Host OS (Mac) Docker Daemon Cache docker socket
  8. © 2019 All Rights Reserved. 11 How does this work?

    - Kubernetes k8s node Docker Daemon Cache Pod Pod Pod Container Container Container Container Container Container
  9. © 2019 All Rights Reserved. 1 2 Docker in Docker

    - Risks • Replace a container on another host • Launch a container on another host On a Kubernetes cluster its much worse… • By passes RBAC
  10. © 2019 All Rights Reserved. 1 4 Kaniko • Build

    containers without a docker daemon • Supports Multistage builds • Caching • DockerHub / GCR / ECR / Custom Registry • https://github.com/GoogleContainerTools/kaniko
  11. © 2019 All Rights Reserved. 1 5 Jenkins X •

    Accelerating Continuous Delivery on Kubernetes • Demo on “CloudBees CI/CD powered by Jenkins X”
  12. © 2019 All Rights Reserved. 1 6 What happens in

    Jenkins X? “skaffold build” is automagically replaced with “/kaniko/executor …” Why have we done this?
  13. © 2019 All Rights Reserved. 1 7 Jenkins X -

    Demo • Create a Quickstart • Skaffold -> Kaniko • Override the default build • Something a little more complex
  14. © 2019 All Rights Reserved. 1 9 Join Us https://jenkins-x.io/community

    Office hours, every other thursday at 4-5pm UK time. #jenkins-x-dev #jenkins-x-user