kubectl.plugin.zsh 2.91 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
# get pod by label: kgpl "app=myapp" -n myns
Kayla Altepeter's avatar
Kayla Altepeter committed
41
alias kgpl='kgp -l'
42

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
# Namespace management
alias kgns='kubectl get namespaces'
alias kens='kubectl edit namespace'
alias kdns='kubectl describe namespace'
alias kdelns='kubectl delete namespace'
62
alias kcn='kubectl config set-context $(kubectl config current-context) --namespace'
63
64
65
66
67
68
69

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

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

# Deployment management.
76
alias kgd='kubectl get deployment'
77
78
alias kgdw='kgd --watch'
alias kgdwide='kgd -o wide'
79
80
81
82
83
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'
84
85
86
kres(){
    kubectl set env $@ REFRESHED_AT=$(date +%Y%m%d%H%M%S)
}
87
88

# Rollout management.
89
90
91
alias kgrs='kubectl get rs'
alias krh='kubectl rollout history'
alias kru='kubectl rollout undo'
92

93
# Port forwarding
94
95
96
97
98
alias kpf="kubectl port-forward"

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

100
# Logs
101
102
alias kl='kubectl logs'
alias klf='kubectl logs -f'
103

104
105
106
# File copy
alias kcp='kubectl cp'

107
108
109
110
# Node Management
alias kgno='kubectl get nodes'
alias keno='kubectl edit node'
alias kdno='kubectl describe node'
Kayla Altepeter's avatar
Kayla Altepeter committed
111
alias kdelno='kubectl delete node'