Skip to content

Instantly share code, notes, and snippets.

@MParvin
Created July 10, 2023 07:32
Show Gist options
  • Save MParvin/84386212ee1f1b6fea85128ff7e76e1c to your computer and use it in GitHub Desktop.
Save MParvin/84386212ee1f1b6fea85128ff7e76e1c to your computer and use it in GitHub Desktop.
Adding servers IP address from kubectl to ssh config file
#!/bin/bash
if [ -z "$1" ]
then
user_name=root
else
user_name=$1
fi
IFS='
'
for line in `kubectl get nodes -o wide --no-headers`
do
server_name=`echo $line | awk '{print $1}'`
server_ip=`echo $line | awk '{print $6}'`
echo "Adding $server_name server with IP $server_ip and user root to ssh config file"
# Install ssc using curl
# curl -L http://git.io/sshconfig | bash
# more info in it's github repository: https://github.com/Ara4Sh/sshconfig
ssc -a $server_name $user_name $server_ip
done
@MParvin
Copy link
Author

MParvin commented Jul 10, 2023

Usage:
./kubectl_2_ssh.sh <SSH USER NAME>
Example:
./kubectl_2_ssh.sh mparvin

If you don't provide a user name it will user root as default

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