Skip to content

Instantly share code, notes, and snippets.

@oskapt
Created August 27, 2019 15:18
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save oskapt/a55198d84f25df812111a8ac879d6920 to your computer and use it in GitHub Desktop.
Save oskapt/a55198d84f25df812111a8ac879d6920 to your computer and use it in GitHub Desktop.
Scripts and commands for https://youtu.be/09bsaCkLfw4

Hello! This gist goes with this video, which covers shortcuts and strategies for working with the K8s command line. You can see all of my videos on YouTube at https://adrian.goins.tv.

Scripts

I use Fish as my shell, but I know that a lot of people are using Bash. Here are two ways to concatenate config files for kubectl into the KUBECONFIG environment variable. If you're using zsh or tcsh you'll know how to convert these to your shell's format.

You can call these from your shell init file, or if you want to temporarily disable a script, append .bak or .disabled to its extension and run the script manually.

You can even hotkey it on something like the Elgato Stream Deck.

Fish

#!/usr/local/bin/fish

set -gx KUBECONFIG (echo (find ~/.kube -type f -name config.\*.yaml) | sed 's/[[:space:]]/:/g')

Bash

#!/bin/bash
export KUBECONFIG=$(echo $(find ~/.kube -type f -name config.\*.yaml) | sed 's/[[:space:]]/:/g')

Aliases

These are the aliases that I use most frequently:

Fish

alias kc kubectl
alias kd 'kubectl describe'
alias kdno 'kubectl describe nodes'
alias kdns 'kubectl describe namespaces'
alias kdpo 'kubectl describe pods'
alias kex 'kubectl exec -i -t'
alias kg 'kubectl get'
alias kga 'kubectl get all'
alias kgd 'kubectl get deploy'
alias kgi 'kubectl get ingress'
alias kgno 'kubectl get nodes'
alias kgns 'kubectl get namespaces'
alias kgow 'kubectl get -o=wide'
alias kgoy 'kubectl get -o=yaml'
alias kgpo 'kubectl get pods'
alias kgs 'kubectl get service'
alias klo 'kubectl logs -f'
alias kp 'kubectl proxy'
alias krm 'kubectl delete'
alias krmpo 'kubectl delete pods'

Bash

alias kc=kubectl
alias kd='kubectl describe'
alias kdno='kubectl describe nodes'
alias kdns='kubectl describe namespaces'
alias kdpo='kubectl describe pods'
alias kex='kubectl exec -i -t'
alias kg='kubectl get'
alias kga='kubectl get all'
alias kgd='kubectl get deploy'
alias kgi='kubectl get ingress'
alias kgno='kubectl get nodes'
alias kgns='kubectl get namespaces'
alias kgow='kubectl get -o=wide'
alias kgoy='kubectl get -o=yaml'
alias kgpo='kubectl get pods'
alias kgs='kubectl get service'
alias klo='kubectl logs -f'
alias kp='kubectl proxy'
alias krm='kubectl delete'
alias krmpo='kubectl delete pods'

Ahmet the Awesome

Ahmet Alp Balkan has created kubectx and kubens, which dramatically simplify common actions with kubectl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment