Compare commits
	
		
			2 Commits
		
	
	
		
			08c0c58227
			...
			c57251d4d5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						
						
							
						
						c57251d4d5
	
				 | 
					
					
						|||
| 
						
						
							
						
						2a59d2b677
	
				 | 
					
					
						
@@ -41,3 +41,7 @@ else
 | 
				
			|||||||
      echo $@
 | 
					      echo $@
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					_fzf() {
 | 
				
			||||||
 | 
					  fzf --multi --ansi -i -1 --height=50% --reverse -0 --header-lines=1 --border --info=hidden
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1 +0,0 @@
 | 
				
			|||||||
/opt/homebrew/bin//gdate
 | 
					 | 
				
			||||||
@@ -56,9 +56,9 @@ if [[ "$POD" == "" ]]; then
 | 
				
			|||||||
    exit 1
 | 
					    exit 1
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pod=($(kubectl get pods --all-namespaces -owide | fzf | awk '{print $1, $2}'))
 | 
					  pod=($(kubectl get pods --all-namespaces -o wide | _fzf | awk '{print $1, $2}'))
 | 
				
			||||||
  POD=$pod[1]
 | 
					  POD=${pod[1]}
 | 
				
			||||||
  NAMESPACE=$pod[0]
 | 
					  NAMESPACE=${pod[0]}
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
echo kubectl exec -it --namespace $NAMESPACE $POD $CMD
 | 
					echo kubectl exec -it --namespace $NAMESPACE $POD $CMD
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -56,9 +56,9 @@ if [[ "$POD" == "" ]]; then
 | 
				
			|||||||
    exit 1
 | 
					    exit 1
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  pod=($(kubectl get pods --all-namespaces -owide | fzf | awk '{print $1, $2}'))
 | 
					  pod=($(kubectl get pods --all-namespaces -o wide | _fzf | awk '{print $1, $2}'))
 | 
				
			||||||
  POD=$pod[1]
 | 
					  POD=${pod[1]}
 | 
				
			||||||
  NAMESPACE=$pod[0]
 | 
					  NAMESPACE=${pod[0]}
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
echo kubectl logs -f $ARGS --namespace $NAMESPACE $POD
 | 
					echo kubectl logs -f $ARGS --namespace $NAMESPACE $POD
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,9 +50,9 @@ if [[ "$DEPLOYMENT" == "" ]]; then
 | 
				
			|||||||
    exit 1
 | 
					    exit 1
 | 
				
			||||||
  )
 | 
					  )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  deployment=($(kubectl get deployments --all-namespaces -owide | fzf | awk '{print $1, $2}'))
 | 
					  deployment=($(kubectl get deployments --all-namespaces -o wide | _fzf | awk '{print $1, $2}'))
 | 
				
			||||||
  DEPLOYMENT=$deployment[1]
 | 
					  DEPLOYMENT=${deployment[1]}
 | 
				
			||||||
  NAMESPACE=$pod[0]
 | 
					  NAMESPACE=${pod[0]}
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
kubectl patch deployment -n ${NAMESPACE} ${DEPLOYMENT} -p '{"spec": { "template": { "spec": { "tolerations": [ { "operator": "Exists" } ] } } } }' 1>/dev/null
 | 
					kubectl patch deployment -n ${NAMESPACE} ${DEPLOYMENT} -p '{"spec": { "template": { "spec": { "tolerations": [ { "operator": "Exists" } ] } } } }' 1>/dev/null
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ set -e
 | 
				
			|||||||
NAMESPACE=${NAMESPACE:-default}
 | 
					NAMESPACE=${NAMESPACE:-default}
 | 
				
			||||||
POD="kube-ssh"
 | 
					POD="kube-ssh"
 | 
				
			||||||
NODE=""
 | 
					NODE=""
 | 
				
			||||||
 | 
					IMAGE="alpine"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
print_usage() {
 | 
					print_usage() {
 | 
				
			||||||
  blue "kube-ssh - gain access to a Kubernetes host node (ssh-like for when a host doesn't have ssh)"
 | 
					  blue "kube-ssh - gain access to a Kubernetes host node (ssh-like for when a host doesn't have ssh)"
 | 
				
			||||||
@@ -17,8 +18,8 @@ print_usage() {
 | 
				
			|||||||
  underline "Options:"
 | 
					  underline "Options:"
 | 
				
			||||||
  echo "-h, --help            show this help text"
 | 
					  echo "-h, --help            show this help text"
 | 
				
			||||||
  echo "-n, --namespace       the namespace to launch the pod in"
 | 
					  echo "-n, --namespace       the namespace to launch the pod in"
 | 
				
			||||||
  echo "-p, --pod             the name of the pod to launch (default: kube-ssh)"
 | 
					 | 
				
			||||||
  echo "-N, --node            the name of the node to access"
 | 
					  echo "-N, --node            the name of the node to access"
 | 
				
			||||||
 | 
					  echo "-i, --image           the image to launch for debugging (default: alpine)"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
while test $# -gt 0; do
 | 
					while test $# -gt 0; do
 | 
				
			||||||
@@ -28,16 +29,16 @@ while test $# -gt 0; do
 | 
				
			|||||||
      NAMESPACE=$1
 | 
					      NAMESPACE=$1
 | 
				
			||||||
      shift
 | 
					      shift
 | 
				
			||||||
      ;;
 | 
					      ;;
 | 
				
			||||||
    -p|--pod)
 | 
					 | 
				
			||||||
      shift
 | 
					 | 
				
			||||||
      POD=$1
 | 
					 | 
				
			||||||
      shift
 | 
					 | 
				
			||||||
      ;;
 | 
					 | 
				
			||||||
    -N|--node)
 | 
					    -N|--node)
 | 
				
			||||||
      shift
 | 
					      shift
 | 
				
			||||||
      NODE=$1
 | 
					      NODE=$1
 | 
				
			||||||
      shift
 | 
					      shift
 | 
				
			||||||
      ;;
 | 
					      ;;
 | 
				
			||||||
 | 
					    -i|--image)
 | 
				
			||||||
 | 
					      shift
 | 
				
			||||||
 | 
					      IMAGE=$1
 | 
				
			||||||
 | 
					      shift
 | 
				
			||||||
 | 
					      ;;
 | 
				
			||||||
    -h|--help)
 | 
					    -h|--help)
 | 
				
			||||||
      print_usage
 | 
					      print_usage
 | 
				
			||||||
      exit 0
 | 
					      exit 0
 | 
				
			||||||
@@ -49,9 +50,9 @@ while test $# -gt 0; do
 | 
				
			|||||||
done
 | 
					done
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if [[ "$NODE" == "" ]]; then
 | 
					if [[ "$NODE" == "" ]]; then
 | 
				
			||||||
  NODES=$(kubectl get nodes --no-headers -o custom-columns=name:.metadata.name)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if [ -z "$(which fzf)" ]; then
 | 
					  if [ -z "$(which fzf)" ]; then
 | 
				
			||||||
 | 
					    NODES=$(kubectl get nodes --no-headers -o custom-columns=name:.metadata.name)
 | 
				
			||||||
    i=0
 | 
					    i=0
 | 
				
			||||||
    while read -r node; do
 | 
					    while read -r node; do
 | 
				
			||||||
      echo "[$i] - $node"
 | 
					      echo "[$i] - $node"
 | 
				
			||||||
@@ -62,11 +63,18 @@ if [[ "$NODE" == "" ]]; then
 | 
				
			|||||||
    IFS=$'\n' NODES=($NODES)
 | 
					    IFS=$'\n' NODES=($NODES)
 | 
				
			||||||
    NODE=${NODES[$REPLY]}
 | 
					    NODE=${NODES[$REPLY]}
 | 
				
			||||||
  else
 | 
					  else
 | 
				
			||||||
    NODE=$(echo "$NODES" | fzf)
 | 
					    NODES=$(kubectl get nodes)
 | 
				
			||||||
 | 
					    NODE=$(echo "$NODES" | _fzf | awk '{print $1}')
 | 
				
			||||||
  fi
 | 
					  fi
 | 
				
			||||||
fi
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					SERVER_VERSION=$(kubectl version --client=false -o json 2>/dev/null | jq -r '.serverVersion.minor')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if [ ${SERVER_VERSION} -ge 22 ]; then
 | 
				
			||||||
 | 
					  kubectl debug node/${NODE} -it --image ${IMAGE}
 | 
				
			||||||
 | 
					else
 | 
				
			||||||
  NODE_NAME=$(kubectl get node $NODE -o template --template='{{index .metadata.labels "kubernetes.io/hostname"}}')
 | 
					  NODE_NAME=$(kubectl get node $NODE -o template --template='{{index .metadata.labels "kubernetes.io/hostname"}}')
 | 
				
			||||||
  NODE_SELECTOR='"nodeSelector": { "kubernetes.io/hostname": "'${NODE_NAME}'" },'
 | 
					  NODE_SELECTOR='"nodeSelector": { "kubernetes.io/hostname": "'${NODE_NAME}'" },'
 | 
				
			||||||
 | 
					  kubectl run --namespace ${NAMESPACE} $POD --rm -it --image ${IMAGE} --privileged --overrides '{"spec":{'"${NODE_SELECTOR}"'"hostPID": true}}' --command nsenter -- --mount=/proc/1/ns/mnt -- /bin/bash
 | 
				
			||||||
 | 
					fi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
kubectl run --namespace ${NAMESPACE} $POD --rm -it --image alpine --privileged --overrides '{"spec":{'"${NODE_SELECTOR}"'"hostPID": true}}' --command nsenter -- --mount=/proc/1/ns/mnt -- /bin/bash
 | 
					 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1 +0,0 @@
 | 
				
			|||||||
/opt/homebrew/bin//greadlink
 | 
					 | 
				
			||||||
@@ -1 +0,0 @@
 | 
				
			|||||||
/opt/homebrew/bin//gsed
 | 
					 | 
				
			||||||
@@ -40,10 +40,10 @@ alias watch='watch '
 | 
				
			|||||||
alias tmp='cd $(mktemp -d)'
 | 
					alias tmp='cd $(mktemp -d)'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# Ensure GNU version of tools are used by default (symlink so they are picked up in scripts also)
 | 
					# Ensure GNU version of tools are used by default (symlink so they are picked up in scripts also)
 | 
				
			||||||
which greadlink &>/dev/null && ln -sfn `which greadlink` ~/.bin/readlink
 | 
					which greadlink &>/dev/null && ln -sfn `which greadlink` /usr/local/bin/readlink
 | 
				
			||||||
which gsed &>/dev/null && ln -sfn `which gsed` ~/.bin/sed
 | 
					which gsed &>/dev/null && ln -sfn `which gsed` /usr/local/bin/sed
 | 
				
			||||||
which gdate &>/dev/null && ln -sfn `which gdate` ~/.bin/date
 | 
					which gdate &>/dev/null && ln -sfn `which gdate` /usr/local/bin/date
 | 
				
			||||||
which gbase64 &>/dev/null && ln -sfn `which gbase64` ~/.bin/base64
 | 
					which gbase64 &>/dev/null && ln -sfn `which gbase64` /usr/local/bin/base64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
lt() {
 | 
					lt() {
 | 
				
			||||||
  DEPTH=$(echo $1 | grep "^[0-9]*$")
 | 
					  DEPTH=$(echo $1 | grep "^[0-9]*$")
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user