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

Making kubectl plugins mainstream

Making kubectl plugins mainstream

It's the end of 2019 and kubectl plugins are finally gaining steam. Krew plugin manager for kubectl (https://krew.dev) is now hosting over 60 plugins (doubling every 6 months).
This talk is an introduction to kubectl plugin mechanism, and best practices for developing plugins.

Presented at KubeCon 2019 North America, San Diego, CA by @ahmetb.

Ahmet Alp Balkan

November 21, 2019
Tweet

More Decks by Ahmet Alp Balkan

Other Decks in Technology

Transcript

  1. @ahmetb @ahmetb on {twitter, github} ➔ ported docker.exe, docker maintainer

    ~2015 ➔ started Azure Container Registry ~2016 ➔ developer advocate @ Google ~2017 working on Google Cloud Run, Knative, dev tools ➔ kubectx & kubens & kubectl-aliases ➔ Google’s microservices-demo ➔ kubectl plugin manager krew.dev about me 2
  2. @ahmetb agenda 1. kubectl plugins 101 2. krew (plugin manager)

    overview 3. why did we need plugins? 4. let's develop a plugin 5. plugin runtime 6. why develop a plugin? 7. how to distribute your plugins 8. best practices for writing plugins user developer 3
  3. @ahmetb kubectl plugin mechanism in a nutshell 1. write an

    executable program 2. name it kubectl-something 3. put it in your $PATH 4. invoke as "kubectl something" 6
  4. @ahmetb Krew the missing plugin manager for kubectl Kubernetes SIG

    CLI sub-project https://krew.dev (sigs.k8s.io/krew) 8
  5. @ahmetb What is Krew? - Functionality - discover plugins -

    install plugins - update plugins - remove plugins - Started in 2018 as an intern project at Google Cloud. - Donated to Kubernetes project in May 2019. - Not an actual package manager - Doesn't handle dependencies. 9
  6. @ahmetb Storage plugins Network plugins Custom controllers Scheduler extension/ custom

    scheduler Custom resources (CRD) API Access Extensions (Admission webhooks, authentication webhook, authz/RBAC webhooks) kubernetes.io/docs/concepts/extend-kubernetes/extend-cluster Kubectl Plugins 22
  7. @ahmetb official command plugin KEP + approval no approvals usefulness

    and stability no restrictions hosted in kubectl codebase (Go only) any language tied to Kubernetes release cycle release at your own pace has to be consistent with kubectl has room for creativity takes O(months)..O(years) from alpha→beta→stable develop & distribute in O(hours) 24
  8. @ahmetb ➔ deprecating a kubectl command is painful. ➔ let

    people experiment, graduate successful ones. experimentation 29
  9. @ahmetb kubectl plugin mechanism in a nutshell 1. write an

    executable program 2. name it kubectl-something 3. put it in your $PATH 4. invoke as "kubectl something" 31
  10. @ahmetb "kubectl a b c" → is "a" builtin command?

    → kubectl-a-b-c ? → kubectl-a-b ? → kubectl-a ? plugin lookup 33
  11. @ahmetb plugin execution runtime 1. look for the plugin executable

    in PATH 2. execve() syscall replace kubectl with the plugin process ◆ inherit environment variables ◆ inherit standard streams ◆ determine exitcode of kubectl invocation 34
  12. @ahmetb your tool has a weird name and it's not

    very memorable rakkess kubectl access-matrix ketall kubectl get-all ksort kubectl sort-manifests kail kubectl tail feels more natural 36
  13. @ahmetb enhances existing kubectl command builtin: query one resource at

    a time plugin: shows a matrix of all capabilities 41
  14. @ahmetb enhances existing kubectl command plugin: queries for all subjects

    in the cluster builtin: query one user at a time 42
  15. @ahmetb plugin developer problems • How can people hear about

    my plugin? • How can I package my plugin for others to install? • How can I deliver updates? If you're a kubectl plugin developer, Krew solves these problems. 44
  16. @ahmetb ...users to: • install plugins • keep them up

    to date • remove plugins cleanly ...developers to: • make their plugins discoverable by users • package their plugins for multiple platforms • deliver updates Krew helps... 49
  17. @ahmetb packaging & distributing with Krew 1. make your plugin

    available as a .tar.gz or .zip archive 2. write a plugin manifest 3. submit a pull request to krew-index 4. party! 51
  18. @ahmetb plugin manifest apiVersion: krew.googlecontainertools.github.com/v1alpha2 kind: Plugin metadata: name: "access-matrix"

    spec: version: "v0.4.0" homepage: "https://github.com/corneliusweig/rakkess" platforms: - <PLATFORM1> - <PLATFORM2> - <PLATFORM3> - ... 52
  19. @ahmetb ... # continued spec: platforms: - selector: matchLabels: os:

    linux arch: amd64 uri: https://github.com/corneliusweig/rakkess/releases/v0.4.0/bundle.tar.gz sha256: 7a16c61dfc4e2924fdedc894d59db7820bc4643a58d9a853c4eb83eadd4deee8 files: - from: ./rakkess_linux-amd64 to: ./rakkess - from: ./LICENSE to: "." bin: ./rakkess plugin manifest - platform 53
  20. @ahmetb recipes for success 1. name your plugin for clarity

    (see Krew Naming Guide) 2. reuse flags/options and KUBECONFIG detection from k8s.io/cli-runtime/pkg/genericclioptions 3. import auth plugins for cloud clusters import _ "k8s.io/client-go/plugin/pkg/client/auth" 54
  21. @ahmetb Join us make kubectl plugins better! • Become a

    kubectl plugin developer, submit your plugins to Krew.dev. • Join developing the Krew project. ◦ you don’t need to be a Kubernetes expert ◦ clean and young codebase ◦ low bug count, high creativity • Bring your ideas to Kubernetes SIG CLI. 56