Last active
September 4, 2021 02:13
-
-
Save SJ50/40d029b4d56d680483976105ffaa8523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### small function to add last command as alias | |
### usage "add <alias_name> "!!" | |
### example add kgp "!!" | |
function add(){ | |
echo alias\ $1=\"$2\" >> ~/.bashrc | |
source ~/.bashrc | |
echo "refreshed..." | |
} | |
### Install pet | |
function pet-install(){ | |
wget -q -O /tmp/pet_0.3.6_linux_amd64.deb https://github.com/knqyf263/pet/releases/download/v0.3.6/pet_0.3.6_linux_amd64.deb | |
apt -qq install /tmp/pet_0.3.6_linux_amd64.deb | |
wget -q -O /tmp/fzf_0.20.0-1build1_amd64.deb http://archive.ubuntu.com/ubuntu/pool/universe/f/fzf/fzf_0.20.0-1build1_amd64.deb | |
apt -qq install /tmp/fzf_0.20.0-1build1_amd64.deb | |
echo 'function pex() { pet exec -q=$@; }' >> ~/.bashrc | |
wget -P ~/.config/pet/ -O ~/.config/pet/snippet.toml https://gist.githubusercontent.com/javajon/131a7f26c11a03d741e6bcefb857c496/raw/kubectl-snippet.toml | |
rm /tmp/pet_0.3.6_linux_amd64.deb | |
rm /tmp/fzf_0.20.0-1build1_amd64.deb | |
echo 'function pex() { pet exec -q=$@; }' >> ~/.bashrc | |
source ~/.bashrc | |
} | |
### expand aliase using "ctr+alt+e" or "esc ctr+e" for autocomplete | |
##### CORE CONCEPTS ##### | |
### apply and delete | |
alias ka="kubectl apply -f" | |
alias kdl="kubectl delete -f " | |
### Pods | |
alias kgp="kubectl get pods -o wide" | |
alias kdp="kubectl describe pods" | |
alias kdlp="kubectl delete pod --force" | |
alias kr="kubectl run --image=" | |
alias kgpy="kubectl get pods -o yaml" | |
alias kgpns="kubectl get pods -n" | |
### Node | |
alias kgn="kubectl get nodes -o wide" | |
### Replicaset | |
alias kgrs="kubectl get replicasets.apps -o wide" | |
alias kdrs="kubectl describe replicasets.apps " | |
alias kdlrs="kubectl delete replicasets.apps " | |
alias kgrsy="kubectl get replicasets.apps -o yaml " | |
alias kscrs="kubectl scale replicaset --replicas=" | |
### Deployments | |
alias kgd="kubectl get deployments.apps -o wide" | |
alias kdd="kubectl describe deployments.apps" | |
alias kdld="kubectl delete deployments.apps" | |
function kcddo(){ | |
read -p "image: " image | |
read -p "no of replicas: " replicas | |
read -p "deployment name: " name | |
case $namespace in | |
"" ) namespae=$(kubectl config view --minify | grep namespace: | cut -d " " -f6);; | |
* ) namespace=$namespace;; | |
esac | |
kubectl create deployment --image=$image --replicas=$replicas --namespace=$namespace $name --dry-run=client -o yaml | |
} | |
function kcd(){ | |
read -p "image: " image | |
read -p "no of replicas: " replicas | |
read -p "deployment name: " name | |
read -p "namespace: " namespace | |
case $namespace in | |
"" ) namespae=$(kubectl config view --minify | grep namespace: | cut -d " " -f6);; | |
* ) namespace=$namespace;; | |
esac | |
kubectl create deployment --image=$image --replicas=$replicas $name --namespace=$namespace | |
} | |
alias kscd="kubectl scale deployement --replicas=" | |
### Services | |
alias kgs="kubectl get service -o wide" | |
alias kds="kubectl describe services" | |
alias kdls="kubectl delete services" | |
alias kre="kubectl run --expose --port" | |
function keddo(){ | |
read -p "deployment name to expose: " name | |
read -p "service type [(C)lusterIP, (N)odePort, (L)oadBalancer]: " service_type | |
case $service_type in | |
n|N ) service_type=NodePort;; | |
l|L ) service_type=LoadBalancer;; | |
* ) service_type=ClusterIP;; | |
esac | |
read -p "service name: " service_name | |
read -p "namespace: " namespace | |
case $namespace in | |
"" ) namespae=$(kubectl config view --minify | grep namespace: | cut -d " " -f6);; | |
* ) namespace=$namespace;; | |
esac | |
kubectl expose deployment $name --type $service_type --name $service_name --namespace $namespace --dry-run=client -o yaml | |
} | |
function ked(){ | |
read -p "deployment name to expose: " name | |
read -p "service type [(C)lusterIP, (N)odePort, (L)oadBalancer]: " service_type | |
case $service_type in | |
n|N ) service_type=NodePort;; | |
l|L ) service_type=LoadBalancer;; | |
* ) service_type=ClusterIP;; | |
esac | |
read -p "service name: " service_name | |
read -p "namespace: " namespace | |
case $namespace in | |
"" ) namespae=$(kubectl config view --minify | grep namespace: | cut -d " " -f6);; | |
* ) namespace=$namespace;; | |
esac | |
kubectl expose deployment $name --type $service_type --name $service_name --namespace $namespace | |
} | |
function kep(){ | |
read -p "pod name to expose: " name | |
read -p "service type [(C)lusterIP, (N)odePort, (L)oadBalancer]: " service_type | |
case $service_type in | |
n|N ) service_type=NodePort;; | |
l|L ) service_type=LoadBalancer;; | |
* ) service_type=ClusterIP;; | |
esac | |
read -p "port: " port | |
read -p "service name: " service_name | |
read -p "namespace: " namespace | |
case $namespace in | |
"" ) namespae=$(kubectl config view --minify | grep namespace: | cut -d " " -f6);; | |
* ) namespace=$namespace;; | |
esac | |
kubectl expose pod $name --type $service_type --port $port --name $service_name --namespace $namespace | |
} | |
##### SCHEDULING ##### | |
# tain | |
function ktn(){ | |
read -p "node name to taint: " node | |
read -p "taint key: " key | |
read -p "taint value: " value | |
read -p "taint effect [(N)oSchedule, (P)referNoSchedule, No(E)xecute]: " effect | |
case $service_type in | |
p|P ) effect=PreferNoSchedule;; | |
e|E ) effect=NoExecute;; | |
* ) effect=NoSchedule;; | |
esac | |
kubectl taint node $node $key=$value:$effect | |
} | |
function knut(){ | |
read -p "node name to taint: " node | |
read -p "taint key: " key | |
read -p "taint value: " value | |
read -p "taint effect [(N)oSchedule, (P)referNoSchedule, No(E)xecute]: " effect | |
case $service_type in | |
p|P ) effect=PreferNoSchedule;; | |
e|E ) effect=NoExecute;; | |
* ) effect=NoSchedule;; | |
esac | |
kubectl taint node $node $key=$value:$effect- | |
} | |
alias kgnt="kubectl get node -o custom-columns=NAME:.metadata.name,TAINT-EFFECT:.spec.taints[*].effect,TAINT-KEY:.spec.taints[*].key,TAINT-VALUE:.spec.taints[*].value" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment