Vikube: Operate Kubernetes in Vim

Vikube: Operate Kubernetes in Vim

7490b4e3e9cb85a1f7dc0c8ea01a86e5?s=128

Yo-An Lin

June 20, 2018
Tweet

Transcript

  1. VIKUBE VIM & KUBERNETES OPERTATION

  2. VIKUBE @C9S ▸ Started open source development from the Perl

    community since 2007 ▸ Maintained over 50 modules on CPAN. The largest Perl module platform. ▸ Found over 200 projects on GitHub from C, VimL, Perl, JavaScript, TypeScript and PHP. ▸ Contributed code to Facebook HHVM, PHP Zend Engine and the Google Go project.
  3. VIKUBE @C9S & KUBERNETRES ▸ Started using Kubernetes for the

    deep learning training platform since last year (Mid 2017) ▸ As a Developer, we heavily use Kubernetes API for integrating the applications. ▸ As a DevOps, we integrate CI/CD with Kubernetes, and use Vikube for debugging the Kubernetes deployments.
  4. KUBERNETES 5 MINUTES

  5. KUBERNETES ARCHITECTUR E REVIEW

  6. Minion kubelet Pod Container Master API Server Replication Controller Scheduler

    Pod Container Minion kubelet Pod Container Pod Container Minion kubelet Pod Container Pod Container
  7. KUBERNETES RESOURCE REVIEW

  8. 5 MINUTES KUBERNETES POD ▸ A pod (as in a

    pod of whales or pea pod) is a group of one or more containers (such as Docker containers) ▸ with shared storage/network, ▸ and a specification for how to run the containers.
  9. 5 MINUTES KUBERNETES REPLICATION CONTROLLER ▸ A ReplicationController ensures that

    a specified number of pod replicas are running at any one time. In other words, a ReplicationController makes sure that a pod or a homogeneous set of pods is always up and available.with shared storage/network,
  10. 5 MINUTES KUBERNETES REPLICASET ▸ ReplicaSet is the next-generation Replication

    Controller. The only difference between a ReplicaSet and a Replication Controller right now is the selector support. ▸ Difference: ReplicaSet supports the new set-based selector requirements whereas a Replication Controller only supports equality-based selector requirements.
  11. 5 MINUTES KUBERNETES DEPLOYMENT ▸ A Deployment controller provides declarative

    updates for Pods and ReplicaSets. ▸ You describe a desired state in a Deployment object, and the Deployment controller changes the actual state to the desired state at a controlled rate. ▸ You can define Deployments to create new ReplicaSets, or to remove existing Deployments and adopt all their resources with new Deployments.
  12. OPERATION DEBUGGING KUBERNETES

  13. VIKUBE KUBERNETES VERBS ▸ kubectl create ▸ kubectl delete ▸

    kubectl get ▸ kubectl edit ▸ kubectl replace ▸ kubectl patch
  14. kubectl get pods 取得現在在預設名稱空間中正在運⾏行行的 Pods CHECK PODS

  15. kubectl get pvc 檢查現在可使⽤用的 Persistent Volume Claim CHECK PERSISTENT VOLUME

    CLAIM
  16. kubectl get pods -o wide 取得現在正在運⾏行行的 Pods 以及其 IP 與正在運⾏行行的

    Node CHECK PODS WITH IP AND NODES
  17. kubectl get pods -o wide \ --all-namespaces 取得現在所有名稱空間中正在運⾏行行的 Pods 以及其

    IP 與正在運⾏行行的 Node CHECK PODS FROM ALL NAMESPACES
  18. kubectl get pods -w 監測 Pods 動態 WATCH PODS

  19. kubectl logs -c webapp -f nginx-xxx 調閱 Container 紀錄 TAIL

    CONTAINER LOG
  20. kubectl exec -it nginx-xxx /bin/sh 在⽬目前正在運⾏行行中的 Container 中執⾏行行命令 EXECUTE COMMAND

    IN THE CONTAINER
  21. CRASHLOOPBACKOFF!

  22. VIKUBE SOP FOR FIXING CRASHLOOPBACKOFF ▸ Check the logs of

    the containers in the pod ▸ Describe the pod ▸ Check if the volume is available? ▸ Check the events of the pod ▸ Check the availability of the image ▸ Exec into the container and try to reproduce the problem ▸ Check the authentication to the image repository (usually happens to the images on ECS or GCR)
  23. VIKUBE TIME WASTED ▸ Copy the target pod name ▸

    Enter the describe command and paste the pod name ▸ Enter the logs command and paste the pod name ▸ Enter the exec command and paste the pod name ▸ Get the events and then use the pod name to grep ▸ Or, get the related deployment, statefulset ...
  24. VIKUBE SOLUTIONS TO THESE REPEATED COMMANDS ▸ kube-shell ▸ kube-prompt

    ▸ kubesh
  25. All of them requires you to type subcommands

  26. I have Vim

  27. I have Kubernetes

  28. None
  29. WHAT'S VIKUBE?

  30. USE VIM AS THE USER INTERFACE

  31. vim -c ":Vikube" All you need is VIM ENTERING VIKUBE

  32. None
  33. None
  34. None
  35. None
  36. Live Demo

  37. WHY USE VIM?

  38. 跨平台

  39. 可遠端執⾏

  40. 超快

  41. 超⽅便

  42. None
  43. Why can't you Get out of vim?

  44. None
  45. Why Is It So Hard?

  46. None
  47. 嚇你的

  48. None
  49. HOW DOES IT WORK?

  50. None
  51. VIKUBE VIEWPORTS AND BUFFERS

  52. VIKUBE TAB VIEWPORTS AND BUFFERS

  53. None
  54. LEARN VIM IN 5 MINUTES

  55. Scope

  56. b: g: s: w: t: Buffer Scope Global Scope Script

    Scope Window Scope Tab Scope
  57. b: g: s: w: t: let foo = 1 let

    let let let foo = 1 foo = 1 foo = 1 foo = 1
  58. Function

  59. function! Add(x, y) return a:x + a:y endfunction let y

    = Add(1,2)
  60. function! Foo() let x = 0 function! Bar() closure let

    x += 1 return x endfunction return funcref('Bar') endfunction let F = Foo() echo F()
  61. :function {arguments} {name} ( ) range abort closure dict :endfunction

    When the [abort] argument is added, the function will abort as soon as an error is detected. When the [closure] argument is added, the function can access variables and arguments from the outer scope. This is usually called a closure. When the [dict] argument is added, the function must be invoked through an entry in a |Dictionary|. The local variable "self" will then be set to the dictionary. When the [closure] argument is added, the function can access variables and arguments from the outer scope.
  62. Command

  63. :w :q :buffers :split :vsplit

  64. -buffer -range command! {name} {command} -range=% -range=N -bar -count=N -bang

    -register The first arguments to the command can be an optional register name The command will only be available in the current buffer {options} Range allowed, the default is the current line Range allowed, the default is the whole file A default N which is specified in the line number position A count (default N) which is specified either in the line number position, or as an initial argument The command can be followed by a "|" and another command. A "|" inside the command argument is not allowed then. The command can take a ! modifier (like :q or :w)
  65. Define The Source

  66. fun! s:source() let cmd = s:cmdbase() let cmd = cmd

    . " get " . b:resource_type if b:wide let cmd = cmd . " -o wide" endif if b:all_namespace let cmd = cmd . " --all-namespaces" endif if b:show_all let cmd = cmd . " --show-all" endif redraw | echomsg cmd return system(cmd . "| awk 'NR == 1; NR > 1 {print $0 | \"sort -b -k1\"}'") endf
  67. Render The Screen

  68. :tabnew

  69. :setlocal noswapfile nonumber :setlocal nobuflisted buftype=nofile bufhidden=wipe

  70. :setlocal updatetime=2000

  71. cal s:render() Script Scope

  72. fun! s:render() let save_cursor = getcurpos() if b:source_changed || !exists('b:source_cache')

    let b:source_cache = s:source() let b:source_changed = 0 endif setlocal modifiable " clear the buffer redraw normal ggdG " draw the result redraw put=out " remove the first empty line redraw normal ggdd endf Data Source Clear the screen and redraw Render the screen Unlock buffer
  73. Now, Get Your DevOps Done in Vim

  74. github.com/c9s/ vikube.vim

  75. THANK YOU