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

Vikube: Operate Kubernetes in Vim

Vikube: Operate Kubernetes in Vim

Yo-An Lin

June 20, 2018
Tweet

More Decks by Yo-An Lin

Other Decks in Technology

Transcript

  1. VIKUBE
    VIM & KUBERNETES OPERTATION

    View Slide

  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.

    View Slide

  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.

    View Slide

  4. KUBERNETES
    5 MINUTES

    View Slide

  5. KUBERNETES
    ARCHITECTUR
    E REVIEW

    View Slide

  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

    View Slide

  7. KUBERNETES
    RESOURCE
    REVIEW

    View Slide

  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.

    View Slide

  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,

    View Slide

  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.

    View Slide

  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.

    View Slide

  12. OPERATION
    DEBUGGING
    KUBERNETES

    View Slide

  13. VIKUBE
    KUBERNETES VERBS
    ▸ kubectl create
    ▸ kubectl delete
    ▸ kubectl get
    ▸ kubectl edit
    ▸ kubectl replace
    ▸ kubectl patch

    View Slide

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

    View Slide

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

    View Slide

  16. kubectl get pods -o wide
    取得現在正在運⾏行行的 Pods 以及其 IP 與正在運⾏行行的 Node
    CHECK PODS WITH IP AND
    NODES

    View Slide

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

    View Slide

  18. kubectl get pods -w
    監測 Pods 動態
    WATCH PODS

    View Slide

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

    View Slide

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

    View Slide

  21. CRASHLOOPBACKOFF!

    View Slide

  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)

    View Slide

  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 ...

    View Slide

  24. VIKUBE
    SOLUTIONS TO THESE REPEATED COMMANDS
    ▸ kube-shell
    ▸ kube-prompt
    ▸ kubesh

    View Slide

  25. All of them requires you
    to type subcommands

    View Slide

  26. I have Vim

    View Slide

  27. I have
    Kubernetes

    View Slide

  28. View Slide

  29. WHAT'S
    VIKUBE?

    View Slide

  30. USE VIM AS
    THE USER
    INTERFACE

    View Slide

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

    View Slide

  32. View Slide

  33. View Slide

  34. View Slide

  35. View Slide

  36. Live Demo

    View Slide

  37. WHY USE
    VIM?

    View Slide

  38. 跨平台

    View Slide

  39. 可遠端執⾏

    View Slide

  40. 超快

    View Slide

  41. 超⽅便

    View Slide

  42. View Slide

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

    View Slide

  44. View Slide

  45. Why Is It So
    Hard?

    View Slide

  46. View Slide

  47. 嚇你的

    View Slide

  48. View Slide

  49. HOW DOES
    IT WORK?

    View Slide

  50. View Slide

  51. VIKUBE
    VIEWPORTS AND BUFFERS

    View Slide

  52. VIKUBE
    TAB VIEWPORTS AND BUFFERS

    View Slide

  53. View Slide

  54. LEARN VIM
    IN 5 MINUTES

    View Slide

  55. Scope

    View Slide

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

    View Slide

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

    View Slide

  58. Function

    View Slide

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

    View Slide

  60. function! Foo()
    let x = 0
    function! Bar() closure
    let x += 1
    return x
    endfunction
    return funcref('Bar')
    endfunction
    let F = Foo()
    echo F()

    View Slide

  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.

    View Slide

  62. Command

    View Slide

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

    View Slide

  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)

    View Slide

  65. Define The
    Source

    View Slide

  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

    View Slide

  67. Render The
    Screen

    View Slide

  68. :tabnew

    View Slide

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

    View Slide

  70. :setlocal updatetime=2000

    View Slide

  71. cal s:render()
    Script Scope

    View Slide

  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

    View Slide

  73. Now, Get Your
    DevOps Done in Vim

    View Slide

  74. github.com/c9s/
    vikube.vim

    View Slide

  75. THANK
    YOU

    View Slide