Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@junaidk
Created November 7, 2019 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junaidk/d4a6693f16677b6d0bbbc1c08681ff54 to your computer and use it in GitHub Desktop.
Save junaidk/d4a6693f16677b6d0bbbc1c08681ff54 to your computer and use it in GitHub Desktop.
Kubectl Commands

get pods

kubectl get pods -n cloudplex-system | grep $1- | awk '{print $1}'

delete pod

kubectl delete po $( getpo $1 )

list pods with image name

kubectl get pods -o=jsonpath='{range .items[*]}{"\n"}{.metadata.name}{":\t\t\t"}{range .spec.containers[0]}{.image}{", "}{end}{end}' |\
sort

script for log and tail

save it in a file klog

#!/bin/bash
LINES_IN=$2
LINES=${LINES_IN:-100}
kubectl get pods -n cloudplex-system -l app=$1 | grep -v NAME | awk '{print $1}' | xargs -I {} kubectl logs -f --tail=$LINES {} $1

run it as klog <service-name> <number of lines | this is optional> klog tarantula 100

script for exec

save it in file kexec

#!/bin/bash
POD=$(kubectl get pods -n cloudplex-system -l app=$1 | grep -v NAME | awk '{print $1}') 
kubectl exec -it $POD -c $1 bash

run it as kexec <service-name> kexec tarantula


links

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