-
Notifications
You must be signed in to change notification settings - Fork 5
/
.aliases
195 lines (170 loc) · 9.26 KB
/
.aliases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# Update git aliases
# Save a copy of the current aliases to a temporary file with a timestamp
# Download the latest version of the.aliases file from GitHub
# Reload the Oh My Zsh configuration
updategitaliases() {
cp ~/.aliases /tmp/.aliases-"`date +"%d-%m-%Y-%H-%M-%S"`"
wget https://raw.githubusercontent.com/jessegoodier/jesse-zsh-profile/main/.aliases -O ~/.aliases \
&& wget https://raw.githubusercontent.com/jessegoodier/jesse-zsh-profile/main/.vimrc -O ~/.vimrc \
&& wget https://raw.githubusercontent.com/jessegoodier/jesse-zsh-profile/main/.prompt.zsh -O ~/.prompt.zsh \
&& mkdir -p ~/.kube-scripts \
&& wget https://raw.githubusercontent.com/jessegoodier/kgc/main/kgc.sh -O ~/.kube-scripts/kgc.sh \
&& wget https://raw.githubusercontent.com/jessegoodier/jesse-zsh-profile/main/.kube-scripts/aliases.sh -O ~/.kube-scripts/aliases.sh \
&& wget https://raw.githubusercontent.com/jessegoodier/jesse-zsh-profile/main/.kube-scripts/get-all-aks-clusters.sh -O ~/.kube-scripts/get-all-aks-clusters.sh \
&& wget https://raw.githubusercontent.com/jessegoodier/jesse-zsh-profile/main/.kube-scripts/get-all-eks-clusters.sh -O ~/.kube-scripts/get-all-eks-clusters.sh \
&& wget https://raw.githubusercontent.com/jessegoodier/jesse-zsh-profile/main/.kube-scripts/get-all-gke-clusters.sh -O ~/.kube-scripts/get-all-gke-clusters.sh \
&& wget https://raw.githubusercontent.com/jessegoodier/jesse-zsh-profile/main/.kube-scripts/k-get-all-pod-images.sh -O ~/.kube-scripts/k-get-all-pod-images.sh \
&& wget https://raw.githubusercontent.com/jessegoodier/jesse-zsh-profile/main/.kube-scripts/k-remove-bad-contexts.sh -O ~/.kube-scripts/k-remove-bad-contexts.sh \
&& touch ~/.aliases-local
omz reload
}
if [ "$(command -v kubecolor)" ]; then
alias kubectl="kubecolor"
compdef kubecolor=kubectl
alias watch='KUBECOLOR_FORCE_COLORS=true watch --color '
fi
# Unalias the ksd command, which is a k scale deployment
unalias ksd 2>/dev/null
unalias hin 2>/dev/null
unalias hup 2>/dev/null
alias hru='helm repo update'
unalias hun 2>/dev/null
unalias hup 2>/dev/null
unalias hin 2>/dev/null
alias fed="kgsec federated-store -oyaml|ksd"
# Aliases
# List files in long format with hidden files and directories, and colorize the output
alias ll='ls -lah'
# Show the command history
alias h='history'
# Get information about Kubernetes resources
alias kg='kubectl get'
# Get nodes with labels
alias kgnol='kubectl get nodes --show-labels'
# Get endpoints
alias kgep='kubectl get ep'
# Describe a resource
alias kd='kubectl describe'
# Edit a StatefulSet
alias kests='kubectl edit sts'
# Find the image used in a pod
alias kdpi='kubectl describe pod|grep -i image:'
# Restart a deployment
alias krrd='kubectl rollout restart deployment'
# Restart a StatefulSet
alias krrsts='kubectl rollout restart sts'
# Get a list of StatefulSets
alias kgsts="kubectl get sts"
# Delete a StatefulSet
alias kdelsts="kubectl delete sts"
# Kubecost
# Get the logs for the cost-model container in the cost-analyzer pod
alias klcm="kubectl logs -l app.kubernetes.io/name=cost-analyzer --tail=-1 -c cost-model"
# Get the logs for the cost-analyzer-frontend container in the cost-analyzer pod
alias klfe="kubectl logs -l app=cost-analyzer --tail=-1 -c cost-analyzer-frontend"
# Get the logs for the aggregator container in the aggregator pod
alias kla="kubectl logs -l app=aggregator -c aggregator --tail=-1"
# Get the logs for the cost-model container in the cost-analyzer pod, and follow the logs
alias klcmf="kubectl logs -l app=cost-analyzer -c cost-model --tail=-1 --follow"
# Get the logs for the cost-analyzer-frontend container in the cost-analyzer pod, and follow the logs
alias klfef="kubectl logs -l app=cost-analyzer -c cost-analyzer-frontend --tail=-1 --follow"
# Get the logs for the aggregator container in the aggregator pod, and follow the logs
alias klaf="kubectl logs -l app=aggregator -c aggregator --tail=-1 --follow"
# Todo function to find the deployment
# Find the deployment named kubecost-cost-analyzer and execute the given command in the cost-analyzer-frontend container
alias kexecfe="kubectl exec -i -t deployment/kubecost-cost-analyzer -c cost-analyzer-frontend --" $1
# Find the deployment named kubecost-cost-analyzer and execute the given command in the cost-model container
alias kexeccm="kubectl exec -i -t deployment/kubecost-cost-analyzer -c cost-model --" $1
# Clean up unused images
# Remove any images that are not currently being used
alias drmi='docker rmi -f $(docker images -q)'
# Start a shell inside a container
alias deit='docker exec -i -t'
# Azure
# List all AKS clusters
alias azl='az aks list --output table'
# AWS
# List all EKS clusters
alias eks='eksctl get cluster'
# Randoms
# Clear the terminal screen
alias c='clear'
alias cat='bat --style=plain --paging=never'
# Send five ICMP ECHO_REQUEST packets and stop
alias ping='ping -c 5'
# Send 100 ICMP ECHO_REQUEST packets with a packet size of 0.2 seconds and do not wait one second between packets
alias fastping='ping -c 100 -s.2'
# Open a file with sudo permissions
alias svi='sudo vi'
# Pass options to the free command, such as showing memory usage in large units, showing the load average, and sorting by memory usage
alias meminfo='free -m -l -t'
# Get the top 5 processes by memory usage
alias psmem='ps auxf | sort -nr -k 4'
# Get the top 10 processes by memory usage
alias psmem10='ps auxf | sort -nr -k 4 | head -10'
# Get the top 5 processes by CPU usage
alias pscpu='ps auxf | sort -nr -k 3'
# Get the top 10 processes by CPU usage
alias pscpu10='ps auxf | sort -nr -k 3 | head -10'
# Get server CPU information
alias cpuinfo='lscpu'
# List the contents of the current directory in human-readable format and show the size of each file in KB, MB, GB, etc.
alias df='df -H'
# List the contents of the current directory in sorted order by size, and for each file, show the size in KB, MB, GB, etc.
alias du='du -sk * | sort -n | while read size fname; do for unit in k M G T P E Z Y; do if [ $size -lt 1024 ]; then echo -e "-${size}${unit}\t${fname}"; break; fi; size=$((size/1024)); done; done'
# If exa is installed, use it as the default ls command, with colorized output, icons, and additional information such as file type
if [ "$(command -v exa)" ]; then
alias ll='exa -l --color always --icons -a -s type'
alias l='exa --color always --icons -a -s type'
alias la='exa -l --color always --icons -a -s type'
alias ls='exa -G --color auto --icons -a -s type'
fi
# Use grep with colorized output and exclude certain directories, such as.bzr, CVS,.git,.hg,.svn,.idea,.tox,.vscode-server-insiders,.vscode-server,.vscode-server-insiders, and.vs-kubernetes
alias grep='grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox,.vscode-server-insiders,.vscode-server,.vscode-server-insiders,.vs-kubernetes}'
# Use ack with colorized output and exclude the same directories as grep
alias ack='ack --color --ignore-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox,.vscode-server-insiders,.vscode-server,.vscode-server-insiders,.vs-kubernetes}'
# More Kubernetes
# Get information about Kubernetes resources
alias kg='kubectl get'
# Get persistent volumes
alias kgpv='kubectl get pv'
# Watch persistent volumes
alias kgpvw='kubectl get pv --watch'
# Watch all pods in all namespaces
alias kgpaw='kubectl get pods --all-namespaces --watch'
# Watch all pods in the current namespace
alias kgpw='kubectl get pods --watch'
# Set the current namespace
alias kn='kubectl config set-context --current --namespace'
# Use a specific Kubernetes context
alias kc='kubectl config use-context'
# If kubectx is installed, use it as an alternative to kn and kc
if [ "$(command -v kubectx)" ]; then
alias kn='kubens'
alias kx='kubectx'
fi
# Get a list of StatefulSets
alias kgsts="kubectl get sts"
# Get events, sorted by lastTimestamp, and only show events of type Normal
alias kge="kubectl get events --sort-by=lastTimestamp --field-selector type!=Normal"
# Start a shell inside a container
alias keit='kubectl exec -i -t'
# Get the nginx version running in the nginx-ingress namespace
alias kic="keit -n nginx-ingress \$(kgpn nginx-ingress|grep ingress -m1 |awk '{print \$1}') -- nginx -T | grep '\\S'"
# AWS
alias acreds='aws eks update-kubeconfig --region ca-central-1 --name'
# gcloud
# create a cluster
alias gccc='gcloud container clusters create --machine-type e2-standard-4 --num-nodes=1 --zone=us-east1-d --network=creynold-vpc'
# get kube creds for a cluster: gcreds jesse-gk1
gcreds() { ZONE=$(gcloud container clusters list --filter=name:"$1" --format="[no-heading](location)") ; gcloud container clusters get-credentials $1 --zone $ZONE }
#delete a cluster
gccd() { ZONE=$(gcloud container clusters list --filter=name:"$1" --format="[no-heading](location)") ; gcloud container clusters delete $1 --zone $ZONE $2 }
# list all clusters in our project, ignore cluster upgrade and surveys
alias gccl='gcloud container clusters list 2>/dev/null'
alias gcclj='gcloud container clusters list 2>/dev/null --filter=name:jesse --format="(name,location,currentNodeCount)"'
# resize cluster
gccr() { ZONE=$(gcloud container clusters list --filter=name:"$1" --format="[no-heading](location)") ; gcloud container clusters resize $1 --zone $ZONE --num-nodes $2 --quiet}
alias gcdu='gcloud dns record-sets update --type=A --ttl=30 --zone=nginx-rocks --rrdatas'
alias gccil'=gcloud compute instances list |grep jesse'
alias gil'=gcloud compute instances list |grep jesse'