Skip to content

Latest commit

 

History

History
256 lines (185 loc) · 6.78 KB

kubernetes-admin.md

File metadata and controls

256 lines (185 loc) · 6.78 KB

Kubernetes Administration

Table of Contents

Tools

  • kubectl
    • to interact with the clusters
  • azure-cli
    • to interact with all Azure Resources
  • krew
    • to install convenient plugins for kubectl
  • kubecolor
    • to colorize the output of kubectl

kubecolor

Plugins in Krew

Set up & Installation

alias k="kubectl"
alias kk="kubectl krew"

# or

alias k="kubecolor"
alias kk="kubecolor krew"
alias kgp="kubecolor get pod"
alias kgd="kubecolor get deployment"
alias kgcr="kubecolor get certificaterequest"
alias kgs="kubecolor get service"
alias kgi="kubecolor get ingress"

alias kdp="kubecolor describe pod"
alias kdd="kubecolor describe deployment"
alias kdcr="kubecolor describe certificaterequest"
alias kds="kubecolor describe service"
alias kdi="kubecolor describe ingress"

kk install ctx # switch between contexts easily
kk install ns # switch between namespaces easily
kk install stern # log tailing of multiple pods
kk install score # static manifest analyzer (good on CI/CD)
kk install allctx # fire commands to multiple contexts
kk install iexec # search and exec pod
kk install kor # discover unused resources
kk install kubescape # scan security vulnerability on resources (good on CI/CD)
kk install kubespy # temporarily add more libraries to the pod for debugging
kk install kurt # show all restarted resources
kk install outdated # detect what resources are outdated and show the latest version available

Set up

PROMPT=$PROMPT'$(kube_ps1)'

How to use

  • switch between contexts easily
k ctx # list all contexts
k ctx nexplore-dev # switch to context `nexplore-dev`
k ctx - # switch to the previous context
  • switch between namespaces easily
k ns # list all namespaces
k ns core # switch to namespace core
  • log tailing of multiple pods
k stern apps -A  # log tailing all components with pattern `apps`
  • static manifest analyzer, can be used with CI/CD
helm template my-app | kube-score score -
  • fire commands to multiple contexts
k allctx get pods --like apps -A
  • search and exec pod
k iexec app # will show a list to select

# Use the arrow keys to navigate: ↓ ↑ → ←
# ? Select Pod:
#   Namespace: app | Pod: ▸ app-5d4c8755cb-aaaaa
#   Namespace: app | Pod: app-5d4c8755cb-bbbbb
# ↓ Namespace: app | Pod: app-background-job-6b577d899f-gnq4s
  • discover unused resources
k kor all
  • scan security vulnerability on resources, operator is also available
k kubescape scan
  • temporarily add more libraries to the pod for debugging
k spy my-app -n app
  • show all restarted nodes and pods
k kurt all

# kurt: Kubernetes Restart Tracker

# ==========

#  Namespace Restarts

#  datadog  3
#  helloworld  1
#  foobar  0
#  core 0
#  keycloak  0

# ==========

#  Node Restarts

#  aks-d4sv5-29292033-vmss000000  4
#  aks-d4sv5-29292033-vmss00000a  0
#  aks-d4sv5-29292033-vmss000002  0
#  aks-d4sv5-29292033-vmss000004  0

# ==========

#  Label       Restarts

#  pod-template-generation:2    3
#  app.kubernetes.io/instance:datadog-agent 3
#  app.kubernetes.io/name:datadog-agent  3
#  app.kubernetes.io/managed-by:Helm   3
#  app.kubernetes.io/component:agent   3

# ==========

#  Pod      Namespace Restarts

#  datadog-agent-zwhd9 datadog  3
#  helloworld-backend-7576dcc5cd-g7tpp  helloworld  1
#  foobar-backend-7bd76cbbc5-jsjsz   foobar  0
#  smalltown-backend-769555d79c-7qwlm  smalltown  0
#  sleepyday-backend-6499b67b87-r96x8 sleepyday  0
  • detect what resources are outdated and show the latest version available
k outdated

# Image                                                  Current               Latest               Behind
# nexplore.azurecr.io/flagship/inspection-b...     prod-26           Unable to get image data
# quay.io/jetstack/cert-manager-controller               v1.11.1               4.0.0-c875c7         3
# quay.io/jetstack/cert-manager-cainjector               v1.11.1               4.0.0-f67c80         3
# quay.io/jetstack/cert-manager-webhook                  v1.11.1               4.0.0-c875c7         3

Short Names

k api-resources

# NAME                                SHORTNAMES          APIVERSION                             NAMESPACED   KIND
# bindings                                                v1                                     true         Binding
# componentstatuses                   cs                  v1                                     false        ComponentStatus
# configmaps                          cm                  v1                                     true         ConfigMap
# endpoints                           ep                  v1                                     true         Endpoints
# events                              ev                  v1                                     true         Event
# limitranges                         limits              v1                                     true         LimitRange

e.g.

  • deploy - deployment
  • po - pod
  • cr - certificaterequest
  • ing - ingress
  • svc - service
  • ns - namespace
  • no - node