kubectl.plugin.zsh 2.81 KB
Newer Older
1
2
if (( $+commands[kubectl] )); then
    __KUBECTL_COMPLETION_FILE="${ZSH_CACHE_DIR}/kubectl_completion"
Patrick Stadler's avatar
Patrick Stadler committed
3

4
5
6
    if [[ ! -f $__KUBECTL_COMPLETION_FILE ]]; then
        kubectl completion zsh >! $__KUBECTL_COMPLETION_FILE
    fi
7

8
    [[ -f $__KUBECTL_COMPLETION_FILE ]] && source $__KUBECTL_COMPLETION_FILE
9

10
    unset __KUBECTL_COMPLETION_FILE
Patrick Stadler's avatar
Patrick Stadler committed
11
fi
12

Shawn Milochik's avatar
Shawn Milochik committed
13
# This command is used a LOT both below and in daily life
14
15
alias k=kubectl

16
# Apply a YML file
17
alias kaf='kubectl apply -f'
18

19
# Drop into an interactive terminal on a container
20
alias keti='kubectl exec -ti'
21
22

# Manage configuration quickly to switch contexts between local, dev ad staging.
23
24
25
26
alias kcuc='kubectl config use-context'
alias kcsc='kubectl config set-context'
alias kcdc='kubectl config delete-context'
alias kccc='kubectl config current-context'
27

28
29
30
31
# General aliases
alias kdel='kubectl delete'
alias kdelf='kubectl delete -f'

32
# Pod management.
33
alias kgp='kubectl get pods'
34
35
alias kgpw='kgp --watch'
alias kgpwide='kgp -o wide'
36
37
38
alias kep='kubectl edit pods'
alias kdp='kubectl describe pods'
alias kdelp='kubectl delete pods'
39

40
41
42
# get pod by label: kgpl "app=myapp" -n myns
alias kgpl='function _kgpl(){ label=$1; shift; kgp -l $label $*; };_kgpl'

43
# Service management.
44
alias kgs='kubectl get svc'
45
46
alias kgsw='kgs --watch'
alias kgswide='kgs -o wide'
47
48
49
alias kes='kubectl edit svc'
alias kds='kubectl describe svc'
alias kdels='kubectl delete svc'
50

51
# Ingress management
52
53
54
55
alias kgi='kubectl get ingress'
alias kei='kubectl edit ingress'
alias kdi='kubectl describe ingress'
alias kdeli='kubectl delete ingress'
56

57
58
59
60
61
62
63
64
65
66
67
68
# Namespace management
alias kgns='kubectl get namespaces'
alias kens='kubectl edit namespace'
alias kdns='kubectl describe namespace'
alias kdelns='kubectl delete namespace'

# ConfigMap management
alias kgcm='kubectl get configmaps'
alias kecm='kubectl edit configmap'
alias kdcm='kubectl describe configmap'
alias kdelcm='kubectl delete configmap'

69
# Secret management
70
71
72
alias kgsec='kubectl get secret'
alias kdsec='kubectl describe secret'
alias kdelsec='kubectl delete secret'
73
74

# Deployment management.
75
alias kgd='kubectl get deployment'
76
77
alias kgdw='kgd --watch'
alias kgdwide='kgd -o wide'
78
79
80
81
82
alias ked='kubectl edit deployment'
alias kdd='kubectl describe deployment'
alias kdeld='kubectl delete deployment'
alias ksd='kubectl scale deployment'
alias krsd='kubectl rollout status deployment'
83
84

# Rollout management.
85
86
87
alias kgrs='kubectl get rs'
alias krh='kubectl rollout history'
alias kru='kubectl rollout undo'
88

89
# Port forwarding
90
91
92
93
94
alias kpf="kubectl port-forward"

# Tools for accessing all information
alias kga='kubectl get all'
alias kgaa='kubectl get all --all-namespaces'
95

96
# Logs
97
98
alias kl='kubectl logs'
alias klf='kubectl logs -f'
99

100
101
102
# File copy
alias kcp='kubectl cp'

103
104
105
106
# Node Management
alias kgno='kubectl get nodes'
alias keno='kubectl edit node'
alias kdno='kubectl describe node'
107
alias kdelno='kubectl delete node'