Created
July 10, 2023 07:32
-
-
Save MParvin/84386212ee1f1b6fea85128ff7e76e1c to your computer and use it in GitHub Desktop.
Adding servers IP address from kubectl to ssh config file
This file contains hidden or 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
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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