We all know how flexible Kubernetes extensions can be - Tekton and Knative are examples. But did you know it's also pretty easy to extend kubectl, the Kubernetes superstar CLI? In this session we see how a kubectl plugin is designed and then from scratch, we will build our own plugin using Quarkus. That will give us the opportunity to discover the command mode of Quarkus, rediscover how native compilation can create super fast binaries, and see how the Kubernetes-client extensions make it super easy to interact with a Kubernetes cluster.
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
13. 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
15. 1. Create a file named kubectl-myplugin
Kubectl plugin > How it works?
15
16. 1. Create a file named kubectl-myplugin
2. Make it executable
Kubectl plugin > How it works?
16
17. 1. Create a file named kubectl-myplugin
2. Make it executable
3. Put it in your PATH
Kubectl plugin > How it works?
17
18. 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/
19. 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/
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 > useful for users
● Discover kubectl plugins
● Easy way to install plugins
● Update easily plugins
34
35. Krew > useful for developers
● Make their plugins discoverable
● Easy way to package their plugins for
multiplatforms (Win, Linux, MacOS)
35
40. 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!
41. 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!
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 > Create your private index & publish into it
New feature: you can create your private index
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 a visual way
http://gumroad.com/aurelievache & http://dev.to/aurelievache