Skip to content

Instantly share code, notes, and snippets.

@arunbsar
Last active November 7, 2019 16:21
Show Gist options
  • Save arunbsar/7c244ee40a44e90f5b48c256494c7779 to your computer and use it in GitHub Desktop.
Save arunbsar/7c244ee40a44e90f5b48c256494c7779 to your computer and use it in GitHub Desktop.
kubectl shortcuts

kubectl shortcuts i use in .bashrc

alias k="kubectl"
alias kg="kubectl get"
alias kc="kubectl create"
alias kgp="kubectl get pods"
export ks="-n kube-system"
export all="--all-namespaces"
export y="-o yaml"
export j="-o json"
export dry="--dry-run -o yaml"

# bash auto completion could have used "complete -F __start_kubectl k" for alias
source <(kubectl completion bash)
source <(kubectl completion bash| sed s/kubectl/k/g)

it makes my life easier

will generate deployment yaml

k run nginx --image=nginx $dry

nginx.yaml:

apiVersion: apps/v1
kind: Deployment
metadata:
  creationTimestamp: null
  labels:
    run: nginx
  name: nginx
spec:
  replicas: 1
  selector:
    matchLabels:
      run: nginx
  strategy: {}
  template:
    metadata:
      creationTimestamp: null
      labels:
        run: nginx
    spec:
      containers:
      - image: nginx
        name: nginx
        resources: {}
status: {}

list all pods from all namespaces

kgp $all

list all pods in kube-system

kgp $ks

so much can be added to the list but want to, keep it simple and just to give an idea

Vim settings

set ts=2 sw=2 et ai
set pastetoggle=<f2>
set relativenumber
set list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment