Build your own
kubectl plugin
using Quarkus
Sebastien Blanc
● @sebi2706
● sblanc@redhat.com
● Currently Red Hat’s Director of Developer Experience
● Java Champion
● Passion-Driven-Developer with one goal : share his
passion by giving talks that are pragmatic, fun and
focused on live coding
kubectl
Kubectl > pronunciation fight
Disclaimer
Pronounce “kubectl” as you want :-)
Kubectl > kubernetes tool/cli
Kubectl > a very logical CLI!
Kubectl > a very logical CLI!
Kubectl > a very logical CLI!
Kubectl > cool, but can i extend it?
Kubectl plugins
Kubectl: tied to core release cycle
Wants to implement a new feature in Kubectl?
So … Forget about it and think about plugins instead ;-)
KuberneteS, an extensible world
Plugins > Why it’s useful?
Extend kubectl with extra functionality
that still feels like kubectl
● e.g. kubectl service-catalog [...]
Encapsulate repetitive workflow
● e.g checking a secret resource, check logs
Plugins > language agnostic!
1. Create a file named kubectl-myplugin
Kubectl plugin > How it works?
15
1. Create a file named kubectl-myplugin
2. Make it executable
Kubectl plugin > How it works?
16
1. Create a file named kubectl-myplugin
2. Make it executable
3. Put it in your PATH
Kubectl plugin > How it works?
17
1. Create a file named kubectl-myplugin
2. Make it executable
3. Put it in your PATH
4. Run “kubectl myplugin”
Kubectl plugin > How it works?
18
https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
1. How to manage the CLI options and parameters ?
2. How to make it interact with a cluster ?
3. How to quickly bootstrap a project ?
4. How to make it executable ?
5. How to make it fast ?
Kubectl plugin > Using Java ?
19
https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
PLUGIN
PARAMETER
OPTION
Kubectl plugin > Handle parameters and options
20
https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
Meet picocli
22
https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
Meet Fabric8 Client
24
https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
Java on steroids !
//DEPS info.picocli:picocli:4.5.0
import picocli.CommandLine;
import picocli.CommandLine.
Command;
import picocli.CommandLine.
Parameters;
import java.util.concurrent.Callable;
@Command(name = "intro")
class intro implements Callable<Integer> {
SUPERSONIC SUBATOMIC JAVA
Quarkus Extensions
Going Native
Let’s create a plugin!
Our plugin > how to share it?
What is krew?
● A package manager for kubectl plugins
○ Like “brew” but for kubectl :)
○ Developed summer of 2018 by Google intern
Luk Burchard (@lbb)
● Krew is open sourced, try it:
https://github.com/kubernetes-sigs/krew
33
Krew > useful for users
● Discover kubectl plugins
● Easy way to install plugins
● Update easily plugins
34
Krew > useful for developers
● Make their plugins discoverable
● Easy way to package their plugins for
multiplatforms (Win, Linux, MacOS)
35
Krew
36
Krew > search
37
Krew > list
38
Krew > install
39
Krew > install not published plugins
40
Your plugin is not already published/available on krew
index?
Not problem, you can also install it through Krew!
Krew > install not published plugins
41
Your plugin is not already published/available on krew
index?
Not problem, you can also install it through Krew!
krew > Local Architecture
42
Publishing on Krew
43
Index:
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: season
spec:
homepage: https://github.com/scraly/kubectl-season
shortDescription: Display seasonal emoji randomly before resources name
version: v0.0.3
description: |
This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji
just before the resources name. It's a special seasonal mode.
platforms:
- selector:
matchExpressions:
- key: os
operator: In
values:
- darwin
- linux
uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz
sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8
bin: kubectl-season-0.0.3/kubectl-season
kubectl-season/.krew.yaml
44
Publishing on Krew > manifest file
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: season
spec:
homepage: https://github.com/scraly/kubectl-season
shortDescription: Display seasonal emoji randomly before resources name
version: v0.0.3
description: |
This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji
just before the resources name. It's a special seasonal mode.
platforms:
- selector:
matchExpressions:
- key: os
operator: In
values:
- darwin
- linux
uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz
sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8
bin: kubectl-season-0.0.3/kubectl-season
K8s Object
45
kubectl-season/.krew.yaml
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: season
spec:
homepage: https://github.com/scraly/kubectl-season
shortDescription: Display seasonal emoji randomly before resources name
version: v0.0.3
description: |
This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji
just before the resources name. It's a special seasonal mode.
platforms:
- selector:
matchExpressions:
- key: os
operator: In
values:
- darwin
- linux
uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz
sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8
bin: kubectl-season-0.0.3/kubectl-season
Plugin
Info
46
kubectl-season/.krew.yaml
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: season
spec:
homepage: https://github.com/scraly/kubectl-season
shortDescription: Display seasonal emoji randomly before resources name
version: v0.0.3
description: |
This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji
just before the resources name. It's a special seasonal mode.
platforms:
- selector:
matchExpressions:
- key: os
operator: In
values:
- darwin
- linux
uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz
sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8
bin: kubectl-season-0.0.3/kubectl-season
Platforms[]
47
kubectl-season/.krew.yaml
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: season
spec:
homepage: https://github.com/scraly/kubectl-season
shortDescription: Display seasonal emoji randomly before resources name
version: v0.0.3
description: |
This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji
just before the resources name. It's a special seasonal mode.
platforms:
- selector:
matchExpressions:
- key: os
operator: In
values:
- darwin
- linux
uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz
sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8
bin: kubectl-season-0.0.3/kubectl-season
Match
Platform
48
kubectl-season/.krew.yaml
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: season
spec:
homepage: https://github.com/scraly/kubectl-season
shortDescription: Display seasonal emoji randomly before resources name
version: v0.0.3
description: |
This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji
just before the resources name. It's a special seasonal mode.
platforms:
- selector:
matchExpressions:
- key: os
operator: In
values:
- darwin
- linux
uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz
sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8
bin: kubectl-season-0.0.3/kubectl-season
Download
49
kubectl-season/.krew.yaml
apiVersion: krew.googlecontainertools.github.com/v1alpha2
kind: Plugin
metadata:
name: season
spec:
homepage: https://github.com/scraly/kubectl-season
shortDescription: Display seasonal emoji randomly before resources name
version: v0.0.3
description: |
This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji
just before the resources name. It's a special seasonal mode.
platforms:
- selector:
matchExpressions:
- key: os
operator: In
values:
- darwin
- linux
uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz
sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8
bin: kubectl-season-0.0.3/kubectl-season
Plugin
Binary
50
kubectl-season/.krew.yaml
Publishing on Krew > Pull Request
51
https://github.com/kubernetes-sigs/krew-index
Krew > Create your private index & publish into it
New feature: you can create your private index
Krew > update index
53
Krew > upgrade plugins
54
Krew > our fav plugins
55
> view-secret
Krew > our fav plugins
56
> view-secret
> view-cert
Krew > our fav plugins
57
> view-secret
> view-cert
> view-utilization
Krew > our fav plugins
58
> view-secret
> view-cert
> view-utilization
> neat
best practices
Plugin creation > best practices
60
Naming is important
● DON’T: kubectl-version
Not possible to create plugins that
overwrite existing kubectl commands
Plugin creation > best practices
61
Naming is important
● DON’T: kubectl service
Unclear what the plugin is doing
with service
● DON’T: kubectl open
Unclear what it is opening
● DO: kubectl open-svc
The plugin will open a service :-)
Plugin creation > best practices
62
Golang
https://github.com/kubernetes/sample-cli-plugin
Plugin creation > best practices
63
krew-release-bot
https://github.com/rajatjindal/krew-release-bot
Golang
Plugin creation > best practices
64
krew-release-bot Go releaser
https://goreleaser.com/
Golang
understanding in a visual way
http://gumroad.com/aurelievache & http://dev.to/aurelievache
Conclusion
$ kubectl thank-you
http://bit.ly/kubernetes-plugin-krew-asynconf
@aurelievache | @Gaelleacas
$ kubectl apply -f questions.yaml
Qui parle quand ?
● why this talk? (G)
● kubectl (A)
● kubectl plugin (G)
● create a plugin (A)
● krew (G)
● best practices (A)
● sketchnotes (G)
● conclusion (G)
● thank you+feedbacks+questions (A)
👍
Building kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech Talk
Building kubectl plugins with Quarkus | DevNation Tech Talk

Building kubectl plugins with Quarkus | DevNation Tech Talk

  • 1.
    Build your own kubectlplugin using Quarkus
  • 2.
    Sebastien Blanc ● @sebi2706 ●sblanc@redhat.com ● Currently Red Hat’s Director of Developer Experience ● Java Champion ● Passion-Driven-Developer with one goal : share his passion by giving talks that are pragmatic, fun and focused on live coding
  • 3.
  • 4.
    Kubectl > pronunciationfight Disclaimer Pronounce “kubectl” as you want :-)
  • 5.
  • 6.
    Kubectl > avery logical CLI!
  • 7.
    Kubectl > avery logical CLI!
  • 8.
    Kubectl > avery logical CLI!
  • 9.
    Kubectl > cool,but can i extend it?
  • 10.
  • 11.
    Kubectl: tied tocore release cycle Wants to implement a new feature in Kubectl? So … Forget about it and think about plugins instead ;-)
  • 12.
  • 13.
    Plugins > Whyit’s useful? Extend kubectl with extra functionality that still feels like kubectl ● e.g. kubectl service-catalog [...] Encapsulate repetitive workflow ● e.g checking a secret resource, check logs
  • 14.
  • 15.
    1. Create afile named kubectl-myplugin Kubectl plugin > How it works? 15
  • 16.
    1. Create afile named kubectl-myplugin 2. Make it executable Kubectl plugin > How it works? 16
  • 17.
    1. Create afile named kubectl-myplugin 2. Make it executable 3. Put it in your PATH Kubectl plugin > How it works? 17
  • 18.
    1. Create afile named kubectl-myplugin 2. Make it executable 3. Put it in your PATH 4. Run “kubectl myplugin” Kubectl plugin > How it works? 18 https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
  • 19.
    1. How tomanage the CLI options and parameters ? 2. How to make it interact with a cluster ? 3. How to quickly bootstrap a project ? 4. How to make it executable ? 5. How to make it fast ? Kubectl plugin > Using Java ? 19 https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
  • 20.
    PLUGIN PARAMETER OPTION Kubectl plugin >Handle parameters and options 20 https://kubernetes.io/docs/tasks/extend-kubectl/kubectl-plugins/
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
    //DEPS info.picocli:picocli:4.5.0 import picocli.CommandLine; importpicocli.CommandLine. Command; import picocli.CommandLine. Parameters; import java.util.concurrent.Callable; @Command(name = "intro") class intro implements Callable<Integer> {
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
    Our plugin >how to share it?
  • 33.
    What is krew? ●A package manager for kubectl plugins ○ Like “brew” but for kubectl :) ○ Developed summer of 2018 by Google intern Luk Burchard (@lbb) ● Krew is open sourced, try it: https://github.com/kubernetes-sigs/krew 33
  • 34.
    Krew > usefulfor users ● Discover kubectl plugins ● Easy way to install plugins ● Update easily plugins 34
  • 35.
    Krew > usefulfor developers ● Make their plugins discoverable ● Easy way to package their plugins for multiplatforms (Win, Linux, MacOS) 35
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
    Krew > installnot published plugins 40 Your plugin is not already published/available on krew index? Not problem, you can also install it through Krew!
  • 41.
    Krew > installnot published plugins 41 Your plugin is not already published/available on krew index? Not problem, you can also install it through Krew!
  • 42.
    krew > LocalArchitecture 42
  • 43.
  • 44.
    Index: apiVersion: krew.googlecontainertools.github.com/v1alpha2 kind: Plugin metadata: name:season spec: homepage: https://github.com/scraly/kubectl-season shortDescription: Display seasonal emoji randomly before resources name version: v0.0.3 description: | This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji just before the resources name. It's a special seasonal mode. platforms: - selector: matchExpressions: - key: os operator: In values: - darwin - linux uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8 bin: kubectl-season-0.0.3/kubectl-season kubectl-season/.krew.yaml 44 Publishing on Krew > manifest file
  • 45.
    apiVersion: krew.googlecontainertools.github.com/v1alpha2 kind: Plugin metadata: name:season spec: homepage: https://github.com/scraly/kubectl-season shortDescription: Display seasonal emoji randomly before resources name version: v0.0.3 description: | This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji just before the resources name. It's a special seasonal mode. platforms: - selector: matchExpressions: - key: os operator: In values: - darwin - linux uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8 bin: kubectl-season-0.0.3/kubectl-season K8s Object 45 kubectl-season/.krew.yaml
  • 46.
    apiVersion: krew.googlecontainertools.github.com/v1alpha2 kind: Plugin metadata: name:season spec: homepage: https://github.com/scraly/kubectl-season shortDescription: Display seasonal emoji randomly before resources name version: v0.0.3 description: | This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji just before the resources name. It's a special seasonal mode. platforms: - selector: matchExpressions: - key: os operator: In values: - darwin - linux uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8 bin: kubectl-season-0.0.3/kubectl-season Plugin Info 46 kubectl-season/.krew.yaml
  • 47.
    apiVersion: krew.googlecontainertools.github.com/v1alpha2 kind: Plugin metadata: name:season spec: homepage: https://github.com/scraly/kubectl-season shortDescription: Display seasonal emoji randomly before resources name version: v0.0.3 description: | This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji just before the resources name. It's a special seasonal mode. platforms: - selector: matchExpressions: - key: os operator: In values: - darwin - linux uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8 bin: kubectl-season-0.0.3/kubectl-season Platforms[] 47 kubectl-season/.krew.yaml
  • 48.
    apiVersion: krew.googlecontainertools.github.com/v1alpha2 kind: Plugin metadata: name:season spec: homepage: https://github.com/scraly/kubectl-season shortDescription: Display seasonal emoji randomly before resources name version: v0.0.3 description: | This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji just before the resources name. It's a special seasonal mode. platforms: - selector: matchExpressions: - key: os operator: In values: - darwin - linux uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8 bin: kubectl-season-0.0.3/kubectl-season Match Platform 48 kubectl-season/.krew.yaml
  • 49.
    apiVersion: krew.googlecontainertools.github.com/v1alpha2 kind: Plugin metadata: name:season spec: homepage: https://github.com/scraly/kubectl-season shortDescription: Display seasonal emoji randomly before resources name version: v0.0.3 description: | This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji just before the resources name. It's a special seasonal mode. platforms: - selector: matchExpressions: - key: os operator: In values: - darwin - linux uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8 bin: kubectl-season-0.0.3/kubectl-season Download 49 kubectl-season/.krew.yaml
  • 50.
    apiVersion: krew.googlecontainertools.github.com/v1alpha2 kind: Plugin metadata: name:season spec: homepage: https://github.com/scraly/kubectl-season shortDescription: Display seasonal emoji randomly before resources name version: v0.0.3 description: | This plugin allows you to add randomly a seasonal (halloween, christmas, easter...) emoji just before the resources name. It's a special seasonal mode. platforms: - selector: matchExpressions: - key: os operator: In values: - darwin - linux uri: https://github.com/scraly/kubectl-season/archive/v0.0.3.tar.gz sha256: ee194028b38fd102becc552ebfc7a7f38253acfb949835aa80bb1eb46eed3de8 bin: kubectl-season-0.0.3/kubectl-season Plugin Binary 50 kubectl-season/.krew.yaml
  • 51.
    Publishing on Krew> Pull Request 51 https://github.com/kubernetes-sigs/krew-index
  • 52.
    Krew > Createyour private index & publish into it New feature: you can create your private index
  • 53.
    Krew > updateindex 53
  • 54.
    Krew > upgradeplugins 54
  • 55.
    Krew > ourfav plugins 55 > view-secret
  • 56.
    Krew > ourfav plugins 56 > view-secret > view-cert
  • 57.
    Krew > ourfav plugins 57 > view-secret > view-cert > view-utilization
  • 58.
    Krew > ourfav plugins 58 > view-secret > view-cert > view-utilization > neat
  • 59.
  • 60.
    Plugin creation >best practices 60 Naming is important ● DON’T: kubectl-version Not possible to create plugins that overwrite existing kubectl commands
  • 61.
    Plugin creation >best practices 61 Naming is important ● DON’T: kubectl service Unclear what the plugin is doing with service ● DON’T: kubectl open Unclear what it is opening ● DO: kubectl open-svc The plugin will open a service :-)
  • 62.
    Plugin creation >best practices 62 Golang https://github.com/kubernetes/sample-cli-plugin
  • 63.
    Plugin creation >best practices 63 krew-release-bot https://github.com/rajatjindal/krew-release-bot Golang
  • 64.
    Plugin creation >best practices 64 krew-release-bot Go releaser https://goreleaser.com/ Golang
  • 65.
    understanding in avisual way http://gumroad.com/aurelievache & http://dev.to/aurelievache
  • 66.
  • 67.
  • 68.
  • 69.
    $ kubectl apply-f questions.yaml
  • 71.
    Qui parle quand? ● why this talk? (G) ● kubectl (A) ● kubectl plugin (G) ● create a plugin (A) ● krew (G) ● best practices (A) ● sketchnotes (G) ● conclusion (G) ● thank you+feedbacks+questions (A) 👍