Skip to content

Instantly share code, notes, and snippets.

@lululau
Last active July 14, 2021 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lululau/af9ec7e2960148bf59319c79238a986c to your computer and use it in GitHub Desktop.
Save lululau/af9ec7e2960148bf59319c79238a986c to your computer and use it in GitHub Desktop.
# $HOME/.k9s/plugin.yml
plugin:
# run-stk:
# # Define a mnemonic to invoke the plugin
# shortCut: r
# # What will be shown on the K9s menu
# description: kubectl run lululau/stk
# # Collections of views that support this shortcut. (You can use `all`)
# scopes:
# - deploy
# - service
# - po
# - container
# # The command to run upon invocation. Can use Krew plugins here too!
# command: /bin/bash
# # Whether or not to run the command in background mode
# background: false
# # Defines the command arguments
# args:
# - -c
# - "kubectl run lx-stk --image lululau/stk -it -n $!NAMESPACE --context $CONTEXT"
run-stk:
# Define a mnemonic to invoke the plugin
shortCut: r
# What will be shown on the K9s menu
description: kubectl run lululau/stk
# Collections of views that support this shortcut. (You can use `all`)
scopes:
- deploy
- service
- po
- container
# The command to run upon invocation. Can use Krew plugins here too!
command: sh
# Whether or not to run the command in background mode
background: false
# Defines the command arguments
args:
- -c
- |
if [ -n "${TMUX}" ]; then
tmux new-window -n 'stk ($NAME)' 'kubectl run lx-stk --image lululau/stk -it -n $!NAMESPACE --context $CONTEXT'
else
osascript -e '
tell app "iTerm2"
tell current window
create tab with default profile command "kubectl run lx-stk --image lululau/stk -it -n $!NAMESPACE --context $CONTEXT"
end
end'
fi
yank:
# Define a mnemonic to invoke the plugin
shortCut: Shift-Y
# What will be shown on the K9s menu
description: Yank(copy) kubectl exec cmd to local system's clipboard
# Collections of views that support this shortcut. (You can use `all`)
scopes:
- deploy
- service
- po
- container
# The command to run upon invocation. Can use Krew plugins here too!
command: /bin/bash
# Whether or not to run the command in background mode
background: true
# Defines the command arguments
args:
- -c
- "echo -n 'kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/bash' | pbcopy"
# arthas:
# # Define a mnemonic to invoke the plugin
# shortCut: Shift-J
# # What will be shown on the K9s menu
# description: Launch Arthas (attach to Java process which PID is 1)
# # Collections of views that support this shortcut. (You can use `all`)
# scopes:
# - po
# # The command to run upon invocation. Can use Krew plugins here too!
# command: kubectl
# # Whether or not to run the command in background mode
# background: false
# # Defines the command arguments
# args:
# - exec
# - $NAME
# - -it
# - -n
# - $NAMESPACE
# - --context
# - $CONTEXT
# - '--'
# - /bin/as.sh
# - 1
arthas:
# Define a mnemonic to invoke the plugin
shortCut: Shift-J
# What will be shown on the K9s menu
description: Launch Arthas (attach to Java process which PID is 1)
# Collections of views that support this shortcut. (You can use `all`)
scopes:
- po
# The command to run upon invocation. Can use Krew plugins here too!
command: sh
# Whether or not to run the command in background mode
background: false
# Defines the command arguments
args:
- -c
- |
if [ -n "${TMUX}" ]; then
tmux new-window -n 'arthas ($NAME)' 'kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/as.sh 1'
else
osascript -e '
tell app "iTerm2"
tell current window
create tab with default profile command "/usr/local/bin/kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/as.sh 1"
end
end'
fi
shell:
shortCut: t
description: exec shell on a new tmux window / iTerm2 tab
scopes:
- po
command: sh
background: false
args:
- -c
- |
if [ -n "${TMUX}" ]; then
tmux new-window -n 'shell ($NAME)' 'kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/bash -l'
else
osascript -e '
tell app "iTerm2"
tell current window
create tab with default profile command "/usr/local/bin/kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/bash -l"
end
end'
fi
# lnav:
# # Define a mnemonic to invoke the plugin
# shortCut: Shift-L
# # What will be shown on the K9s menu
# description: Lnav the latest log file in /data/logs/*/
# # Collections of views that support this shortcut. (You can use `all`)
# scopes:
# - po
# # The command to run upon invocation. Can use Krew plugins here too!
# command: kubectl
# # Whether or not to run the command in background mode
# background: false
# # Defines the command arguments
# args:
# - exec
# - $NAME
# - -it
# - -n
# - $NAMESPACE
# - --context
# - $CONTEXT
# - '--'
# - /bin/bash
# - -c
# - "/usr/bin/lnav /data/logs/*/$(ls -t /data/logs/*/ | grep -P '\\d{4}-\\d{2}-\\d{2}.*\\.(log|gz)' | head -1)"
lnav:
# Define a mnemonic to invoke the plugin
shortCut: Shift-L
# What will be shown on the K9s menu
description: Lnav the latest log file in /data/logs/*/
# Collections of views that support this shortcut. (You can use `all`)
scopes:
- po
# The command to run upon invocation. Can use Krew plugins here too!
command: sh
# Whether or not to run the command in background mode
background: false
# Defines the command arguments
args:
- -c
- |
if [ -n "${TMUX}" ]; then
tmux new-window -n 'lnav ($NAME)' "kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/bash -c \"/usr/bin/lnav /data/logs/*/\\\$(ls -t /data/logs/*/ | grep -P '\\d{4}-\\d{2}-\\d{2}.*\\.(log|gz)' | head -1)\""
else
osascript -e '
tell app "iTerm2"
tell current window
create tab with default profile command "/usr/local/bin/kubectl exec $NAME -it -n $!NAMESPACE --context $CONTEXT -- /bin/bash -c '"'"'/usr/bin/lnav /data/logs/*/$(ls -t /data/logs/*/ | grep -P \"\\d{4}-\\d{2}-\\d{2}.*\\.(log|gz)\" | head -1)'"'"'"
end
end'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment